Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:26

0001 /*
0002  *
0003  * Copyright (c) 1998-2002
0004  * John Maddock
0005  *
0006  * Use, modification and distribution are subject to the 
0007  * Boost Software License, Version 1.0. (See accompanying file 
0008  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009  *
0010  */
0011 
0012  /*
0013   *   LOCATION:    see http://www.boost.org for most recent version.
0014   *   FILE         regex_raw_buffer.hpp
0015   *   VERSION      see <boost/version.hpp>
0016   *   DESCRIPTION: Raw character buffer for regex code.
0017   *                Note this is an internal header file included
0018   *                by regex.hpp, do not include on its own.
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 // class raw_storage
0105 // basically this is a simplified vector<unsigned char>
0106 // this is used by basic_regex for expression storage
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       // extend newsize to WORD/DWORD boundary:
0133       newsize = (newsize + padding_mask) & ~(padding_mask);
0134 
0135       // allocate and copy data:
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       // get rid of old buffer:
0142       ::operator delete(start);
0143 
0144       // and set up pointers:
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       // move end up to a boundary:
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 } // namespace BOOST_REGEX_DETAIL_NS
0233 } // namespace boost
0234 
0235 #endif
0236 
0237 
0238 
0239 
0240 
0241