blob: 199035922d16ab4fb22528e37a2083413c5b9071 [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001/*
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 <ndnboost/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 NDNBOOST_REGEX_RAW_BUFFER_HPP
22#define NDNBOOST_REGEX_RAW_BUFFER_HPP
23
24#ifndef NDNBOOST_REGEX_CONFIG_HPP
25#include <ndnboost/regex/config.hpp>
26#endif
27
28#include <algorithm>
29#include <cstddef>
30
31namespace ndnboost{
32 namespace re_detail{
33
34#ifdef NDNBOOST_MSVC
35#pragma warning(push)
36#pragma warning(disable: 4103)
37#endif
38#ifdef NDNBOOST_HAS_ABI_HEADERS
39# include NDNBOOST_ABI_PREFIX
40#endif
41#ifdef NDNBOOST_MSVC
42#pragma warning(pop)
43#endif
44
45struct empty_padding{};
46
47union padding
48{
49 void* p;
50 unsigned int i;
51};
52
53template <int N>
54struct padding3
55{
56 enum{
57 padding_size = 8,
58 padding_mask = 7
59 };
60};
61
62template<>
63struct padding3<2>
64{
65 enum{
66 padding_size = 2,
67 padding_mask = 1
68 };
69};
70
71template<>
72struct padding3<4>
73{
74 enum{
75 padding_size = 4,
76 padding_mask = 3
77 };
78};
79
80template<>
81struct padding3<8>
82{
83 enum{
84 padding_size = 8,
85 padding_mask = 7
86 };
87};
88
89template<>
90struct padding3<16>
91{
92 enum{
93 padding_size = 16,
94 padding_mask = 15
95 };
96};
97
98enum{
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
109class NDNBOOST_REGEX_DECL raw_storage
110{
111public:
112 typedef std::size_t size_type;
113 typedef unsigned char* pointer;
114private:
115 pointer last, start, end;
116public:
117
118 raw_storage();
119 raw_storage(size_type n);
120
121 ~raw_storage()
122 {
123 ::operator delete(start);
124 }
125
126 void NDNBOOST_REGEX_CALL resize(size_type n);
127
128 void* NDNBOOST_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* NDNBOOST_REGEX_CALL insert(size_type pos, size_type n);
138
139 size_type NDNBOOST_REGEX_CALL size()
140 {
141 return end - start;
142 }
143
144 size_type NDNBOOST_REGEX_CALL capacity()
145 {
146 return last - start;
147 }
148
149 void* NDNBOOST_REGEX_CALL data()const
150 {
151 return start;
152 }
153
154 size_type NDNBOOST_REGEX_CALL index(void* ptr)
155 {
156 return static_cast<pointer>(ptr) - static_cast<pointer>(data());
157 }
158
159 void NDNBOOST_REGEX_CALL clear()
160 {
161 end = start;
162 }
163
164 void NDNBOOST_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
177inline raw_storage::raw_storage()
178{
179 last = start = end = 0;
180}
181
182inline raw_storage::raw_storage(size_type n)
183{
184 start = end = static_cast<pointer>(::operator new(n));
185 NDNBOOST_REGEX_NOEH_ASSERT(start)
186 last = start + n;
187}
188
189
190#ifdef NDNBOOST_MSVC
191#pragma warning(push)
192#pragma warning(disable: 4103)
193#endif
194#ifdef NDNBOOST_HAS_ABI_HEADERS
195# include NDNBOOST_ABI_SUFFIX
196#endif
197#ifdef NDNBOOST_MSVC
198#pragma warning(pop)
199#endif
200
201} // namespace re_detail
202} // namespace ndnboost
203
204#endif
205
206
207
208
209
210