chset.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_CHSET_HPP
  9. #define BOOST_SPIRIT_CHSET_HPP
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include <boost/shared_ptr.hpp>
  12. #include <boost/spirit/home/classic/namespace.hpp>
  13. #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
  14. #include <boost/spirit/home/classic/utility/impl/chset/basic_chset.hpp>
  15. ///////////////////////////////////////////////////////////////////////////////
  16. namespace boost { namespace spirit {
  17. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  18. namespace utility { namespace impl {
  19. // This is here because some compilers choke on out-of-line member
  20. // template functions. And we don't want to put the whole algorithm
  21. // in the chset constructor in the class definition.
  22. template <typename CharT, typename CharT2>
  23. void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
  24. CharT2 const* definition);
  25. }} // namespace utility::impl
  26. ///////////////////////////////////////////////////////////////////////////////
  27. //
  28. // chset class
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. template <typename CharT = char>
  32. class chset: public char_parser<chset<CharT> > {
  33. public:
  34. chset();
  35. chset(chset const& arg_);
  36. explicit chset(CharT arg_);
  37. explicit chset(anychar_parser arg_);
  38. explicit chset(nothing_parser arg_);
  39. explicit chset(chlit<CharT> const& arg_);
  40. explicit chset(range<CharT> const& arg_);
  41. explicit chset(negated_char_parser<chlit<CharT> > const& arg_);
  42. explicit chset(negated_char_parser<range<CharT> > const& arg_);
  43. template <typename CharT2>
  44. explicit chset(CharT2 const* definition)
  45. : ptr(new basic_chset<CharT>())
  46. {
  47. utility::impl::construct_chset(ptr, definition);
  48. }
  49. ~chset();
  50. chset& operator=(chset const& rhs);
  51. chset& operator=(CharT rhs);
  52. chset& operator=(anychar_parser rhs);
  53. chset& operator=(nothing_parser rhs);
  54. chset& operator=(chlit<CharT> const& rhs);
  55. chset& operator=(range<CharT> const& rhs);
  56. chset& operator=(negated_char_parser<chlit<CharT> > const& rhs);
  57. chset& operator=(negated_char_parser<range<CharT> > const& rhs);
  58. void set(range<CharT> const& arg_);
  59. void set(negated_char_parser<chlit<CharT> > const& arg_);
  60. void set(negated_char_parser<range<CharT> > const& arg_);
  61. void clear(range<CharT> const& arg_);
  62. void clear(negated_char_parser<range<CharT> > const& arg_);
  63. bool test(CharT ch) const;
  64. chset& inverse();
  65. void swap(chset& x);
  66. chset& operator|=(chset const& x);
  67. chset& operator&=(chset const& x);
  68. chset& operator-=(chset const& x);
  69. chset& operator^=(chset const& x);
  70. private:
  71. boost::shared_ptr<basic_chset<CharT> > ptr;
  72. };
  73. ///////////////////////////////////////////////////////////////////////////////
  74. //
  75. // Generator functions
  76. //
  77. ///////////////////////////////////////////////////////////////////////////////
  78. template <typename CharT>
  79. inline chset<CharT>
  80. chset_p(chlit<CharT> const& arg_)
  81. { return chset<CharT>(arg_); }
  82. //////////////////////////////////
  83. template <typename CharT>
  84. inline chset<CharT>
  85. chset_p(range<CharT> const& arg_)
  86. { return chset<CharT>(arg_); }
  87. template <typename CharT>
  88. inline chset<CharT>
  89. chset_p(negated_char_parser<chlit<CharT> > const& arg_)
  90. { return chset<CharT>(arg_); }
  91. template <typename CharT>
  92. inline chset<CharT>
  93. chset_p(negated_char_parser<range<CharT> > const& arg_)
  94. { return chset<CharT>(arg_); }
  95. //////////////////////////////////
  96. inline chset<char>
  97. chset_p(char const* init)
  98. { return chset<char>(init); }
  99. //////////////////////////////////
  100. inline chset<wchar_t>
  101. chset_p(wchar_t const* init)
  102. { return chset<wchar_t>(init); }
  103. //////////////////////////////////
  104. inline chset<char>
  105. chset_p(char ch)
  106. { return chset<char>(ch); }
  107. //////////////////////////////////
  108. inline chset<wchar_t>
  109. chset_p(wchar_t ch)
  110. { return chset<wchar_t>(ch); }
  111. //////////////////////////////////
  112. inline chset<int>
  113. chset_p(int ch)
  114. { return chset<int>(ch); }
  115. //////////////////////////////////
  116. inline chset<unsigned int>
  117. chset_p(unsigned int ch)
  118. { return chset<unsigned int>(ch); }
  119. //////////////////////////////////
  120. inline chset<short>
  121. chset_p(short ch)
  122. { return chset<short>(ch); }
  123. #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
  124. //////////////////////////////////
  125. inline chset<unsigned short>
  126. chset_p(unsigned short ch)
  127. { return chset<unsigned short>(ch); }
  128. #endif
  129. //////////////////////////////////
  130. inline chset<long>
  131. chset_p(long ch)
  132. { return chset<long>(ch); }
  133. //////////////////////////////////
  134. inline chset<unsigned long>
  135. chset_p(unsigned long ch)
  136. { return chset<unsigned long>(ch); }
  137. #ifdef BOOST_HAS_LONG_LONG
  138. //////////////////////////////////
  139. inline chset< ::boost::long_long_type>
  140. chset_p( ::boost::long_long_type ch)
  141. { return chset< ::boost::long_long_type>(ch); }
  142. //////////////////////////////////
  143. inline chset< ::boost::ulong_long_type>
  144. chset_p( ::boost::ulong_long_type ch)
  145. { return chset< ::boost::ulong_long_type>(ch); }
  146. #endif
  147. ///////////////////////////////////////////////////////////////////////////////
  148. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  149. }} // namespace BOOST_SPIRIT_CLASSIC_NS
  150. #endif
  151. #include <boost/spirit/home/classic/utility/impl/chset.ipp>
  152. #include <boost/spirit/home/classic/utility/chset_operators.hpp>