4 #ifndef FIXED_CHAR_BUF_H_INCLUDED 5 #define FIXED_CHAR_BUF_H_INCLUDED 16 template <
size_t SIZE,
18 class Traits = std::char_traits<CharT> >
22 typedef CharT value_type;
23 typedef value_type* pointer;
24 typedef const value_type* const_pointer;
25 typedef value_type& reference;
26 typedef const value_type& const_reference;
27 typedef size_t size_type;
28 typedef ptrdiff_t difference_type;
29 typedef const value_type* const_iterator;
30 typedef value_type* iterator;
31 typedef std::reverse_iterator<const_iterator>
32 const_reverse_iterator;
33 typedef std::reverse_iterator<iterator> reverse_iterator;
34 typedef std::allocator<CharT> allocator_type;
37 typedef Traits traits_type;
38 static const size_type
npos;
46 range_initialize(s.begin(), s.end());
52 range_initialize(s.begin(), s.end());
56 template <
class InputIter>
57 void insert(iterator pos, InputIter first, InputIter last) {
59 size_type xtra = std::distance(first,last);
61 if (_end-_buffer + xtra >= SIZE)
62 throw std::out_of_range(
"fixed_char_buf");
63 Traits::move(pos+xtra,pos,_end-pos);
65 std::copy(first,last,pos);
71 iterator erase(iterator first, iterator last) {
73 Traits::move(first, last, (_end - last) + 1);
74 const iterator new_finish = _end - (last - first);
88 iterator begin() {
return _buffer;}
89 const_iterator begin()
const {
return _buffer;}
90 iterator end() {
return _end;}
91 const_iterator end()
const {
return _end;}
93 void clear() {_end = _buffer;}
94 size_t max_size()
const {
return SIZE; }
95 bool empty()
const {
return (_end == _buffer); }
96 size_type size()
const {
return _end - _buffer;}
101 for(
int i=0;i<SIZE;++i) {
102 std::swap(_buffer[i],s._buffer[i]);
104 int len = _end - _buffer;
105 _end = s.size()+_buffer;
106 s._end = len+s._buffer;
110 void reserve(size_type n = 0) {
112 throw std::length_error(
"fixed_char_buf");
114 size_type capacity()
const {
return max_size(); }
116 const CharT* c_str()
const {
121 const CharT* data()
const {
129 void element_initialize(size_type n, value_type c) {
131 throw std::length_error(
"fixed_char_buf");
132 std::uninitialized_fill_n(begin(), n, c);
137 template <
class InputIter>
138 void range_initialize(InputIter first, InputIter last) {
139 size_t n = std::distance(first,last);
141 throw std::length_error(
"fixed_char_buf");
142 std::uninitialized_copy(first,last,_buffer);
148 CharT _buffer[SIZE+1];
149 mutable CharT *_end ;
154 template <
size_t SIZE,
class CharT,
class Traits>
155 const fixed_char_buf<SIZE,CharT,Traits>::size_type
157 = (fixed_char_buf<SIZE,CharT,Traits>::size_type) -1;
160 template <
size_t SIZE,
class CharT,
class Traits>
161 const fixed_char_buf<SIZE,CharT,Traits>::allocator_type
const allocator_type & get_allocator() const
(Replace can be defined in terms of erase and insert, so the minimal interface can skip it...
Definition: fixed_char_buf.h:84
void swap(fixed_char_buf &s)
Definition: fixed_char_buf.h:98
static const size_type npos
Definition of "npos" constant:
Definition: fixed_char_buf.h:38
static const allocator_type _allocator
Definition of "_allocator" dummy constant:
Definition: fixed_char_buf.h:150
This class implements the minimal string interface and is intended to be used as a base class for xst...
Definition: fixed_char_buf.h:19