1 /*=============================================================================
2     Copyright (c) 2001-2014 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_X3_TST_JUNE_03_2007_1031AM)
8 #define BOOST_SPIRIT_X3_TST_JUNE_03_2007_1031AM
9 
10 #include <boost/spirit/home/x3/string/detail/tst.hpp>
11 
12 namespace boost { namespace spirit { namespace x3
13 {
14     struct tst_pass_through
15     {
16         template <typename Char>
operator ()boost::spirit::x3::tst_pass_through17         Char operator()(Char ch) const
18         {
19             return ch;
20         }
21     };
22 
23     template <typename Char, typename T>
24     struct tst
25     {
26         typedef Char char_type; // the character type
27         typedef T value_type; // the value associated with each entry
28         typedef detail::tst_node<Char, T> node;
29 
tstboost::spirit::x3::tst30         tst()
31           : root(0)
32         {
33         }
34 
~tstboost::spirit::x3::tst35         ~tst()
36         {
37             clear();
38         }
39 
tstboost::spirit::x3::tst40         tst(tst const& rhs)
41           : root(0)
42         {
43             copy(rhs);
44         }
45 
operator =boost::spirit::x3::tst46         tst& operator=(tst const& rhs)
47         {
48             return assign(rhs);
49         }
50 
51         template <typename Iterator, typename CaseCompare>
findboost::spirit::x3::tst52         T* find(Iterator& first, Iterator last, CaseCompare caseCompare) const
53         {
54             return node::find(root, first, last, caseCompare);
55         }
56 
57         /*template <typename Iterator>
58         T* find(Iterator& first, Iterator last) const
59         {
60             return find(first, last, case_compare<tst_pass_through());
61         }*/
62 
63         template <typename Iterator>
addboost::spirit::x3::tst64         T* add(
65             Iterator first
66           , Iterator last
67           , typename boost::call_traits<T>::param_type val)
68         {
69             return node::add(root, first, last, val, this);
70         }
71 
72         template <typename Iterator>
removeboost::spirit::x3::tst73         void remove(Iterator first, Iterator last)
74         {
75             node::remove(root, first, last, this);
76         }
77 
clearboost::spirit::x3::tst78         void clear()
79         {
80             node::destruct_node(root, this);
81             root = 0;
82         }
83 
84         template <typename F>
for_eachboost::spirit::x3::tst85         void for_each(F f) const
86         {
87             node::for_each(root, std::basic_string<Char>(), f);
88         }
89 
90     private:
91 
92         friend struct detail::tst_node<Char, T>;
93 
copyboost::spirit::x3::tst94         void copy(tst const& rhs)
95         {
96             root = node::clone_node(rhs.root, this);
97         }
98 
assignboost::spirit::x3::tst99         tst& assign(tst const& rhs)
100         {
101             if (this != &rhs)
102             {
103                 clear();
104                 copy(rhs);
105             }
106             return *this;
107         }
108 
109         node* root;
110 
new_nodeboost::spirit::x3::tst111         node* new_node(Char id)
112         {
113             return new node(id);
114         }
115 
new_databoost::spirit::x3::tst116         T* new_data(typename boost::call_traits<T>::param_type val)
117         {
118             return new T(val);
119         }
120 
delete_nodeboost::spirit::x3::tst121         void delete_node(node* p)
122         {
123             delete p;
124         }
125 
delete_databoost::spirit::x3::tst126         void delete_data(T* p)
127         {
128             delete p;
129         }
130     };
131 }}}
132 
133 #endif
134