Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:48

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003     Copyright (c) 2001-2009 Daniel Nuffer
0004     http://spirit.sourceforge.net/
0005 
0006   Distributed under the Boost Software License, Version 1.0. (See accompanying
0007   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #ifndef BOOST_SPIRIT_BASIC_CHSET_APRIL_17_2008
0010 #define BOOST_SPIRIT_BASIC_CHSET_APRIL_17_2008
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 ///////////////////////////////////////////////////////////////////////////////
0017 #include <bitset>
0018 #include <climits> 
0019 #include <boost/spirit/home/support/char_set/range_run.hpp>
0020 
0021 namespace boost { namespace spirit { namespace support { namespace detail
0022 {
0023     ///////////////////////////////////////////////////////////////////////////
0024     //
0025     //  basic_chset: basic character set implementation using range_run
0026     //
0027     ///////////////////////////////////////////////////////////////////////////
0028     template <typename Char>
0029     struct basic_chset
0030     {
0031         basic_chset() {}
0032         basic_chset(basic_chset const& arg_)
0033           : rr(arg_.rr) {}
0034 
0035         bool
0036         test(Char v) const
0037         {
0038             return rr.test(v);
0039         }
0040 
0041         void
0042         set(Char from, Char to)
0043         {
0044             rr.set(range<Char>(from, to));
0045         }
0046 
0047         void
0048         set(Char c)
0049         {
0050             rr.set(range<Char>(c, c));
0051         }
0052 
0053         void
0054         clear(Char from, Char to)
0055         {
0056             rr.clear(range<Char>(from, to));
0057         }
0058 
0059         void
0060         clear(Char c)
0061         {
0062             rr.clear(range<Char>(c, c));
0063         }
0064 
0065         void
0066         clear()
0067         {
0068             rr.clear();
0069         }
0070 
0071         void
0072         inverse()
0073         {
0074             basic_chset inv;
0075             inv.set(
0076                 (std::numeric_limits<Char>::min)(),
0077                 (std::numeric_limits<Char>::max)()
0078             );
0079             inv -= *this;
0080             swap(inv);
0081         }
0082 
0083         void
0084         swap(basic_chset& x)
0085         {
0086             rr.swap(x.rr);
0087         }
0088 
0089 
0090         basic_chset&
0091         operator|=(basic_chset const& x)
0092         {
0093             typedef typename range_run<Char>::const_iterator const_iterator;
0094             for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter)
0095                 rr.set(*iter);
0096             return *this;
0097         }
0098 
0099         basic_chset&
0100         operator&=(basic_chset const& x)
0101         {
0102             basic_chset inv;
0103             inv.set(
0104                 (std::numeric_limits<Char>::min)(),
0105                 (std::numeric_limits<Char>::max)()
0106             );
0107             inv -= x;
0108             *this -= inv;
0109             return *this;
0110         }
0111 
0112         basic_chset&
0113         operator-=(basic_chset const& x)
0114         {
0115             typedef typename range_run<Char>::const_iterator const_iterator;
0116             for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter)
0117                 rr.clear(*iter);
0118             return *this;
0119         }
0120 
0121         basic_chset&
0122         operator^=(basic_chset const& x)
0123         {
0124             basic_chset bma = x;
0125             bma -= *this;
0126             *this -= x;
0127             *this |= bma;
0128             return *this;
0129         }
0130 
0131         private: range_run<Char> rr;
0132     };
0133 
0134 #if (CHAR_BIT == 8)
0135 
0136     ///////////////////////////////////////////////////////////////////////////
0137     //
0138     //  basic_chset: specializations for 8 bit chars using std::bitset
0139     //
0140     ///////////////////////////////////////////////////////////////////////////
0141     template <typename Char>
0142     struct basic_chset_8bit
0143     {
0144         basic_chset_8bit() {}
0145         basic_chset_8bit(basic_chset_8bit const& arg_)
0146           : bset(arg_.bset) {}
0147 
0148         bool
0149         test(Char v) const
0150         {
0151             return bset.test((unsigned char)v);
0152         }
0153 
0154         void
0155         set(Char from, Char to)
0156         {
0157             for (int i = from; i <= to; ++i)
0158                 bset.set((unsigned char)i);
0159         }
0160 
0161         void
0162         set(Char c)
0163         {
0164             bset.set((unsigned char)c);
0165         }
0166 
0167         void
0168         clear(Char from, Char to)
0169         {
0170             for (int i = from; i <= to; ++i)
0171                 bset.reset((unsigned char)i);
0172         }
0173 
0174         void
0175         clear(Char c)
0176         {
0177             bset.reset((unsigned char)c);
0178         }
0179 
0180         void
0181         clear()
0182         {
0183             bset.reset();
0184         }
0185 
0186         void
0187         inverse()
0188         {
0189             bset.flip();
0190         }
0191 
0192         void
0193         swap(basic_chset_8bit& x)
0194         {
0195             std::swap(bset, x.bset);
0196         }
0197 
0198         basic_chset_8bit&
0199         operator|=(basic_chset_8bit const& x)
0200         {
0201             bset |= x.bset;
0202             return *this;
0203         }
0204 
0205         basic_chset_8bit&
0206         operator&=(basic_chset_8bit const& x)
0207         {
0208             bset &= x.bset;
0209             return *this;
0210         }
0211 
0212         basic_chset_8bit&
0213         operator-=(basic_chset_8bit const& x)
0214         {
0215             bset &= ~x.bset;
0216             return *this;
0217         }
0218 
0219         basic_chset_8bit&
0220         operator^=(basic_chset_8bit const& x)
0221         {
0222             bset ^= x.bset;
0223             return *this;
0224         }
0225 
0226         private: std::bitset<256> bset;
0227     };
0228 
0229     /////////////////////////////////
0230     template <>
0231     struct basic_chset<char>
0232       : basic_chset_8bit<char> {};
0233 
0234     /////////////////////////////////
0235     template <>
0236     struct basic_chset<signed char>
0237       : basic_chset_8bit<signed char> {};
0238 
0239     /////////////////////////////////
0240     template <>
0241     struct basic_chset<unsigned char>
0242       : basic_chset_8bit<unsigned char> {};
0243 
0244 #endif // #if (CHAR_BIT == 8)
0245 
0246 }}}}
0247 
0248 #endif
0249