]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/v4/regex_raw_buffer.hpp
Update to latest from boost 1.34.x branch
[lyx.git] / boost / boost / regex / v4 / regex_raw_buffer.hpp
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_HAS_ABI_HEADERS
35 #  include BOOST_ABI_PREFIX
36 #endif
37
38 struct empty_padding{};
39
40 union padding
41 {
42    void* p;
43    unsigned int i;
44 };
45
46 template <int N>
47 struct padding3
48 {
49    enum{
50       padding_size = 8,
51       padding_mask = 7
52    };
53 };
54
55 template<>
56 struct padding3<2>
57 {
58    enum{
59       padding_size = 2,
60       padding_mask = 1
61    };
62 };
63
64 template<>
65 struct padding3<4>
66 {
67    enum{
68       padding_size = 4,
69       padding_mask = 3
70    };
71 };
72
73 template<>
74 struct padding3<8>
75 {
76    enum{
77       padding_size = 8,
78       padding_mask = 7
79    };
80 };
81
82 template<>
83 struct padding3<16>
84 {
85    enum{
86       padding_size = 16,
87       padding_mask = 15
88    };
89 };
90
91 enum{
92    padding_size = padding3<sizeof(padding)>::padding_size,
93    padding_mask = padding3<sizeof(padding)>::padding_mask
94 };
95
96 //
97 // class raw_storage
98 // basically this is a simplified vector<unsigned char>
99 // this is used by basic_regex for expression storage
100 //
101
102 class BOOST_REGEX_DECL raw_storage
103 {
104 public:
105    typedef std::size_t           size_type;
106    typedef unsigned char*        pointer;
107 private:
108    pointer last, start, end;
109 public:
110
111    raw_storage();
112    raw_storage(size_type n);
113
114    ~raw_storage()
115    {
116       ::operator delete(start);
117    }
118
119    void BOOST_REGEX_CALL resize(size_type n);
120    
121    void* BOOST_REGEX_CALL extend(size_type n)
122    {
123       if(size_type(last - end) < n)
124          resize(n + (end - start));
125       register pointer result = end;
126       end += n;
127       return result;
128    }
129
130    void* BOOST_REGEX_CALL insert(size_type pos, size_type n);
131
132    size_type BOOST_REGEX_CALL size()
133    {
134       return end - start;
135    }
136
137    size_type BOOST_REGEX_CALL capacity()
138    {
139       return last - start;
140    }
141
142    void* BOOST_REGEX_CALL data()const
143    {
144       return start;
145    }
146
147    size_type BOOST_REGEX_CALL index(void* ptr)
148    {
149       return static_cast<pointer>(ptr) - static_cast<pointer>(data());
150    }
151
152    void BOOST_REGEX_CALL clear()
153    {
154       end = start;
155    }
156
157    void BOOST_REGEX_CALL align()
158    {
159       // move end up to a boundary:
160       end = start + (((end - start) + padding_mask) & ~padding_mask);
161    }
162    void swap(raw_storage& that)
163    {
164       std::swap(start, that.start);
165       std::swap(end, that.end);
166       std::swap(last, that.last);
167   }
168 };
169
170 inline raw_storage::raw_storage()
171 {
172    last = start = end = 0;
173 }
174
175 inline raw_storage::raw_storage(size_type n)
176 {
177    start = end = static_cast<pointer>(::operator new(n));
178    BOOST_REGEX_NOEH_ASSERT(start)
179    last = start + n;
180 }
181
182
183 #ifdef BOOST_HAS_ABI_HEADERS
184 #  include BOOST_ABI_SUFFIX
185 #endif
186
187 } // namespace re_detail
188 } // namespace boost
189
190 #endif
191
192
193
194
195
196