1
/*=============================================================================
3
Copyright (c) 2001-2003 Joel de Guzman
4
Copyright (c) 2001-2003 Daniel Nuffer
5
http://spirit.sourceforge.net/
7
Permission to copy, use, modify, sell and distribute this software is
8
granted provided this copyright notice appears in all copies. This
9
software is provided "as is" without express or implied warranty, and
10
with no claim as to its suitability for any purpose.
11
=============================================================================*/
12
#ifndef BOOST_SPIRIT_CHSET_HPP
13
#define BOOST_SPIRIT_CHSET_HPP
15
///////////////////////////////////////////////////////////////////////////////
16
#include <boost/shared_ptr.hpp>
17
#include <boost/spirit/core/primitives/primitives.hpp>
18
#include <boost/spirit/utility/impl/chset/basic_chset.hpp>
20
///////////////////////////////////////////////////////////////////////////////
21
namespace boost { namespace spirit {
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
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
34
template <typename CharT, typename FakeT>
35
void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr, chlit<CharT> const &ch,
38
template <typename CharT, typename FakeT>
39
void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr,
40
spirit::range<CharT> const &rng, FakeT);
42
#endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
43
}} // namespace utility::impl
45
///////////////////////////////////////////////////////////////////////////////
49
///////////////////////////////////////////////////////////////////////////////
50
template <typename CharT = char>
51
class chset: public char_parser<chset<CharT> > {
55
chset(chset const& arg);
56
explicit chset(CharT arg);
57
explicit chset(anychar_parser arg);
58
explicit chset(nothing_parser arg);
59
explicit chset(chlit<CharT> const& arg);
60
explicit chset(range<CharT> const& arg);
61
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
62
template <typename ParserT>
63
explicit chset(negated_char_parser<ParserT> const& arg)
64
: ptr(new basic_chset<CharT>())
69
explicit chset(negated_char_parser<chlit<CharT> > const& arg);
70
explicit chset(negated_char_parser<range<CharT> > const& arg);
73
template <typename CharT2>
74
explicit chset(CharT2 const* definition)
75
: ptr(new basic_chset<CharT>())
77
utility::impl::construct_chset(ptr, definition);
81
chset& operator=(chset const& rhs);
82
chset& operator=(CharT rhs);
83
chset& operator=(anychar_parser rhs);
84
chset& operator=(nothing_parser rhs);
85
chset& operator=(chlit<CharT> const& rhs);
86
chset& operator=(range<CharT> const& rhs);
87
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
88
template <typename ParserT>
89
chset& operator=(negated_char_parser<ParserT> const& rhs)
91
utility::impl::detach_clear(ptr);
97
chset& operator=(negated_char_parser<chlit<CharT> > const& rhs);
98
chset& operator=(negated_char_parser<range<CharT> > const& rhs);
101
void set(range<CharT> const& arg);
102
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
103
template <typename ParserT>
104
void set(negated_char_parser<ParserT> const& arg)
106
utility::impl::detach(ptr);
107
utility::impl::chset_negated_set(ptr, arg.positive, 0);
110
void set(negated_char_parser<chlit<CharT> > const& arg);
111
void set(negated_char_parser<range<CharT> > const& arg);
113
void clear(range<CharT> const& arg);
114
void clear(negated_char_parser<range<CharT> > const& arg);
115
bool test(CharT ch) const;
119
chset& operator|=(chset const& x);
120
chset& operator&=(chset const& x);
121
chset& operator-=(chset const& x);
122
chset& operator^=(chset const& x);
126
boost::shared_ptr<basic_chset<CharT> > ptr;
129
///////////////////////////////////////////////////////////////////////////////
131
// Generator functions
133
///////////////////////////////////////////////////////////////////////////////
134
template <typename CharT>
135
inline chset<wchar_t>
136
chset_p(chlit<CharT> const& arg)
137
{ return chset<CharT>(arg); }
139
//////////////////////////////////
140
template <typename CharT>
141
inline chset<wchar_t>
142
chset_p(range<CharT> const& arg)
143
{ return chset<CharT>(arg); }
145
//////////////////////////////////
146
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
148
template <typename ParserT>
149
inline chset<wchar_t>
150
chset_p(negated_char_parser<ParserT> const& arg)
151
{ return chset<typename ParserT::char_t>(arg); }
153
#else // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
155
template <typename CharT>
156
inline chset<wchar_t>
157
chset_p(negated_char_parser<chlit<CharT> > const& arg)
158
{ return chset<CharT>(arg); }
160
template <typename CharT>
161
inline chset<wchar_t>
162
chset_p(negated_char_parser<range<CharT> > const& arg)
163
{ return chset<CharT>(arg); }
165
#endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
167
//////////////////////////////////
169
chset_p(char const* init)
170
{ return chset<char>(init); }
172
//////////////////////////////////
173
inline chset<wchar_t>
174
chset_p(wchar_t const* init)
175
{ return chset<wchar_t>(init); }
177
//////////////////////////////////
180
{ return chset<char>(ch); }
182
//////////////////////////////////
183
inline chset<wchar_t>
185
{ return chset<wchar_t>(ch); }
187
//////////////////////////////////
190
{ return chset<int>(ch); }
192
//////////////////////////////////
193
inline chset<unsigned int>
194
chset_p(unsigned int ch)
195
{ return chset<unsigned int>(ch); }
197
//////////////////////////////////
200
{ return chset<short>(ch); }
202
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
203
//////////////////////////////////
204
inline chset<unsigned short>
205
chset_p(unsigned short ch)
206
{ return chset<unsigned short>(ch); }
208
//////////////////////////////////
211
{ return chset<long>(ch); }
213
//////////////////////////////////
214
inline chset<unsigned long>
215
chset_p(unsigned long ch)
216
{ return chset<unsigned long>(ch); }
218
#ifdef BOOST_HAS_LONG_LONG
219
//////////////////////////////////
220
inline chset<long long>
221
chset_p(long long ch)
222
{ return chset<long long>(ch); }
224
//////////////////////////////////
225
inline chset<unsigned long long>
226
chset_p(unsigned long long ch)
227
{ return chset<unsigned long long>(ch); }
230
///////////////////////////////////////////////////////////////////////////////
231
}} // namespace boost::spirit
235
#include <boost/spirit/utility/impl/chset.ipp>
236
#include <boost/spirit/utility/chset_operators.hpp>