PageRenderTime 30ms CodeModel.GetById 21ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/classic/utility/impl/chset.ipp

http://hadesmem.googlecode.com/
C++ Header | 366 lines | 291 code | 56 blank | 19 comment | 27 complexity | 25190b27d0bdacfb122c020588451b78 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2003 Joel de Guzman
  3    Copyright (c) 2001-2003 Daniel Nuffer
  4    http://spirit.sourceforge.net/
  5
  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
 12
 13///////////////////////////////////////////////////////////////////////////////
 14#include <boost/limits.hpp>
 15#include <boost/spirit/home/classic/utility/chset.hpp>
 16
 17///////////////////////////////////////////////////////////////////////////////
 18namespace boost { namespace spirit {
 19
 20BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
 21
 22///////////////////////////////////////////////////////////////////////////////
 23//
 24//  chset class
 25//
 26///////////////////////////////////////////////////////////////////////////////
 27namespace utility { namespace impl {
 28    template <typename CharT>
 29    inline void
 30    detach(boost::shared_ptr<basic_chset<CharT> >& ptr)
 31    {
 32        if (!ptr.unique())
 33            ptr = boost::shared_ptr<basic_chset<CharT> >
 34                (new basic_chset<CharT>(*ptr));
 35    }
 36
 37    template <typename CharT>
 38    inline void
 39    detach_clear(boost::shared_ptr<basic_chset<CharT> >& ptr)
 40    {
 41        if (ptr.unique())
 42            ptr->clear();
 43        else
 44            ptr.reset(new basic_chset<CharT>());
 45    }
 46
 47    template <typename CharT, typename CharT2>
 48    void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
 49            CharT2 const* definition)
 50    {
 51        CharT2 ch = *definition++;
 52        while (ch)
 53        {
 54            CharT2 next = *definition++;
 55            if (next == '-')
 56            {
 57                next = *definition++;
 58                if (next == 0)
 59                {
 60                    ptr->set(ch);
 61                    ptr->set('-');
 62                    break;
 63                }
 64                ptr->set(ch, next);
 65            }
 66            else
 67            {
 68                ptr->set(ch);
 69            }
 70            ch = next;
 71        }
 72    }
 73
 74    //////////////////////////////////
 75
 76#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
 77
 78    template <typename CharT, typename FakeT>
 79    void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr, chlit<CharT> const &ch,
 80            FakeT)
 81    {
 82        if(ch.ch != (std::numeric_limits<CharT>::min)()) {
 83            ptr->set((std::numeric_limits<CharT>::min)(), ch.ch - 1);
 84        }
 85        if(ch.ch != (std::numeric_limits<CharT>::max)()) {
 86            ptr->set(ch.ch + 1, (std::numeric_limits<CharT>::max)());
 87        }
 88    }
 89    
 90    template <typename CharT, typename FakeT>
 91    void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr,
 92            spirit::range<CharT> const &rng, FakeT)
 93    {
 94        if(rng.first != (std::numeric_limits<CharT>::min)()) {
 95            ptr->set((std::numeric_limits<CharT>::min)(), rng.first - 1);
 96        }
 97        if(rng.last != (std::numeric_limits<CharT>::max)()) {
 98            ptr->set(rng.last + 1, (std::numeric_limits<CharT>::max)());
 99        }
100    }
101
102#endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
103
104//////////////////////////////////
105
106}} // namespace utility::impl
107
108template <typename CharT>
109inline chset<CharT>::chset()
110: ptr(new basic_chset<CharT>()) {}
111
112template <typename CharT>
113inline chset<CharT>::chset(chset const& arg_)
114: ptr(new basic_chset<CharT>(*arg_.ptr)) {}
115
116template <typename CharT>
117inline chset<CharT>::chset(CharT arg_)
118: ptr(new basic_chset<CharT>())
119{ ptr->set(arg_); }
120
121template <typename CharT>
122inline chset<CharT>::chset(anychar_parser /*arg*/)
123: ptr(new basic_chset<CharT>())
124{
125    ptr->set(
126        (std::numeric_limits<CharT>::min)(),
127        (std::numeric_limits<CharT>::max)()
128    );
129}
130
131template <typename CharT>
132inline chset<CharT>::chset(nothing_parser arg_)
133: ptr(new basic_chset<CharT>()) {}
134
135template <typename CharT>
136inline chset<CharT>::chset(chlit<CharT> const& arg_)
137: ptr(new basic_chset<CharT>())
138{ ptr->set(arg_.ch); }
139
140template <typename CharT>
141inline chset<CharT>::chset(range<CharT> const& arg_)
142: ptr(new basic_chset<CharT>())
143{ ptr->set(arg_.first, arg_.last); }
144
145#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
146
147template <typename CharT>
148inline chset<CharT>::chset(negated_char_parser<chlit<CharT> > const& arg_)
149: ptr(new basic_chset<CharT>())
150{
151    set(arg_);
152}
153
154template <typename CharT>
155inline chset<CharT>::chset(negated_char_parser<range<CharT> > const& arg_)
156: ptr(new basic_chset<CharT>())
157{
158    set(arg_);
159}
160
161#endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
162
163template <typename CharT>
164inline chset<CharT>::~chset() {}
165
166template <typename CharT>
167inline chset<CharT>&
168chset<CharT>::operator=(chset const& rhs)
169{
170    ptr = rhs.ptr;
171    return *this;
172}
173
174template <typename CharT>
175inline chset<CharT>&
176chset<CharT>::operator=(CharT rhs)
177{
178    utility::impl::detach_clear(ptr);
179    ptr->set(rhs);
180    return *this;
181}
182
183template <typename CharT>
184inline chset<CharT>&
185chset<CharT>::operator=(anychar_parser rhs)
186{
187    utility::impl::detach_clear(ptr);
188    ptr->set(
189        (std::numeric_limits<CharT>::min)(),
190        (std::numeric_limits<CharT>::max)()
191    );
192    return *this;
193}
194
195template <typename CharT>
196inline chset<CharT>&
197chset<CharT>::operator=(nothing_parser rhs)
198{
199    utility::impl::detach_clear(ptr);
200    return *this;
201}
202
203template <typename CharT>
204inline chset<CharT>&
205chset<CharT>::operator=(chlit<CharT> const& rhs)
206{
207    utility::impl::detach_clear(ptr);
208    ptr->set(rhs.ch);
209    return *this;
210}
211
212template <typename CharT>
213inline chset<CharT>&
214chset<CharT>::operator=(range<CharT> const& rhs)
215{
216    utility::impl::detach_clear(ptr);
217    ptr->set(rhs.first, rhs.last);
218    return *this;
219}
220
221#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
222
223template <typename CharT>
224inline chset<CharT>&
225chset<CharT>::operator=(negated_char_parser<chlit<CharT> > const& rhs)
226{
227    utility::impl::detach_clear(ptr);
228    set(rhs);
229    return *this;
230}
231
232template <typename CharT>
233inline chset<CharT>&
234chset<CharT>::operator=(negated_char_parser<range<CharT> > const& rhs)
235{
236    utility::impl::detach_clear(ptr);
237    set(rhs);
238    return *this;
239}
240
241#endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
242
243template <typename CharT>
244inline void
245chset<CharT>::set(range<CharT> const& arg_)
246{
247    utility::impl::detach(ptr);
248    ptr->set(arg_.first, arg_.last);
249}
250
251#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
252
253template <typename CharT>
254inline void
255chset<CharT>::set(negated_char_parser<chlit<CharT> > const& arg_)
256{
257    utility::impl::detach(ptr);
258    
259    if(arg_.positive.ch != (std::numeric_limits<CharT>::min)()) {
260        ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.ch - 1);
261    }
262    if(arg_.positive.ch != (std::numeric_limits<CharT>::max)()) {
263        ptr->set(arg_.positive.ch + 1, (std::numeric_limits<CharT>::max)());
264    }
265}
266
267template <typename CharT>
268inline void
269chset<CharT>::set(negated_char_parser<range<CharT> > const& arg_)
270{
271    utility::impl::detach(ptr);
272    
273    if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
274        ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
275    }
276    if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
277        ptr->set(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
278    }
279}
280
281#endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
282
283template <typename CharT>
284inline void
285chset<CharT>::clear(range<CharT> const& arg_)
286{
287    utility::impl::detach(ptr);
288    ptr->clear(arg_.first, arg_.last);
289}
290
291template <typename CharT>
292inline void
293chset<CharT>::clear(negated_char_parser<range<CharT> > const& arg_)
294{
295    utility::impl::detach(ptr);
296
297    if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
298        ptr->clear((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
299    }
300    if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
301        ptr->clear(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
302    }
303}
304
305template <typename CharT>
306inline bool
307chset<CharT>::test(CharT ch) const
308{ return ptr->test(ch); }
309
310template <typename CharT>
311inline chset<CharT>&
312chset<CharT>::inverse()
313{
314    utility::impl::detach(ptr);
315    ptr->inverse();
316    return *this;
317}
318
319template <typename CharT>
320inline void
321chset<CharT>::swap(chset& x)
322{ ptr.swap(x.ptr); }
323
324template <typename CharT>
325inline chset<CharT>&
326chset<CharT>::operator|=(chset const& x)
327{
328    utility::impl::detach(ptr);
329    *ptr |= *x.ptr;
330    return *this;
331}
332
333template <typename CharT>
334inline chset<CharT>&
335chset<CharT>::operator&=(chset const& x)
336{
337    utility::impl::detach(ptr);
338    *ptr &= *x.ptr;
339    return *this;
340}
341
342template <typename CharT>
343inline chset<CharT>&
344chset<CharT>::operator-=(chset const& x)
345{
346    utility::impl::detach(ptr);
347    *ptr -= *x.ptr;
348    return *this;
349}
350
351template <typename CharT>
352inline chset<CharT>&
353chset<CharT>::operator^=(chset const& x)
354{
355    utility::impl::detach(ptr);
356    *ptr ^= *x.ptr;
357    return *this;
358}
359
360///////////////////////////////////////////////////////////////////////////////
361BOOST_SPIRIT_CLASSIC_NAMESPACE_END
362
363}} // namespace boost::spirit
364
365#endif
366