| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2003 Joel de Guzman |
| 3 | Copyright (c) 2001-2003 Daniel Nuffer |
| 4 | http://spirit.sourceforge.net/ |
| 5 | |
| 6 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 7 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | =============================================================================*/ |
| 9 | #ifndef BOOST_SPIRIT_BASIC_CHSET_HPP |
| 10 | #define BOOST_SPIRIT_BASIC_CHSET_HPP |
| 11 | |
| 12 | /////////////////////////////////////////////////////////////////////////////// |
| 13 | #include <bitset> |
| 14 | #include <climits> |
| 15 | #include <boost/spirit/home/classic/utility/impl/chset/range_run.hpp> |
| 16 | #include <boost/spirit/home/classic/namespace.hpp> |
| 17 | |
| 18 | namespace boost { namespace spirit { |
| 19 | |
| 20 | BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN |
| 21 | |
| 22 | /////////////////////////////////////////////////////////////////////////// |
| 23 | // |
| 24 | // basic_chset: basic character set implementation using range_run |
| 25 | // |
| 26 | /////////////////////////////////////////////////////////////////////////// |
| 27 | template <typename CharT> |
| 28 | class basic_chset |
| 29 | { |
| 30 | public: |
| 31 | basic_chset(); |
| 32 | basic_chset(basic_chset const& arg_); |
| 33 | |
| 34 | bool test(CharT v) const; |
| 35 | void set(CharT from, CharT to); |
| 36 | void set(CharT c); |
| 37 | void clear(CharT from, CharT to); |
| 38 | void clear(CharT c); |
| 39 | void clear(); |
| 40 | |
| 41 | void inverse(); |
| 42 | void swap(basic_chset& x); |
| 43 | |
| 44 | basic_chset& operator|=(basic_chset const& x); |
| 45 | basic_chset& operator&=(basic_chset const& x); |
| 46 | basic_chset& operator-=(basic_chset const& x); |
| 47 | basic_chset& operator^=(basic_chset const& x); |
| 48 | |
| 49 | private: utility::impl::range_run<CharT> rr; |
| 50 | }; |
| 51 | |
| 52 | #if (CHAR_BIT == 8) |
| 53 | |
| 54 | /////////////////////////////////////////////////////////////////////////// |
| 55 | // |
| 56 | // basic_chset: specializations for 8 bit chars using std::bitset |
| 57 | // |
| 58 | /////////////////////////////////////////////////////////////////////////// |
| 59 | template <typename CharT> |
| 60 | class basic_chset_8bit { |
| 61 | |
| 62 | public: |
| 63 | basic_chset_8bit(); |
| 64 | basic_chset_8bit(basic_chset_8bit const& arg_); |
| 65 | |
| 66 | bool test(CharT v) const; |
| 67 | void set(CharT from, CharT to); |
| 68 | void set(CharT c); |
| 69 | void clear(CharT from, CharT to); |
| 70 | void clear(CharT c); |
| 71 | void clear(); |
| 72 | |
| 73 | void inverse(); |
| 74 | void swap(basic_chset_8bit& x); |
| 75 | |
| 76 | basic_chset_8bit& operator|=(basic_chset_8bit const& x); |
| 77 | basic_chset_8bit& operator&=(basic_chset_8bit const& x); |
| 78 | basic_chset_8bit& operator-=(basic_chset_8bit const& x); |
| 79 | basic_chset_8bit& operator^=(basic_chset_8bit const& x); |
| 80 | |
| 81 | private: std::bitset<256> bset; |
| 82 | }; |
| 83 | |
| 84 | ///////////////////////////////// |
| 85 | template <> |
| 86 | class basic_chset<char> |
| 87 | : public basic_chset_8bit<char> {}; |
| 88 | |
| 89 | ///////////////////////////////// |
| 90 | template <> |
| 91 | class basic_chset<signed char> |
| 92 | : public basic_chset_8bit<signed char> {}; |
| 93 | |
| 94 | ///////////////////////////////// |
| 95 | template <> |
| 96 | class basic_chset<unsigned char> |
| 97 | : public basic_chset_8bit<unsigned char> {}; |
| 98 | |
| 99 | #endif |
| 100 | |
| 101 | BOOST_SPIRIT_CLASSIC_NAMESPACE_END |
| 102 | |
| 103 | }} // namespace BOOST_SPIRIT_CLASSIC_NS |
| 104 | |
| 105 | #endif |
| 106 | |
| 107 | #include <boost/spirit/home/classic/utility/impl/chset/basic_chset.ipp> |
| 108 | |