Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:07

0001 /*=============================================================================
0002     Copyright (c) 2001-2003 Joel de Guzman
0003     Copyright (c) 2001-2003 Daniel Nuffer
0004     http://spirit.sourceforge.net/
0005 
0006     Use, modification and distribution is subject to the Boost Software
0007     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008     http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #ifndef BOOST_SPIRIT_CHSET_IPP
0011 #define BOOST_SPIRIT_CHSET_IPP
0012 
0013 ///////////////////////////////////////////////////////////////////////////////
0014 #include <boost/limits.hpp>
0015 #include <boost/spirit/home/classic/utility/chset.hpp>
0016 
0017 ///////////////////////////////////////////////////////////////////////////////
0018 namespace boost { namespace spirit {
0019 
0020 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0021 
0022 ///////////////////////////////////////////////////////////////////////////////
0023 //
0024 //  chset class
0025 //
0026 ///////////////////////////////////////////////////////////////////////////////
0027 namespace utility { namespace impl {
0028     template <typename CharT>
0029     inline void
0030     detach(boost::shared_ptr<basic_chset<CharT> >& ptr)
0031     {
0032         if (!ptr.unique())
0033             ptr = boost::shared_ptr<basic_chset<CharT> >
0034                 (new basic_chset<CharT>(*ptr));
0035     }
0036 
0037     template <typename CharT>
0038     inline void
0039     detach_clear(boost::shared_ptr<basic_chset<CharT> >& ptr)
0040     {
0041         if (ptr.unique())
0042             ptr->clear();
0043         else
0044             ptr.reset(new basic_chset<CharT>());
0045     }
0046 
0047     template <typename CharT, typename CharT2>
0048     void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
0049             CharT2 const* definition)
0050     {
0051         CharT2 ch = *definition++;
0052         while (ch)
0053         {
0054             CharT2 next = *definition++;
0055             if (next == '-')
0056             {
0057                 next = *definition++;
0058                 if (next == 0)
0059                 {
0060                     ptr->set(ch);
0061                     ptr->set('-');
0062                     break;
0063                 }
0064                 ptr->set(ch, next);
0065             }
0066             else
0067             {
0068                 ptr->set(ch);
0069             }
0070             ch = next;
0071         }
0072     }
0073 
0074 }} // namespace utility::impl
0075 
0076 template <typename CharT>
0077 inline chset<CharT>::chset()
0078 : ptr(new basic_chset<CharT>()) {}
0079 
0080 template <typename CharT>
0081 inline chset<CharT>::chset(chset const& arg_)
0082 : ptr(new basic_chset<CharT>(*arg_.ptr)) {}
0083 
0084 template <typename CharT>
0085 inline chset<CharT>::chset(CharT arg_)
0086 : ptr(new basic_chset<CharT>())
0087 { ptr->set(arg_); }
0088 
0089 template <typename CharT>
0090 inline chset<CharT>::chset(anychar_parser /*arg*/)
0091 : ptr(new basic_chset<CharT>())
0092 {
0093     ptr->set(
0094         (std::numeric_limits<CharT>::min)(),
0095         (std::numeric_limits<CharT>::max)()
0096     );
0097 }
0098 
0099 template <typename CharT>
0100 inline chset<CharT>::chset(nothing_parser /*arg_*/)
0101 : ptr(new basic_chset<CharT>()) {}
0102 
0103 template <typename CharT>
0104 inline chset<CharT>::chset(chlit<CharT> const& arg_)
0105 : ptr(new basic_chset<CharT>())
0106 { ptr->set(arg_.ch); }
0107 
0108 template <typename CharT>
0109 inline chset<CharT>::chset(range<CharT> const& arg_)
0110 : ptr(new basic_chset<CharT>())
0111 { ptr->set(arg_.first, arg_.last); }
0112 
0113 template <typename CharT>
0114 inline chset<CharT>::chset(negated_char_parser<chlit<CharT> > const& arg_)
0115 : ptr(new basic_chset<CharT>())
0116 {
0117     set(arg_);
0118 }
0119 
0120 template <typename CharT>
0121 inline chset<CharT>::chset(negated_char_parser<range<CharT> > const& arg_)
0122 : ptr(new basic_chset<CharT>())
0123 {
0124     set(arg_);
0125 }
0126 
0127 template <typename CharT>
0128 inline chset<CharT>::~chset() {}
0129 
0130 template <typename CharT>
0131 inline chset<CharT>&
0132 chset<CharT>::operator=(chset const& rhs)
0133 {
0134     ptr = rhs.ptr;
0135     return *this;
0136 }
0137 
0138 template <typename CharT>
0139 inline chset<CharT>&
0140 chset<CharT>::operator=(CharT rhs)
0141 {
0142     utility::impl::detach_clear(ptr);
0143     ptr->set(rhs);
0144     return *this;
0145 }
0146 
0147 template <typename CharT>
0148 inline chset<CharT>&
0149 chset<CharT>::operator=(anychar_parser /*rhs*/)
0150 {
0151     utility::impl::detach_clear(ptr);
0152     ptr->set(
0153         (std::numeric_limits<CharT>::min)(),
0154         (std::numeric_limits<CharT>::max)()
0155     );
0156     return *this;
0157 }
0158 
0159 template <typename CharT>
0160 inline chset<CharT>&
0161 chset<CharT>::operator=(nothing_parser /*rhs*/)
0162 {
0163     utility::impl::detach_clear(ptr);
0164     return *this;
0165 }
0166 
0167 template <typename CharT>
0168 inline chset<CharT>&
0169 chset<CharT>::operator=(chlit<CharT> const& rhs)
0170 {
0171     utility::impl::detach_clear(ptr);
0172     ptr->set(rhs.ch);
0173     return *this;
0174 }
0175 
0176 template <typename CharT>
0177 inline chset<CharT>&
0178 chset<CharT>::operator=(range<CharT> const& rhs)
0179 {
0180     utility::impl::detach_clear(ptr);
0181     ptr->set(rhs.first, rhs.last);
0182     return *this;
0183 }
0184 
0185 template <typename CharT>
0186 inline chset<CharT>&
0187 chset<CharT>::operator=(negated_char_parser<chlit<CharT> > const& rhs)
0188 {
0189     utility::impl::detach_clear(ptr);
0190     set(rhs);
0191     return *this;
0192 }
0193 
0194 template <typename CharT>
0195 inline chset<CharT>&
0196 chset<CharT>::operator=(negated_char_parser<range<CharT> > const& rhs)
0197 {
0198     utility::impl::detach_clear(ptr);
0199     set(rhs);
0200     return *this;
0201 }
0202 
0203 template <typename CharT>
0204 inline void
0205 chset<CharT>::set(range<CharT> const& arg_)
0206 {
0207     utility::impl::detach(ptr);
0208     ptr->set(arg_.first, arg_.last);
0209 }
0210 
0211 template <typename CharT>
0212 inline void
0213 chset<CharT>::set(negated_char_parser<chlit<CharT> > const& arg_)
0214 {
0215     utility::impl::detach(ptr);
0216     
0217     if(arg_.positive.ch != (std::numeric_limits<CharT>::min)()) {
0218         ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.ch - 1);
0219     }
0220     if(arg_.positive.ch != (std::numeric_limits<CharT>::max)()) {
0221         ptr->set(arg_.positive.ch + 1, (std::numeric_limits<CharT>::max)());
0222     }
0223 }
0224 
0225 template <typename CharT>
0226 inline void
0227 chset<CharT>::set(negated_char_parser<range<CharT> > const& arg_)
0228 {
0229     utility::impl::detach(ptr);
0230     
0231     if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
0232         ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
0233     }
0234     if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
0235         ptr->set(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
0236     }
0237 }
0238 
0239 template <typename CharT>
0240 inline void
0241 chset<CharT>::clear(range<CharT> const& arg_)
0242 {
0243     utility::impl::detach(ptr);
0244     ptr->clear(arg_.first, arg_.last);
0245 }
0246 
0247 template <typename CharT>
0248 inline void
0249 chset<CharT>::clear(negated_char_parser<range<CharT> > const& arg_)
0250 {
0251     utility::impl::detach(ptr);
0252 
0253     if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
0254         ptr->clear((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
0255     }
0256     if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
0257         ptr->clear(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
0258     }
0259 }
0260 
0261 template <typename CharT>
0262 inline bool
0263 chset<CharT>::test(CharT ch) const
0264 { return ptr->test(ch); }
0265 
0266 template <typename CharT>
0267 inline chset<CharT>&
0268 chset<CharT>::inverse()
0269 {
0270     utility::impl::detach(ptr);
0271     ptr->inverse();
0272     return *this;
0273 }
0274 
0275 template <typename CharT>
0276 inline void
0277 chset<CharT>::swap(chset& x)
0278 { ptr.swap(x.ptr); }
0279 
0280 template <typename CharT>
0281 inline chset<CharT>&
0282 chset<CharT>::operator|=(chset const& x)
0283 {
0284     utility::impl::detach(ptr);
0285     *ptr |= *x.ptr;
0286     return *this;
0287 }
0288 
0289 template <typename CharT>
0290 inline chset<CharT>&
0291 chset<CharT>::operator&=(chset const& x)
0292 {
0293     utility::impl::detach(ptr);
0294     *ptr &= *x.ptr;
0295     return *this;
0296 }
0297 
0298 template <typename CharT>
0299 inline chset<CharT>&
0300 chset<CharT>::operator-=(chset const& x)
0301 {
0302     utility::impl::detach(ptr);
0303     *ptr -= *x.ptr;
0304     return *this;
0305 }
0306 
0307 template <typename CharT>
0308 inline chset<CharT>&
0309 chset<CharT>::operator^=(chset const& x)
0310 {
0311     utility::impl::detach(ptr);
0312     *ptr ^= *x.ptr;
0313     return *this;
0314 }
0315 
0316 ///////////////////////////////////////////////////////////////////////////////
0317 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0318 
0319 }} // namespace boost::spirit
0320 
0321 #endif
0322