File indexing completed on 2025-01-18 09:51:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef BOOST_REGEX_RAW_BUFFER_HPP
0022 #define BOOST_REGEX_RAW_BUFFER_HPP
0023
0024 #ifndef BOOST_REGEX_CONFIG_HPP
0025 #include <boost/regex/config.hpp>
0026 #endif
0027
0028 #include <algorithm>
0029 #include <cstddef>
0030
0031 namespace boost{
0032 namespace BOOST_REGEX_DETAIL_NS{
0033
0034 #ifdef BOOST_MSVC
0035 #pragma warning(push)
0036 #pragma warning(disable: 4103)
0037 #endif
0038 #ifdef BOOST_HAS_ABI_HEADERS
0039 # include BOOST_ABI_PREFIX
0040 #endif
0041 #ifdef BOOST_MSVC
0042 #pragma warning(pop)
0043 #endif
0044
0045 struct empty_padding{};
0046
0047 union padding
0048 {
0049 void* p;
0050 unsigned int i;
0051 };
0052
0053 template <int N>
0054 struct padding3
0055 {
0056 enum{
0057 padding_size = 8,
0058 padding_mask = 7
0059 };
0060 };
0061
0062 template<>
0063 struct padding3<2>
0064 {
0065 enum{
0066 padding_size = 2,
0067 padding_mask = 1
0068 };
0069 };
0070
0071 template<>
0072 struct padding3<4>
0073 {
0074 enum{
0075 padding_size = 4,
0076 padding_mask = 3
0077 };
0078 };
0079
0080 template<>
0081 struct padding3<8>
0082 {
0083 enum{
0084 padding_size = 8,
0085 padding_mask = 7
0086 };
0087 };
0088
0089 template<>
0090 struct padding3<16>
0091 {
0092 enum{
0093 padding_size = 16,
0094 padding_mask = 15
0095 };
0096 };
0097
0098 enum{
0099 padding_size = padding3<sizeof(padding)>::padding_size,
0100 padding_mask = padding3<sizeof(padding)>::padding_mask
0101 };
0102
0103
0104
0105
0106
0107
0108
0109 class raw_storage
0110 {
0111 public:
0112 typedef std::size_t size_type;
0113 typedef unsigned char* pointer;
0114 private:
0115 pointer last, start, end;
0116 public:
0117
0118 raw_storage();
0119 raw_storage(size_type n);
0120
0121 ~raw_storage()
0122 {
0123 ::operator delete(start);
0124 }
0125
0126 void BOOST_REGEX_CALL resize(size_type n)
0127 {
0128 size_type newsize = start ? last - start : 1024;
0129 while (newsize < n)
0130 newsize *= 2;
0131 size_type datasize = end - start;
0132
0133 newsize = (newsize + padding_mask) & ~(padding_mask);
0134
0135
0136 pointer ptr = static_cast<pointer>(::operator new(newsize));
0137 BOOST_REGEX_NOEH_ASSERT(ptr)
0138 if (start)
0139 std::memcpy(ptr, start, datasize);
0140
0141
0142 ::operator delete(start);
0143
0144
0145 start = ptr;
0146 end = ptr + datasize;
0147 last = ptr + newsize;
0148 }
0149
0150 void* BOOST_REGEX_CALL extend(size_type n)
0151 {
0152 if(size_type(last - end) < n)
0153 resize(n + (end - start));
0154 pointer result = end;
0155 end += n;
0156 return result;
0157 }
0158
0159 void* BOOST_REGEX_CALL insert(size_type pos, size_type n)
0160 {
0161 BOOST_REGEX_ASSERT(pos <= size_type(end - start));
0162 if (size_type(last - end) < n)
0163 resize(n + (end - start));
0164 void* result = start + pos;
0165 std::memmove(start + pos + n, start + pos, (end - start) - pos);
0166 end += n;
0167 return result;
0168 }
0169
0170 size_type BOOST_REGEX_CALL size()
0171 {
0172 return size_type(end - start);
0173 }
0174
0175 size_type BOOST_REGEX_CALL capacity()
0176 {
0177 return size_type(last - start);
0178 }
0179
0180 void* BOOST_REGEX_CALL data()const
0181 {
0182 return start;
0183 }
0184
0185 size_type BOOST_REGEX_CALL index(void* ptr)
0186 {
0187 return size_type(static_cast<pointer>(ptr) - static_cast<pointer>(data()));
0188 }
0189
0190 void BOOST_REGEX_CALL clear()
0191 {
0192 end = start;
0193 }
0194
0195 void BOOST_REGEX_CALL align()
0196 {
0197
0198 end = start + (((end - start) + padding_mask) & ~padding_mask);
0199 }
0200 void swap(raw_storage& that)
0201 {
0202 std::swap(start, that.start);
0203 std::swap(end, that.end);
0204 std::swap(last, that.last);
0205 }
0206 };
0207
0208 inline raw_storage::raw_storage()
0209 {
0210 last = start = end = 0;
0211 }
0212
0213 inline raw_storage::raw_storage(size_type n)
0214 {
0215 start = end = static_cast<pointer>(::operator new(n));
0216 BOOST_REGEX_NOEH_ASSERT(start)
0217 last = start + n;
0218 }
0219
0220
0221 #ifdef BOOST_MSVC
0222 #pragma warning(push)
0223 #pragma warning(disable: 4103)
0224 #endif
0225 #ifdef BOOST_HAS_ABI_HEADERS
0226 # include BOOST_ABI_SUFFIX
0227 #endif
0228 #ifdef BOOST_MSVC
0229 #pragma warning(pop)
0230 #endif
0231
0232 }
0233 }
0234
0235 #endif
0236
0237
0238
0239
0240
0241