11 #ifndef BOOST_IOSTREAMS_FINITE_STATE_FILTER_HPP_INCLUDED
12 #define BOOST_IOSTREAMS_FINITE_STATE_FILTER_HPP_INCLUDED
19 #include <boost/config.hpp>
20 #include <boost/detail/workaround.hpp>
21 #include <boost/iostreams/categories.hpp>
22 #include <boost/iostreams/char_traits.hpp>
23 #include <boost/iostreams/checked_operations.hpp>
24 #include <boost/iostreams/concepts.hpp>
25 #include <boost/iostreams/detail/ios.hpp>
26 #include <boost/iostreams/filter/stdio.hpp>
27 #include <boost/iostreams/operations.hpp>
28 #include <boost/mpl/begin_end.hpp>
29 #include <boost/mpl/deref.hpp>
30 #include <boost/preprocessor/control/expr_if.hpp>
31 #include <boost/static_assert.hpp>
32 #include <boost/type_traits/is_base_and_derived.hpp>
34 namespace boost {
namespace iostreams {
46 static bool test(Ch,
const std::locale&) {
return true; }
51 #define BOOST_IOSTREAMS_CHARACTER_CLASS(class) \
52 struct BOOST_JOIN(is_, class) { \
53 template<typename Ch> \
54 static bool test(Ch event, const std::locale& loc) \
55 { return std::BOOST_JOIN(is, class)(event, loc); } \
71 #undef BOOST_IOSTREAMS_CHARACTER_CLASS
78 static bool test(Ch event,
const std::locale&)
89 template<
typename FiniteStateMachine>
94 template<
typename Derived,
typename Ch =
char>
107 typename CharacterClass,
112 static const int state = State;
113 static const int next_state = NextState;
146 #if BOOST_WORKAROUND(__MWERKS__, <= 0x3206)
147 template<
typename Ch>
148 void _push_impl(Ch c) {
push(c); }
151 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
152 template<
typename FiniteStateFilter>
166 #if !BOOST_WORKAROUND(__MWERKS__, <= 0x3206)
167 # define BOOST_IOSTREAMS_FSM(fsm) \
168 template<typename Ch> \
170 { ::boost::iostreams::finite_state_machine<fsm, Ch>::push(c); } \
171 template<typename Ch> \
172 void skip(Ch c) { (void) c; } \
174 #else // #ifndef __MWERKS__
175 # define BOOST_IOSTREAMS_FSM(fsm) \
176 void push(char c) { this->_push_impl(c); } \
177 void push(wchar_t c) { this->_push_impl(c); } \
178 void skip(char c) { (void) c; } \
179 void skip(wchar_t c) { (void) c; } \
187 template<
typename FiniteStateMachine>
188 class finite_state_filter_impl :
public FiniteStateMachine
191 template<
typename First,
typename Last>
194 typedef typename char_type_of<FiniteStateMachine>::type
char_type;
198 template<
typename T0>
200 : FiniteStateMachine(t0), state_(FiniteStateMachine::initial_state)
203 template<
typename T0,
typename T1>
205 : FiniteStateMachine(t0, t1), state_(FiniteStateMachine::initial_state)
208 template<
typename T0,
typename T1,
typename T2>
210 : FiniteStateMachine(t0, t1, t2),
211 state_(FiniteStateMachine::initial_state)
216 typedef typename FiniteStateMachine::transition_table transitions;
217 typedef typename mpl::begin<transitions>::type first;
218 typedef typename mpl::end<transitions>::type last;
224 state_ = FiniteStateMachine::initial_state;
228 template<
typename First,
typename Last>
229 struct process_event_impl {
232 typedef typename mpl::deref<First>::type rule;
233 typedef typename mpl::next<First>::type next;
234 typedef typename rule::character_class character_class;
236 if ( state == rule::state &&
237 character_class::test(event, fsm.getloc()) )
240 rule::execute(fsm, event);
241 return rule::next_state;
249 template<
typename Last>
257 #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042)) \
258 || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
261 template<
typename FSM>
271 template<
typename FiniteStateMachine>
282 : dual_use, filter_tag, closable_tag, localizable_tag
287 template<
typename T0>
292 template<
typename T0,
typename T1>
297 template<
typename T0,
typename T1,
typename T2>
302 template<
typename Source>
305 assert((flags_ & f_write) == 0);
309 if ((flags_ & f_eof) == 0) {
316 }
else if (!traits_type::would_block(c)) {
317 this->process_event(c);
324 else if ((flags_ & f_eof) != 0)
325 return traits_type::eof();
329 template<
typename Sink>
332 assert((flags_ & f_read) == 0);
335 this->process_event(c);
336 while (!this->empty() && iostreams::put(dest, this->top()))
342 template<
typename Device>
343 void close(Device& dev, BOOST_IOS::openmode which)
345 if (which == BOOST_IOS::out) {
346 if (flags_ & f_write)
347 while (!this->empty())
348 iostreams::put_if(dev, this->pop());
356 f_write = f_read << 1,
365 #endif // #ifndef BOOST_IOSTREAMS_FINITE_STATE_FILTER_HPP_INCLUDED