/*============================================================================= Copyright (c) 2001-2003 Joel de Guzman Copyright (c) 2001-2003 Daniel Nuffer http://spirit.sourceforge.net/ Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef BOOST_SPIRIT_CHSET_IPP #define BOOST_SPIRIT_CHSET_IPP /////////////////////////////////////////////////////////////////////////////// #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // // chset class // /////////////////////////////////////////////////////////////////////////////// namespace utility { namespace impl { template inline void detach(boost::shared_ptr >& ptr) { if (!ptr.unique()) ptr = boost::shared_ptr > (new basic_chset(*ptr)); } template inline void detach_clear(boost::shared_ptr >& ptr) { if (ptr.unique()) ptr->clear(); else ptr.reset(new basic_chset()); } template void construct_chset(boost::shared_ptr >& ptr, CharT2 const* definition) { CharT2 ch = *definition++; while (ch) { CharT2 next = *definition++; if (next == '-') { next = *definition++; if (next == 0) { ptr->set(ch); ptr->set('-'); break; } ptr->set(ch, next); } else { ptr->set(ch); } ch = next; } } ////////////////////////////////// #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) template void chset_negated_set(boost::shared_ptr > &ptr, chlit const &ch, FakeT) { if(ch.ch != (std::numeric_limits::min)()) { ptr->set((std::numeric_limits::min)(), ch.ch - 1); } if(ch.ch != (std::numeric_limits::max)()) { ptr->set(ch.ch + 1, (std::numeric_limits::max)()); } } template void chset_negated_set(boost::shared_ptr > &ptr, spirit::range const &rng, FakeT) { if(rng.first != (std::numeric_limits::min)()) { ptr->set((std::numeric_limits::min)(), rng.first - 1); } if(rng.last != (std::numeric_limits::max)()) { ptr->set(rng.last + 1, (std::numeric_limits::max)()); } } #endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300) ////////////////////////////////// }} // namespace utility::impl template inline chset::chset() : ptr(new basic_chset()) {} template inline chset::chset(chset const& arg_) : ptr(new basic_chset(*arg_.ptr)) {} template inline chset::chset(CharT arg_) : ptr(new basic_chset()) { ptr->set(arg_); } template inline chset::chset(anychar_parser /*arg*/) : ptr(new basic_chset()) { ptr->set( (std::numeric_limits::min)(), (std::numeric_limits::max)() ); } template inline chset::chset(nothing_parser arg_) : ptr(new basic_chset()) {} template inline chset::chset(chlit const& arg_) : ptr(new basic_chset()) { ptr->set(arg_.ch); } template inline chset::chset(range const& arg_) : ptr(new basic_chset()) { ptr->set(arg_.first, arg_.last); } #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline chset::chset(negated_char_parser > const& arg_) : ptr(new basic_chset()) { set(arg_); } template inline chset::chset(negated_char_parser > const& arg_) : ptr(new basic_chset()) { set(arg_); } #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline chset::~chset() {} template inline chset& chset::operator=(chset const& rhs) { ptr = rhs.ptr; return *this; } template inline chset& chset::operator=(CharT rhs) { utility::impl::detach_clear(ptr); ptr->set(rhs); return *this; } template inline chset& chset::operator=(anychar_parser rhs) { utility::impl::detach_clear(ptr); ptr->set( (std::numeric_limits::min)(), (std::numeric_limits::max)() ); return *this; } template inline chset& chset::operator=(nothing_parser rhs) { utility::impl::detach_clear(ptr); return *this; } template inline chset& chset::operator=(chlit const& rhs) { utility::impl::detach_clear(ptr); ptr->set(rhs.ch); return *this; } template inline chset& chset::operator=(range const& rhs) { utility::impl::detach_clear(ptr); ptr->set(rhs.first, rhs.last); return *this; } #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline chset& chset::operator=(negated_char_parser > const& rhs) { utility::impl::detach_clear(ptr); set(rhs); return *this; } template inline chset& chset::operator=(negated_char_parser > const& rhs) { utility::impl::detach_clear(ptr); set(rhs); return *this; } #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline void chset::set(range const& arg_) { utility::impl::detach(ptr); ptr->set(arg_.first, arg_.last); } #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline void chset::set(negated_char_parser > const& arg_) { utility::impl::detach(ptr); if(arg_.positive.ch != (std::numeric_limits::min)()) { ptr->set((std::numeric_limits::min)(), arg_.positive.ch - 1); } if(arg_.positive.ch != (std::numeric_limits::max)()) { ptr->set(arg_.positive.ch + 1, (std::numeric_limits::max)()); } } template inline void chset::set(negated_char_parser > const& arg_) { utility::impl::detach(ptr); if(arg_.positive.first != (std::numeric_limits::min)()) { ptr->set((std::numeric_limits::min)(), arg_.positive.first - 1); } if(arg_.positive.last != (std::numeric_limits::max)()) { ptr->set(arg_.positive.last + 1, (std::numeric_limits::max)()); } } #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300) template inline void chset::clear(range const& arg_) { utility::impl::detach(ptr); ptr->clear(arg_.first, arg_.last); } template inline void chset::clear(negated_char_parser > const& arg_) { utility::impl::detach(ptr); if(arg_.positive.first != (std::numeric_limits::min)()) { ptr->clear((std::numeric_limits::min)(), arg_.positive.first - 1); } if(arg_.positive.last != (std::numeric_limits::max)()) { ptr->clear(arg_.positive.last + 1, (std::numeric_limits::max)()); } } template inline bool chset::test(CharT ch) const { return ptr->test(ch); } template inline chset& chset::inverse() { utility::impl::detach(ptr); ptr->inverse(); return *this; } template inline void chset::swap(chset& x) { ptr.swap(x.ptr); } template inline chset& chset::operator|=(chset const& x) { utility::impl::detach(ptr); *ptr |= *x.ptr; return *this; } template inline chset& chset::operator&=(chset const& x) { utility::impl::detach(ptr); *ptr &= *x.ptr; return *this; } template inline chset& chset::operator-=(chset const& x) { utility::impl::detach(ptr); *ptr -= *x.ptr; return *this; } template inline chset& chset::operator^=(chset const& x) { utility::impl::detach(ptr); *ptr ^= *x.ptr; return *this; } /////////////////////////////////////////////////////////////////////////////// BOOST_SPIRIT_CLASSIC_NAMESPACE_END }} // namespace boost::spirit #endif