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_BASIC_CHSET_IPP 11#define BOOST_SPIRIT_BASIC_CHSET_IPP 12 13/////////////////////////////////////////////////////////////////////////////// 14#include <bitset> 15#include <boost/spirit/home/classic/utility/impl/chset/basic_chset.hpp> 16 17/////////////////////////////////////////////////////////////////////////////// 18namespace boost { namespace spirit { 19 20BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN 21 22/////////////////////////////////////////////////////////////////////////////// 23// 24// basic_chset: character set implementation 25// 26/////////////////////////////////////////////////////////////////////////////// 27template <typename CharT> 28inline basic_chset<CharT>::basic_chset() {} 29 30////////////////////////////////// 31template <typename CharT> 32inline basic_chset<CharT>::basic_chset(basic_chset const& arg_) 33: rr(arg_.rr) {} 34 35////////////////////////////////// 36template <typename CharT> 37inline bool 38basic_chset<CharT>::test(CharT v) const 39{ return rr.test(v); } 40 41////////////////////////////////// 42template <typename CharT> 43inline void 44basic_chset<CharT>::set(CharT from, CharT to) 45{ rr.set(utility::impl::range<CharT>(from, to)); } 46 47////////////////////////////////// 48template <typename CharT> 49inline void 50basic_chset<CharT>::set(CharT c) 51{ rr.set(utility::impl::range<CharT>(c, c)); } 52 53////////////////////////////////// 54template <typename CharT> 55inline void 56basic_chset<CharT>::clear(CharT from, CharT to) 57{ rr.clear(utility::impl::range<CharT>(from, to)); } 58 59////////////////////////////////// 60template <typename CharT> 61inline void 62basic_chset<CharT>::clear() 63{ rr.clear(); } 64 65///////////////////////////////// 66template <typename CharT> 67inline void 68basic_chset<CharT>::inverse() 69{ 70 basic_chset inv; 71 inv.set( 72 (std::numeric_limits<CharT>::min)(), 73 (std::numeric_limits<CharT>::max)() 74 ); 75 inv -= *this; 76 swap(inv); 77} 78 79///////////////////////////////// 80template <typename CharT> 81inline void 82basic_chset<CharT>::swap(basic_chset& x) 83{ rr.swap(x.rr); } 84 85///////////////////////////////// 86template <typename CharT> 87inline basic_chset<CharT>& 88basic_chset<CharT>::operator|=(basic_chset<CharT> const& x) 89{ 90 typedef typename utility::impl::range_run<CharT>::const_iterator const_iterator; 91 for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter) 92 rr.set(*iter); 93 return *this; 94} 95 96///////////////////////////////// 97template <typename CharT> 98inline basic_chset<CharT>& 99basic_chset<CharT>::operator&=(basic_chset<CharT> const& x) 100{ 101 basic_chset inv; 102 inv.set( 103 (std::numeric_limits<CharT>::min)(), 104 (std::numeric_limits<CharT>::max)() 105 ); 106 inv -= x; 107 *this -= inv; 108 return *this; 109} 110 111///////////////////////////////// 112template <typename CharT> 113inline basic_chset<CharT>& 114basic_chset<CharT>::operator-=(basic_chset<CharT> const& x) 115{ 116 typedef typename utility::impl::range_run<CharT>::const_iterator const_iterator; 117 for (const_iterator iter = x.rr.begin(); iter != x.rr.end(); ++iter) 118 rr.clear(*iter); 119 return *this; 120} 121 122///////////////////////////////// 123template <typename CharT> 124inline basic_chset<CharT>& 125basic_chset<CharT>::operator^=(basic_chset<CharT> const& x) 126{ 127 basic_chset bma = x; 128 bma -= *this; 129 *this -= x; 130 *this |= bma; 131 return *this; 132} 133 134#if (CHAR_BIT == 8) 135 136/////////////////////////////////////////////////////////////////////////////// 137// 138// basic_chset: specializations for 8 bit chars using std::bitset 139// 140/////////////////////////////////////////////////////////////////////////////// 141template <typename CharT> 142inline basic_chset_8bit<CharT>::basic_chset_8bit() {} 143 144///////////////////////////////// 145template <typename CharT> 146inline basic_chset_8bit<CharT>::basic_chset_8bit(basic_chset_8bit const& arg_) 147: bset(arg_.bset) {} 148 149///////////////////////////////// 150template <typename CharT> 151inline bool 152basic_chset_8bit<CharT>::test(CharT v) const 153{ return bset.test((unsigned char)v); } 154 155///////////////////////////////// 156template <typename CharT> 157inline void 158basic_chset_8bit<CharT>::set(CharT from, CharT to) 159{ 160 for (int i = from; i <= to; ++i) 161 bset.set((unsigned char)i); 162} 163 164///////////////////////////////// 165template <typename CharT> 166inline void 167basic_chset_8bit<CharT>::set(CharT c) 168{ bset.set((unsigned char)c); } 169 170///////////////////////////////// 171template <typename CharT> 172inline void 173basic_chset_8bit<CharT>::clear(CharT from, CharT to) 174{ 175 for (int i = from; i <= to; ++i) 176 bset.reset((unsigned char)i); 177} 178 179///////////////////////////////// 180template <typename CharT> 181inline void 182basic_chset_8bit<CharT>::clear(CharT c) 183{ bset.reset((unsigned char)c); } 184 185///////////////////////////////// 186template <typename CharT> 187inline void 188basic_chset_8bit<CharT>::clear() 189{ bset.reset(); } 190 191///////////////////////////////// 192template <typename CharT> 193inline void 194basic_chset_8bit<CharT>::inverse() 195{ bset.flip(); } 196 197///////////////////////////////// 198template <typename CharT> 199inline void 200basic_chset_8bit<CharT>::swap(basic_chset_8bit& x) 201{ std::swap(bset, x.bset); } 202 203///////////////////////////////// 204template <typename CharT> 205inline basic_chset_8bit<CharT>& 206basic_chset_8bit<CharT>::operator|=(basic_chset_8bit const& x) 207{ 208 bset |= x.bset; 209 return *this; 210} 211 212///////////////////////////////// 213template <typename CharT> 214inline basic_chset_8bit<CharT>& 215basic_chset_8bit<CharT>::operator&=(basic_chset_8bit const& x) 216{ 217 bset &= x.bset; 218 return *this; 219} 220 221///////////////////////////////// 222template <typename CharT> 223inline basic_chset_8bit<CharT>& 224basic_chset_8bit<CharT>::operator-=(basic_chset_8bit const& x) 225{ 226 bset &= ~x.bset; 227 return *this; 228} 229 230///////////////////////////////// 231template <typename CharT> 232inline basic_chset_8bit<CharT>& 233basic_chset_8bit<CharT>::operator^=(basic_chset_8bit const& x) 234{ 235 bset ^= x.bset; 236 return *this; 237} 238 239#endif 240 241BOOST_SPIRIT_CLASSIC_NAMESPACE_END 242 243}} // namespace boost::spirit 244 245#endif 246 247