600
|
1 |
/*
|
|
2 |
*
|
|
3 |
* Copyright (c) 1998-2002
|
|
4 |
* John Maddock
|
|
5 |
*
|
|
6 |
* Use, modification and distribution are subject to the
|
|
7 |
* Boost Software License, Version 1.0. (See accompanying file
|
|
8 |
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
9 |
*
|
|
10 |
*/
|
|
11 |
|
|
12 |
/*
|
|
13 |
* LOCATION: see http://www.boost.org for most recent version.
|
|
14 |
* FILE regex_raw_buffer.hpp
|
|
15 |
* VERSION see <boost/version.hpp>
|
|
16 |
* DESCRIPTION: Raw character buffer for regex code.
|
|
17 |
* Note this is an internal header file included
|
|
18 |
* by regex.hpp, do not include on its own.
|
|
19 |
*/
|
|
20 |
|
|
21 |
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
|
|
22 |
#define BOOST_REGEX_RAW_BUFFER_HPP
|
|
23 |
|
|
24 |
#ifndef BOOST_REGEX_CONFIG_HPP
|
|
25 |
#include <boost/regex/config.hpp>
|
|
26 |
#endif
|
|
27 |
|
|
28 |
#include <algorithm>
|
|
29 |
#include <cstddef>
|
|
30 |
|
|
31 |
namespace boost{
|
|
32 |
namespace re_detail{
|
|
33 |
|
|
34 |
#ifdef BOOST_MSVC
|
|
35 |
#pragma warning(push)
|
|
36 |
#pragma warning(disable: 4103)
|
|
37 |
#endif
|
|
38 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
39 |
# include BOOST_ABI_PREFIX
|
|
40 |
#endif
|
|
41 |
#ifdef BOOST_MSVC
|
|
42 |
#pragma warning(pop)
|
|
43 |
#endif
|
|
44 |
|
|
45 |
struct empty_padding{};
|
|
46 |
|
|
47 |
union padding
|
|
48 |
{
|
|
49 |
void* p;
|
|
50 |
unsigned int i;
|
|
51 |
};
|
|
52 |
|
|
53 |
template <int N>
|
|
54 |
struct padding3
|
|
55 |
{
|
|
56 |
enum{
|
|
57 |
padding_size = 8,
|
|
58 |
padding_mask = 7
|
|
59 |
};
|
|
60 |
};
|
|
61 |
|
|
62 |
template<>
|
|
63 |
struct padding3<2>
|
|
64 |
{
|
|
65 |
enum{
|
|
66 |
padding_size = 2,
|
|
67 |
padding_mask = 1
|
|
68 |
};
|
|
69 |
};
|
|
70 |
|
|
71 |
template<>
|
|
72 |
struct padding3<4>
|
|
73 |
{
|
|
74 |
enum{
|
|
75 |
padding_size = 4,
|
|
76 |
padding_mask = 3
|
|
77 |
};
|
|
78 |
};
|
|
79 |
|
|
80 |
template<>
|
|
81 |
struct padding3<8>
|
|
82 |
{
|
|
83 |
enum{
|
|
84 |
padding_size = 8,
|
|
85 |
padding_mask = 7
|
|
86 |
};
|
|
87 |
};
|
|
88 |
|
|
89 |
template<>
|
|
90 |
struct padding3<16>
|
|
91 |
{
|
|
92 |
enum{
|
|
93 |
padding_size = 16,
|
|
94 |
padding_mask = 15
|
|
95 |
};
|
|
96 |
};
|
|
97 |
|
|
98 |
enum{
|
|
99 |
padding_size = padding3<sizeof(padding)>::padding_size,
|
|
100 |
padding_mask = padding3<sizeof(padding)>::padding_mask
|
|
101 |
};
|
|
102 |
|
|
103 |
//
|
|
104 |
// class raw_storage
|
|
105 |
// basically this is a simplified vector<unsigned char>
|
|
106 |
// this is used by basic_regex for expression storage
|
|
107 |
//
|
|
108 |
|
|
109 |
class BOOST_REGEX_DECL raw_storage
|
|
110 |
{
|
|
111 |
public:
|
|
112 |
typedef std::size_t size_type;
|
|
113 |
typedef unsigned char* pointer;
|
|
114 |
private:
|
|
115 |
pointer last, start, end;
|
|
116 |
public:
|
|
117 |
|
|
118 |
raw_storage();
|
|
119 |
raw_storage(size_type n);
|
|
120 |
|
|
121 |
~raw_storage()
|
|
122 |
{
|
|
123 |
::operator delete(start);
|
|
124 |
}
|
|
125 |
|
|
126 |
void BOOST_REGEX_CALL resize(size_type n);
|
|
127 |
|
|
128 |
void* BOOST_REGEX_CALL extend(size_type n)
|
|
129 |
{
|
|
130 |
if(size_type(last - end) < n)
|
|
131 |
resize(n + (end - start));
|
|
132 |
register pointer result = end;
|
|
133 |
end += n;
|
|
134 |
return result;
|
|
135 |
}
|
|
136 |
|
|
137 |
void* BOOST_REGEX_CALL insert(size_type pos, size_type n);
|
|
138 |
|
|
139 |
size_type BOOST_REGEX_CALL size()
|
|
140 |
{
|
|
141 |
return end - start;
|
|
142 |
}
|
|
143 |
|
|
144 |
size_type BOOST_REGEX_CALL capacity()
|
|
145 |
{
|
|
146 |
return last - start;
|
|
147 |
}
|
|
148 |
|
|
149 |
void* BOOST_REGEX_CALL data()const
|
|
150 |
{
|
|
151 |
return start;
|
|
152 |
}
|
|
153 |
|
|
154 |
size_type BOOST_REGEX_CALL index(void* ptr)
|
|
155 |
{
|
|
156 |
return static_cast<pointer>(ptr) - static_cast<pointer>(data());
|
|
157 |
}
|
|
158 |
|
|
159 |
void BOOST_REGEX_CALL clear()
|
|
160 |
{
|
|
161 |
end = start;
|
|
162 |
}
|
|
163 |
|
|
164 |
void BOOST_REGEX_CALL align()
|
|
165 |
{
|
|
166 |
// move end up to a boundary:
|
|
167 |
end = start + (((end - start) + padding_mask) & ~padding_mask);
|
|
168 |
}
|
|
169 |
void swap(raw_storage& that)
|
|
170 |
{
|
|
171 |
std::swap(start, that.start);
|
|
172 |
std::swap(end, that.end);
|
|
173 |
std::swap(last, that.last);
|
|
174 |
}
|
|
175 |
};
|
|
176 |
|
|
177 |
inline raw_storage::raw_storage()
|
|
178 |
{
|
|
179 |
last = start = end = 0;
|
|
180 |
}
|
|
181 |
|
|
182 |
inline raw_storage::raw_storage(size_type n)
|
|
183 |
{
|
|
184 |
start = end = static_cast<pointer>(::operator new(n));
|
|
185 |
BOOST_REGEX_NOEH_ASSERT(start)
|
|
186 |
last = start + n;
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
#ifdef BOOST_MSVC
|
|
191 |
#pragma warning(push)
|
|
192 |
#pragma warning(disable: 4103)
|
|
193 |
#endif
|
|
194 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
195 |
# include BOOST_ABI_SUFFIX
|
|
196 |
#endif
|
|
197 |
#ifdef BOOST_MSVC
|
|
198 |
#pragma warning(pop)
|
|
199 |
#endif
|
|
200 |
|
|
201 |
} // namespace re_detail
|
|
202 |
} // namespace boost
|
|
203 |
|
|
204 |
#endif
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|