1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 Copyright (c) 2001-2003 Daniel Nuffer
4 http://spirit.sourceforge.net/
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
10 #ifndef BOOST_SPIRIT_CHSET_IPP
11 #define BOOST_SPIRIT_CHSET_IPP
13 ///////////////////////////////////////////////////////////////////////////////
14 #include <boost/limits.hpp>
15 #include <boost/spirit/home/classic/utility/chset.hpp>
17 ///////////////////////////////////////////////////////////////////////////////
18 namespace boost { namespace spirit {
20 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
22 ///////////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
27 namespace utility { namespace impl {
28 template <typename CharT>
30 detach(boost::shared_ptr<basic_chset<CharT> >& ptr)
33 ptr = boost::shared_ptr<basic_chset<CharT> >
34 (new basic_chset<CharT>(*ptr));
37 template <typename CharT>
39 detach_clear(boost::shared_ptr<basic_chset<CharT> >& ptr)
44 ptr.reset(new basic_chset<CharT>());
47 template <typename CharT, typename CharT2>
48 void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
49 CharT2 const* definition)
51 CharT2 ch = *definition++;
54 CharT2 next = *definition++;
74 }} // namespace utility::impl
76 template <typename CharT>
77 inline chset<CharT>::chset()
78 : ptr(new basic_chset<CharT>()) {}
80 template <typename CharT>
81 inline chset<CharT>::chset(chset const& arg_)
82 : ptr(new basic_chset<CharT>(*arg_.ptr)) {}
84 template <typename CharT>
85 inline chset<CharT>::chset(CharT arg_)
86 : ptr(new basic_chset<CharT>())
89 template <typename CharT>
90 inline chset<CharT>::chset(anychar_parser /*arg*/)
91 : ptr(new basic_chset<CharT>())
94 (std::numeric_limits<CharT>::min)(),
95 (std::numeric_limits<CharT>::max)()
99 template <typename CharT>
100 inline chset<CharT>::chset(nothing_parser /*arg_*/)
101 : ptr(new basic_chset<CharT>()) {}
103 template <typename CharT>
104 inline chset<CharT>::chset(chlit<CharT> const& arg_)
105 : ptr(new basic_chset<CharT>())
106 { ptr->set(arg_.ch); }
108 template <typename CharT>
109 inline chset<CharT>::chset(range<CharT> const& arg_)
110 : ptr(new basic_chset<CharT>())
111 { ptr->set(arg_.first, arg_.last); }
113 template <typename CharT>
114 inline chset<CharT>::chset(negated_char_parser<chlit<CharT> > const& arg_)
115 : ptr(new basic_chset<CharT>())
120 template <typename CharT>
121 inline chset<CharT>::chset(negated_char_parser<range<CharT> > const& arg_)
122 : ptr(new basic_chset<CharT>())
127 template <typename CharT>
128 inline chset<CharT>::~chset() {}
130 template <typename CharT>
132 chset<CharT>::operator=(chset const& rhs)
138 template <typename CharT>
140 chset<CharT>::operator=(CharT rhs)
142 utility::impl::detach_clear(ptr);
147 template <typename CharT>
149 chset<CharT>::operator=(anychar_parser /*rhs*/)
151 utility::impl::detach_clear(ptr);
153 (std::numeric_limits<CharT>::min)(),
154 (std::numeric_limits<CharT>::max)()
159 template <typename CharT>
161 chset<CharT>::operator=(nothing_parser /*rhs*/)
163 utility::impl::detach_clear(ptr);
167 template <typename CharT>
169 chset<CharT>::operator=(chlit<CharT> const& rhs)
171 utility::impl::detach_clear(ptr);
176 template <typename CharT>
178 chset<CharT>::operator=(range<CharT> const& rhs)
180 utility::impl::detach_clear(ptr);
181 ptr->set(rhs.first, rhs.last);
185 template <typename CharT>
187 chset<CharT>::operator=(negated_char_parser<chlit<CharT> > const& rhs)
189 utility::impl::detach_clear(ptr);
194 template <typename CharT>
196 chset<CharT>::operator=(negated_char_parser<range<CharT> > const& rhs)
198 utility::impl::detach_clear(ptr);
203 template <typename CharT>
205 chset<CharT>::set(range<CharT> const& arg_)
207 utility::impl::detach(ptr);
208 ptr->set(arg_.first, arg_.last);
211 template <typename CharT>
213 chset<CharT>::set(negated_char_parser<chlit<CharT> > const& arg_)
215 utility::impl::detach(ptr);
217 if(arg_.positive.ch != (std::numeric_limits<CharT>::min)()) {
218 ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.ch - 1);
220 if(arg_.positive.ch != (std::numeric_limits<CharT>::max)()) {
221 ptr->set(arg_.positive.ch + 1, (std::numeric_limits<CharT>::max)());
225 template <typename CharT>
227 chset<CharT>::set(negated_char_parser<range<CharT> > const& arg_)
229 utility::impl::detach(ptr);
231 if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
232 ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
234 if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
235 ptr->set(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
239 template <typename CharT>
241 chset<CharT>::clear(range<CharT> const& arg_)
243 utility::impl::detach(ptr);
244 ptr->clear(arg_.first, arg_.last);
247 template <typename CharT>
249 chset<CharT>::clear(negated_char_parser<range<CharT> > const& arg_)
251 utility::impl::detach(ptr);
253 if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
254 ptr->clear((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
256 if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
257 ptr->clear(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
261 template <typename CharT>
263 chset<CharT>::test(CharT ch) const
264 { return ptr->test(ch); }
266 template <typename CharT>
268 chset<CharT>::inverse()
270 utility::impl::detach(ptr);
275 template <typename CharT>
277 chset<CharT>::swap(chset& x)
280 template <typename CharT>
282 chset<CharT>::operator|=(chset const& x)
284 utility::impl::detach(ptr);
289 template <typename CharT>
291 chset<CharT>::operator&=(chset const& x)
293 utility::impl::detach(ptr);
298 template <typename CharT>
300 chset<CharT>::operator-=(chset const& x)
302 utility::impl::detach(ptr);
307 template <typename CharT>
309 chset<CharT>::operator^=(chset const& x)
311 utility::impl::detach(ptr);
316 ///////////////////////////////////////////////////////////////////////////////
317 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
319 }} // namespace boost::spirit