]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ==============================================================================*/ | |
7 | #if !defined(BOOST_SPIRIT_TST_JUNE_03_2007_1031AM) | |
8 | #define BOOST_SPIRIT_TST_JUNE_03_2007_1031AM | |
9 | ||
10 | #if defined(_MSC_VER) | |
11 | #pragma once | |
12 | #endif | |
13 | ||
14 | #include <boost/spirit/home/qi/string/detail/tst.hpp> | |
15 | ||
16 | namespace boost { namespace spirit { namespace qi | |
17 | { | |
18 | struct tst_pass_through | |
19 | { | |
20 | template <typename Char> | |
21 | Char operator()(Char ch) const | |
22 | { | |
23 | return ch; | |
24 | } | |
25 | }; | |
26 | ||
27 | template <typename Char, typename T> | |
28 | struct tst | |
29 | { | |
30 | typedef Char char_type; // the character type | |
31 | typedef T value_type; // the value associated with each entry | |
32 | typedef detail::tst_node<Char, T> node; | |
33 | ||
34 | tst() | |
35 | : root(0) | |
36 | { | |
37 | } | |
38 | ||
39 | ~tst() | |
40 | { | |
41 | clear(); | |
42 | } | |
43 | ||
44 | tst(tst const& rhs) | |
45 | : root(0) | |
46 | { | |
47 | copy(rhs); | |
48 | } | |
49 | ||
50 | tst& operator=(tst const& rhs) | |
51 | { | |
52 | return assign(rhs); | |
53 | } | |
54 | ||
55 | template <typename Iterator, typename Filter> | |
56 | T* find(Iterator& first, Iterator last, Filter filter) const | |
57 | { | |
58 | return node::find(root, first, last, filter); | |
59 | } | |
60 | ||
61 | template <typename Iterator> | |
62 | T* find(Iterator& first, Iterator last) const | |
63 | { | |
64 | return find(first, last, tst_pass_through()); | |
65 | } | |
66 | ||
67 | template <typename Iterator> | |
68 | T* add( | |
69 | Iterator first | |
70 | , Iterator last | |
71 | , typename boost::call_traits<T>::param_type val) | |
72 | { | |
73 | return node::add(root, first, last, val, this); | |
74 | } | |
75 | ||
76 | template <typename Iterator> | |
77 | void remove(Iterator first, Iterator last) | |
78 | { | |
79 | node::remove(root, first, last, this); | |
80 | } | |
81 | ||
82 | void clear() | |
83 | { | |
84 | node::destruct_node(root, this); | |
85 | root = 0; | |
86 | } | |
87 | ||
88 | template <typename F> | |
89 | void for_each(F f) const | |
90 | { | |
91 | node::for_each(root, std::basic_string<Char>(), f); | |
92 | } | |
93 | ||
94 | private: | |
95 | ||
96 | friend struct detail::tst_node<Char, T>; | |
97 | ||
98 | void copy(tst const& rhs) | |
99 | { | |
100 | root = node::clone_node(rhs.root, this); | |
101 | } | |
102 | ||
103 | tst& assign(tst const& rhs) | |
104 | { | |
105 | if (this != &rhs) | |
106 | { | |
107 | clear(); | |
108 | copy(rhs); | |
109 | } | |
110 | return *this; | |
111 | } | |
112 | ||
113 | node* root; | |
114 | ||
115 | node* new_node(Char id) | |
116 | { | |
117 | return new node(id); | |
118 | } | |
119 | ||
120 | T* new_data(typename boost::call_traits<T>::param_type val) | |
121 | { | |
122 | return new T(val); | |
123 | } | |
124 | ||
125 | void delete_node(node* p) | |
126 | { | |
127 | delete p; | |
128 | } | |
129 | ||
130 | void delete_data(T* p) | |
131 | { | |
132 | delete p; | |
133 | } | |
134 | }; | |
135 | }}} | |
136 | ||
137 | #endif |