/*============================================================================= 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_BASIC_CHSET_IPP #define BOOST_SPIRIT_BASIC_CHSET_IPP /////////////////////////////////////////////////////////////////////////////// #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // // basic_chset: character set implementation // /////////////////////////////////////////////////////////////////////////////// template inline basic_chset::basic_chset() {} ////////////////////////////////// template inline basic_chset::basic_chset(basic_chset const& arg_) : rr(arg_.rr) {} ////////////////////////////////// template inline bool basic_chset::test(CharT v) const { return rr.test(v); } ////////////////////////////////// template inline void basic_chset::set(CharT from, CharT to) { rr.set(utility::impl::range(from, to)); } ////////////////////////////////// template inline void basic_chset::set(CharT c) { rr.set(utility::impl::range(c, c)); } ////////////////////////////////// template inline void basic_chset::clear(CharT from, CharT to) { rr.clear(utility::impl::range(from, to)); } ////////////////////////////////// template inline void basic_chset::clear() { rr.clear(); } ///////////////////////////////// template inline void basic_chset::inverse() { basic_chset inv; inv.set( (std::numeric_limits::min)(), (std::numeric_limits::max)() ); inv -= *this; swap(inv); } ///////////////////////////////// template inline void basic_chset::swap(basic_chset& x) { rr.swap(x.rr); } ///////////////////////////////// template inline basic_chset& basic_chset::operator|=(basic_chset const& x) { typedef typename utility::impl::range_run::const_iterator const_iterator; for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter) rr.set(*iter); return *this; } ///////////////////////////////// template inline basic_chset& basic_chset::operator&=(basic_chset const& x) { basic_chset inv; inv.set( (std::numeric_limits::min)(), (std::numeric_limits::max)() ); inv -= x; *this -= inv; return *this; } ///////////////////////////////// template inline basic_chset& basic_chset::operator-=(basic_chset const& x) { typedef typename utility::impl::range_run::const_iterator const_iterator; for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter) rr.clear(*iter); return *this; } ///////////////////////////////// template inline basic_chset& basic_chset::operator^=(basic_chset const& x) { basic_chset bma = x; bma -= *this; *this -= x; *this |= bma; return *this; } #if (CHAR_BIT == 8) /////////////////////////////////////////////////////////////////////////////// // // basic_chset: specializations for 8 bit chars using std::bitset // /////////////////////////////////////////////////////////////////////////////// template inline basic_chset_8bit::basic_chset_8bit() {} ///////////////////////////////// template inline basic_chset_8bit::basic_chset_8bit(basic_chset_8bit const& arg_) : bset(arg_.bset) {} ///////////////////////////////// template inline bool basic_chset_8bit::test(CharT v) const { return bset.test((unsigned char)v); } ///////////////////////////////// template inline void basic_chset_8bit::set(CharT from, CharT to) { for (int i = from; i <= to; ++i) bset.set((unsigned char)i); } ///////////////////////////////// template inline void basic_chset_8bit::set(CharT c) { bset.set((unsigned char)c); } ///////////////////////////////// template inline void basic_chset_8bit::clear(CharT from, CharT to) { for (int i = from; i <= to; ++i) bset.reset((unsigned char)i); } ///////////////////////////////// template inline void basic_chset_8bit::clear(CharT c) { bset.reset((unsigned char)c); } ///////////////////////////////// template inline void basic_chset_8bit::clear() { bset.reset(); } ///////////////////////////////// template inline void basic_chset_8bit::inverse() { bset.flip(); } ///////////////////////////////// template inline void basic_chset_8bit::swap(basic_chset_8bit& x) { std::swap(bset, x.bset); } ///////////////////////////////// template inline basic_chset_8bit& basic_chset_8bit::operator|=(basic_chset_8bit const& x) { bset |= x.bset; return *this; } ///////////////////////////////// template inline basic_chset_8bit& basic_chset_8bit::operator&=(basic_chset_8bit const& x) { bset &= x.bset; return *this; } ///////////////////////////////// template inline basic_chset_8bit& basic_chset_8bit::operator-=(basic_chset_8bit const& x) { bset &= ~x.bset; return *this; } ///////////////////////////////// template inline basic_chset_8bit& basic_chset_8bit::operator^=(basic_chset_8bit const& x) { bset ^= x.bset; return *this; } #endif BOOST_SPIRIT_CLASSIC_NAMESPACE_END }} // namespace boost::spirit #endif