source: NonGTP/Boost/boost/spirit/utility/impl/chset/basic_chset.ipp @ 857

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