root/lang/c/mpio/trunk/mp/byte_array.pre.h @ 18301

Revision 18183, 2.4 kB (checked in by frsyuki, 5 years ago)

lang/c/mpio: added mp::coroutine, mp::async, mp::byte_array, mp::short_queue, removed mp::io

Line 
1//
2// mp::byte_array
3//
4// Copyright (C) 2008 FURUHASHI Sadayuki
5//
6//    Licensed under the Apache License, Version 2.0 (the "License");
7//    you may not use this file except in compliance with the License.
8//    You may obtain a copy of the License at
9//
10//        http://www.apache.org/licenses/LICENSE-2.0
11//
12//    Unless required by applicable law or agreed to in writing, software
13//    distributed under the License is distributed on an "AS IS" BASIS,
14//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//    See the License for the specific language governing permissions and
16//    limitations under the License.
17//
18
19#ifndef MP_BYTE_ARRAY_H__
20#define MP_BYTE_ARRAY_H__
21
22#include <stddef.h>
23#include <memory>
24
25#ifndef MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE
26#define MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE 4096
27#endif
28
29namespace mp {
30
31static const size_t BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE = MP_BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE;
32
33template <typename Allocator = std::allocator<char> >
34class byte_array {
35public:
36        typedef char value_type;
37        typedef size_t size_type;
38        typedef char* iterator;
39        typedef const char* const_iterator;
40        typedef char& reference;
41        typedef const char& const_reference;
42        typedef ptrdiff_t difference_type;
43        typedef Allocator allocator_type;
44
45public:
46        byte_array(size_type initial_size=BYTE_ARRAY_DEFAULT_INITIAL_ALLOCATION_SIZE);
47        ~byte_array();
48
49        iterator begin();
50        const_iterator begin() const;
51
52        iterator end();
53        const_iterator end() const;
54
55        bool empty() const;
56        size_type size() const;
57        size_type capacity() const;
58        size_type space() const;
59
60        void produced(size_type produced_size);
61        void consumed(size_type consumed_size);
62        void clear();
63
64        void reserve(size_type new_size);
65        void reserve_space(size_type required_size);
66
67        void swap(byte_array& other);
68
69public:
70        void read(void* buffer, size_type size);
71
72        void write(const void* buffer, size_type size);
73
74MP_ARGS_BEGIN
75        template <MP_ARGS_TEMPLATE>
76        void read(MP_ARGS_PARAMS_PTR);
77MP_ARGS_END
78
79MP_ARGS_BEGIN
80        template <MP_ARGS_TEMPLATE>
81        void write(MP_ARGS_PARAMS);
82MP_ARGS_END
83
84private:
85        char* storage;
86        char* start;
87        char* finish;
88        char* allocated_end;
89
90private:
91        size_type allocated_size() const;
92        allocator_type get_allocator() const;
93
94private:
95        byte_array(const byte_array<Allocator>&);
96};
97
98
99}  // namespace mp
100
101#include "mp/byte_array_impl.h"
102
103#endif /* mp/byte_array.h */
104
Note: See TracBrowser for help on using the browser.