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