1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 Copyright (c) 2001-2003 Daniel Nuffer
4 http://spirit.sourceforge.net/
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_CHSET_HPP
10 #define BOOST_SPIRIT_CHSET_HPP
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/shared_ptr.hpp>
14 #include <boost/spirit/home/classic/namespace.hpp>
15 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
16 #include <boost/spirit/home/classic/utility/impl/chset/basic_chset.hpp>
18 ///////////////////////////////////////////////////////////////////////////////
19 namespace boost { namespace spirit {
21 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
23 namespace utility { namespace impl {
25 // This is here because some compilers choke on out-of-line member
26 // template functions. And we don't want to put the whole algorithm
27 // in the chset constructor in the class definition.
28 template <typename CharT, typename CharT2>
29 void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
30 CharT2 const* definition);
32 }} // namespace utility::impl
34 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 template <typename CharT = char>
40 class chset: public char_parser<chset<CharT> > {
44 chset(chset const& arg_);
45 explicit chset(CharT arg_);
46 explicit chset(anychar_parser arg_);
47 explicit chset(nothing_parser arg_);
48 explicit chset(chlit<CharT> const& arg_);
49 explicit chset(range<CharT> const& arg_);
50 explicit chset(negated_char_parser<chlit<CharT> > const& arg_);
51 explicit chset(negated_char_parser<range<CharT> > const& arg_);
53 template <typename CharT2>
54 explicit chset(CharT2 const* definition)
55 : ptr(new basic_chset<CharT>())
57 utility::impl::construct_chset(ptr, definition);
61 chset& operator=(chset const& rhs);
62 chset& operator=(CharT rhs);
63 chset& operator=(anychar_parser rhs);
64 chset& operator=(nothing_parser rhs);
65 chset& operator=(chlit<CharT> const& rhs);
66 chset& operator=(range<CharT> const& rhs);
67 chset& operator=(negated_char_parser<chlit<CharT> > const& rhs);
68 chset& operator=(negated_char_parser<range<CharT> > const& rhs);
70 void set(range<CharT> const& arg_);
71 void set(negated_char_parser<chlit<CharT> > const& arg_);
72 void set(negated_char_parser<range<CharT> > const& arg_);
74 void clear(range<CharT> const& arg_);
75 void clear(negated_char_parser<range<CharT> > const& arg_);
76 bool test(CharT ch) const;
80 chset& operator|=(chset const& x);
81 chset& operator&=(chset const& x);
82 chset& operator-=(chset const& x);
83 chset& operator^=(chset const& x);
87 boost::shared_ptr<basic_chset<CharT> > ptr;
90 ///////////////////////////////////////////////////////////////////////////////
92 // Generator functions
94 ///////////////////////////////////////////////////////////////////////////////
95 template <typename CharT>
97 chset_p(chlit<CharT> const& arg_)
98 { return chset<CharT>(arg_); }
100 //////////////////////////////////
101 template <typename CharT>
103 chset_p(range<CharT> const& arg_)
104 { return chset<CharT>(arg_); }
106 template <typename CharT>
108 chset_p(negated_char_parser<chlit<CharT> > const& arg_)
109 { return chset<CharT>(arg_); }
111 template <typename CharT>
113 chset_p(negated_char_parser<range<CharT> > const& arg_)
114 { return chset<CharT>(arg_); }
116 //////////////////////////////////
118 chset_p(char const* init)
119 { return chset<char>(init); }
121 //////////////////////////////////
122 inline chset<wchar_t>
123 chset_p(wchar_t const* init)
124 { return chset<wchar_t>(init); }
126 //////////////////////////////////
129 { return chset<char>(ch); }
131 //////////////////////////////////
132 inline chset<wchar_t>
134 { return chset<wchar_t>(ch); }
136 //////////////////////////////////
139 { return chset<int>(ch); }
141 //////////////////////////////////
142 inline chset<unsigned int>
143 chset_p(unsigned int ch)
144 { return chset<unsigned int>(ch); }
146 //////////////////////////////////
149 { return chset<short>(ch); }
151 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
152 //////////////////////////////////
153 inline chset<unsigned short>
154 chset_p(unsigned short ch)
155 { return chset<unsigned short>(ch); }
157 //////////////////////////////////
160 { return chset<long>(ch); }
162 //////////////////////////////////
163 inline chset<unsigned long>
164 chset_p(unsigned long ch)
165 { return chset<unsigned long>(ch); }
167 #ifdef BOOST_HAS_LONG_LONG
168 //////////////////////////////////
169 inline chset< ::boost::long_long_type>
170 chset_p( ::boost::long_long_type ch)
171 { return chset< ::boost::long_long_type>(ch); }
173 //////////////////////////////////
174 inline chset< ::boost::ulong_long_type>
175 chset_p( ::boost::ulong_long_type ch)
176 { return chset< ::boost::ulong_long_type>(ch); }
179 ///////////////////////////////////////////////////////////////////////////////
180 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
182 }} // namespace BOOST_SPIRIT_CLASSIC_NS
186 #include <boost/spirit/home/classic/utility/impl/chset.ipp>
187 #include <boost/spirit/home/classic/utility/chset_operators.hpp>