// // mp::byte_array // // Copyright (C) 2008 FURUHASHI Sadayuki // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef MP_BYTE_ARRAY_H__ #define MP_BYTE_ARRAY_H__ #include #include #ifndef MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE #define MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE 4096 #endif namespace mp { static const size_t BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE = MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE; template > class byte_array { public: typedef char value_type; typedef size_t size_type; typedef char* iterator; typedef const char* const_iterator; typedef char& reference; typedef const char& const_reference; typedef ptrdiff_t difference_type; typedef Allocator allocator_type; public: byte_array(size_type initial_size=BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE); ~byte_array(); iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; bool empty() const; size_type size() const; size_type capacity() const; size_type space() const; void produced(size_type produced_size); void consumed(size_type consumed_size); void clear(); void reserve(size_type new_size); void reserve_space(size_type required_size); void swap(byte_array& other); public: void read(void* buffer, size_type size); void write(const void* buffer, size_type size); MP_ARGS_BEGIN template void read(MP_ARGS_PARAMS_PTR); MP_ARGS_END MP_ARGS_BEGIN template void write(MP_ARGS_PARAMS); MP_ARGS_END private: char* storage; char* start; char* finish; char* allocated_end; private: size_type allocated_size() const; allocator_type get_allocator() const; private: byte_array(const byte_array&); }; } // namespace mp #include "mp/byte_array_impl.h" #endif /* mp/byte_array.h */