3 * Copyright (c) 1998-2000
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
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/re_detail/regex_config.hpp>
36 #if __BORLANDC__ == 0x530
37 #pragma option push -a4 -b -Ve
38 #elif __BORLANDC__ > 0x530
39 #pragma option push -a8 -b -Ve
43 struct empty_padding{};
97 padding_size = padding3<sizeof(padding)>::padding_size,
98 padding_mask = padding3<sizeof(padding)>::padding_mask
103 // basically this is a simplified vector<unsigned char>
104 // this is used by reg_expression for expression storage
107 template <class Allocator>
111 typedef Allocator allocator_type;
112 typedef typename REBIND_TYPE(unsigned char, allocator_type)::size_type size_type;
113 typedef BOOST_RE_MAYBE_TYPENAME REBIND_TYPE(unsigned char, allocator_type) alloc_inst_type;
114 typedef typename REBIND_TYPE(unsigned char, allocator_type)::pointer pointer;
117 // empty member optimisation:
118 struct alloc_data : public alloc_inst_type
120 typename alloc_inst_type::pointer last;
121 alloc_data(const Allocator& a) : alloc_inst_type(a){}
126 raw_storage(const Allocator& a = Allocator());
127 raw_storage(size_type n, const Allocator& a = Allocator());
131 alloc_inst.deallocate(start, (alloc_inst.last - start));
134 void BOOST_RE_CALL resize(size_type n);
136 void* BOOST_RE_CALL extend(size_type n)
138 if(size_type(alloc_inst.last - end) < n)
139 resize(n + (end - start));
140 register void* result = end;
145 void* BOOST_RE_CALL insert(size_type pos, size_type n);
147 size_type BOOST_RE_CALL size()
152 size_type BOOST_RE_CALL capacity()
154 return alloc_inst.last - start;
157 void* BOOST_RE_CALL data()const
162 size_type BOOST_RE_CALL index(void* ptr)
164 return (unsigned char*)ptr - (unsigned char*)data();
167 void BOOST_RE_CALL clear()
172 void BOOST_RE_CALL align()
174 // move end up to a boundary:
175 end = (unsigned char*)start + ((((unsigned char*)end - (unsigned char*)start) + padding_mask) & ~padding_mask);
178 Allocator BOOST_RE_CALL allocator()const;
181 template <class Allocator>
182 CONSTRUCTOR_INLINE raw_storage<Allocator>::raw_storage(const Allocator& a)
185 start = end = alloc_inst.allocate(1024);
186 alloc_inst.last = start + 1024;
189 template <class Allocator>
190 CONSTRUCTOR_INLINE raw_storage<Allocator>::raw_storage(size_type n, const Allocator& a)
193 start = end = alloc_inst.allocate(n);
194 alloc_inst.last = start + n;
197 template <class Allocator>
198 Allocator BOOST_RE_CALL raw_storage<Allocator>::allocator()const
203 template <class Allocator>
204 void BOOST_RE_CALL raw_storage<Allocator>::resize(size_type n)
206 register size_type newsize = (alloc_inst.last - start) * 2;
207 register size_type datasize = end - start;
210 // extend newsize to WORD/DWORD boundary:
211 newsize = (newsize + padding_mask) & ~(padding_mask);
213 // allocate and copy data:
214 register unsigned char* ptr = alloc_inst.allocate(newsize);
215 std::memcpy(ptr, start, datasize);
217 // get rid of old buffer:
218 alloc_inst.deallocate(start, (alloc_inst.last - start));
220 // and set up pointers:
222 end = ptr + datasize;
223 alloc_inst.last = ptr + newsize;
226 template <class Allocator>
227 void* BOOST_RE_CALL raw_storage<Allocator>::insert(size_type pos, size_type n)
229 jm_assert(pos <= size_type(end - start));
230 if(size_type(alloc_inst.last - end) < n)
231 resize(n + (end - start));
232 register void* result = start + pos;
233 std::memmove(start + pos + n, start + pos, (end - start) - pos);
239 #if __BORLANDC__ > 0x520
244 } // namespace re_detail