9
3

basic_chset.hpp 3.6 KB

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