3
* Copyright (c) 1998-2002
6
* Permission to use, copy, modify, distribute and sell this software
7
* and its documentation for any purpose is hereby granted without fee,
8
* provided that the above copyright notice appear in all copies and
9
* that both that copyright notice and this permission notice appear
10
* in supporting documentation. Dr John Maddock makes no representations
11
* about the suitability of this software for any purpose.
12
* It is provided "as is" without express or implied warranty.
17
* LOCATION: see http://www.boost.org for most recent version.
18
* FILE regex_raw_buffer.hpp
19
* VERSION see <boost/version.hpp>
20
* DESCRIPTION: Raw character buffer for regex code.
21
* Note this is an internal header file included
22
* by regex.hpp, do not include on its own.
25
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
26
#define BOOST_REGEX_RAW_BUFFER_HPP
28
#ifndef BOOST_REGEX_CONFIG_HPP
29
#include <boost/regex/config.hpp>
36
#pragma option push -a8 -b -Vx -Ve -pc
39
struct empty_padding{};
93
padding_size = padding3<sizeof(padding)>::padding_size,
94
padding_mask = padding3<sizeof(padding)>::padding_mask
99
// basically this is a simplified vector<unsigned char>
100
// this is used by reg_expression for expression storage
103
template <class Allocator>
107
typedef Allocator allocator_type;
108
typedef typename boost::detail::rebind_allocator<unsigned char, allocator_type>::type alloc_inst_type;
109
typedef typename alloc_inst_type::size_type size_type;
110
typedef typename alloc_inst_type::pointer pointer;
113
// empty member optimisation:
114
struct alloc_data : public alloc_inst_type
116
typename alloc_inst_type::pointer last;
117
alloc_data(const Allocator& a) : alloc_inst_type(a){}
122
raw_storage(const Allocator& a = Allocator());
123
raw_storage(size_type n, const Allocator& a = Allocator());
127
alloc_inst.deallocate(start, (alloc_inst.last - start));
130
void BOOST_REGEX_CALL resize(size_type n);
132
void* BOOST_REGEX_CALL extend(size_type n)
134
if(size_type(alloc_inst.last - end) < n)
135
resize(n + (end - start));
136
register void* result = end;
141
void* BOOST_REGEX_CALL insert(size_type pos, size_type n);
143
size_type BOOST_REGEX_CALL size()
148
size_type BOOST_REGEX_CALL capacity()
150
return alloc_inst.last - start;
153
void* BOOST_REGEX_CALL data()const
158
size_type BOOST_REGEX_CALL index(void* ptr)
160
return reinterpret_cast<unsigned char*>(ptr) - reinterpret_cast<unsigned char*>(data());
163
void BOOST_REGEX_CALL clear()
168
void BOOST_REGEX_CALL align()
170
// move end up to a boundary:
171
end = reinterpret_cast<unsigned char*>(start) + (((reinterpret_cast<unsigned char*>(end) - reinterpret_cast<unsigned char*>(start)) + padding_mask) & ~padding_mask);
174
Allocator BOOST_REGEX_CALL allocator()const;
177
template <class Allocator>
178
raw_storage<Allocator>::raw_storage(const Allocator& a)
181
start = end = alloc_inst.allocate(1024);
182
BOOST_REGEX_NOEH_ASSERT(start)
183
alloc_inst.last = start + 1024;
186
template <class Allocator>
187
raw_storage<Allocator>::raw_storage(size_type n, const Allocator& a)
190
start = end = alloc_inst.allocate(n);
191
BOOST_REGEX_NOEH_ASSERT(start)
192
alloc_inst.last = start + n;
195
template <class Allocator>
196
Allocator BOOST_REGEX_CALL raw_storage<Allocator>::allocator()const
201
template <class Allocator>
202
void BOOST_REGEX_CALL raw_storage<Allocator>::resize(size_type n)
204
register size_type newsize = (alloc_inst.last - start) * 2;
205
register size_type datasize = end - start;
208
// extend newsize to WORD/DWORD boundary:
209
newsize = (newsize + padding_mask) & ~(padding_mask);
211
// allocate and copy data:
212
register unsigned char* ptr = alloc_inst.allocate(newsize);
213
BOOST_REGEX_NOEH_ASSERT(ptr)
214
std::memcpy(ptr, start, datasize);
216
// get rid of old buffer:
217
alloc_inst.deallocate(start, (alloc_inst.last - start));
219
// and set up pointers:
221
end = ptr + datasize;
222
alloc_inst.last = ptr + newsize;
225
template <class Allocator>
226
void* BOOST_REGEX_CALL raw_storage<Allocator>::insert(size_type pos, size_type n)
228
jm_assert(pos <= size_type(end - start));
229
if(size_type(alloc_inst.last - end) < n)
230
resize(n + (end - start));
231
register void* result = start + pos;
232
std::memmove(start + pos + n, start + pos, (end - start) - pos);
241
} // namespace re_detail