<commit_before>/*
 * Copyright (c) 2016 <NAME>
 *
 * This file is part of the Realms Of Steel.
 * For conditions of distribution and use, see copyright details in the LICENSE file.
 */
#ifndef ROS_RAW_BUFFER_H
#define ROS_RAW_BUFFER_H

#include <boost/endian/conversion.hpp>
#include <core/Common.h>
#include <core/Environment.h>
#include <core/Buffer.h>

namespace ros {
    class ROS_API RawBuffer: public Buffer {
        public:
            RawBuffer();
            explicit RawBuffer(U32 size);
            virtual ~RawBuffer();

            RawBuffer(const RawBuffer& src);
            RawBuffer& operator=(const RawBuffer& src);

            bool allocate(U32 size);
            bool assign(const RawBuffer& src);
            bool resize(U32 size);
            void free();
            void clear();

            virtual bool isNull() const { return !data; }
            virtual U32 getSize() const { return size; }

            template<class Type>
            inline Type* at(U32 offset = 0) {
                if (!data || offset >= size) {
                    return ROS_NULL;
                }
                return reinterpret_cast<Type*>(data + offset);
            }

            template<class Type>
            inline const Type* at(U32 offset = 0) const {
                if (!data || offset >= size) {
                    return ROS_NULL;
                }
                return reinterpret_cast<const Type*>(data + offset);
            }

            U32 getPosition() const { return position; }
            bool seek(S64 offset, BufferOrigin origin) const;
            bool rewind() const;
            bool hasEnded() const;

            bool read(void* dst, U32 size) const;

            template<class Type>
            Type read() const {
                Type dst;
                if (!read(&dst, sizeof(Type))) {
                    return Type();
                }
                return dst;
            }

            template<class Type>
            inline Type readLittle() const {
                return boost::endian::little_to_native(read<Type>());
            }

            template<class Type>
            inline bool readBig(Type& dst) const {
                return boost::endian::big_to_native(read<Type>());
            }

            bool write(const void* src, U32 size);

            template<class Type>
            inline bool write(const Type& src) {<commit_msg>Make RawBuffer and RawFile APIs more alike<commit_after>/*
 * Copyright (c) 2016 <NAME>
 *
 * This file is part of the Realms Of Steel.
 * For conditions of distribution and use, see copyright details in the LICENSE file.
 */
#ifndef ROS_RAW_BUFFER_H
#define ROS_RAW_BUFFER_H

#include <boost/endian/conversion.hpp>
#include <core/Common.h>
#include <core/Environment.h>
#include <core/Buffer.h>

namespace ros {
    class ROS_API RawBuffer: public Buffer {
        public:
            RawBuffer();
            explicit RawBuffer(U32 size);
            virtual ~RawBuffer();

            RawBuffer(const RawBuffer& src);
            RawBuffer& operator=(const RawBuffer& src);

            bool allocate(U32 size);
            bool assign(const RawBuffer& src);
            bool resize(U32 size);
            void free();
            void clear();

            virtual bool isNull() const { return !data; }
            virtual U32 getSize() const { return size; }

            template<class Type>
            inline Type* at(U32 offset = 0) {
                if (!data || offset >= size) {
                    return ROS_NULL;
                }
                return reinterpret_cast<Type*>(data + offset);
            }

            template<class Type>
            inline const Type* at(U32 offset = 0) const {
                if (!data || offset >= size) {
                    return ROS_NULL;
                }
                return reinterpret_cast<const Type*>(data + offset);
            }

            U32 getPosition() const { return position; }
            bool seek(S64 offset, BufferOrigin origin) const;
            bool rewind() const;
            bool hasEnded() const;

            bool read(void* dst, U32 size) const;

            template<class Type>
            inline bool read(Type& dst) const {
                return this->read(&dst, sizeof(Type));
            }

            template<class Type>
            bool readLittle(Type& dst) const {
                if (!read<Type>(dst)) {
                    return false;
                }
                boost::endian::little_to_native_inplace(dst);
                return true;
            }

            template<class Type>
            bool readBig(Type& dst) const {
                if (!read(&dst, sizeof(dst))) {
                    return false;
                }
                boost::endian::big_to_native_inplace(dst);
                return true;
            }

            bool write(const void* src, U32 size);

            template<class Type>
            inline bool write(const Type& src) {
{'fraction_non_alphanumeric': 0.09436986575836506, 'fraction_numerical': 0.010418753756762171, 'mean_word_length': 1.5391658189216684, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5605787', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1235, 'n_words': 388}