| 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 | #include <string> |
| 13 | |
| 14 | namespace boost { namespace spirit { namespace x3 |
| 15 | { |
| 16 | struct tst_pass_through |
| 17 | { |
| 18 | template <typename Char> |
| 19 | Char operator()(Char ch) const |
| 20 | { |
| 21 | return ch; |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | template <typename Char, typename T> |
| 26 | struct tst |
| 27 | { |
| 28 | typedef Char char_type; // the character type |
| 29 | typedef T value_type; // the value associated with each entry |
| 30 | typedef detail::tst_node<Char, T> node; |
| 31 | |
| 32 | tst() |
| 33 | : root(0) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | ~tst() |
| 38 | { |
| 39 | clear(); |
| 40 | } |
| 41 | |
| 42 | tst(tst const& rhs) |
| 43 | : root(0) |
| 44 | { |
| 45 | copy(rhs); |
| 46 | } |
| 47 | |
| 48 | tst& operator=(tst const& rhs) |
| 49 | { |
| 50 | return assign(rhs); |
| 51 | } |
| 52 | |
| 53 | template <typename Iterator, typename CaseCompare> |
| 54 | T* find(Iterator& first, Iterator last, CaseCompare caseCompare) const |
| 55 | { |
| 56 | return node::find(root, first, last, caseCompare); |
| 57 | } |
| 58 | |
| 59 | /*template <typename Iterator> |
| 60 | T* find(Iterator& first, Iterator last) const |
| 61 | { |
| 62 | return find(first, last, case_compare<tst_pass_through()); |
| 63 | }*/ |
| 64 | |
| 65 | template <typename Iterator> |
| 66 | T* add( |
| 67 | Iterator first |
| 68 | , Iterator last |
| 69 | , typename boost::call_traits<T>::param_type val) |
| 70 | { |
| 71 | return node::add(root, first, last, val, this); |
| 72 | } |
| 73 | |
| 74 | template <typename Iterator> |
| 75 | void remove(Iterator first, Iterator last) |
| 76 | { |
| 77 | node::remove(root, first, last, this); |
| 78 | } |
| 79 | |
| 80 | void clear() |
| 81 | { |
| 82 | node::destruct_node(root, this); |
| 83 | root = 0; |
| 84 | } |
| 85 | |
| 86 | template <typename F> |
| 87 | void for_each(F f) const |
| 88 | { |
| 89 | node::for_each(root, std::basic_string<Char>(), f); |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | |
| 94 | friend struct detail::tst_node<Char, T>; |
| 95 | |
| 96 | void copy(tst const& rhs) |
| 97 | { |
| 98 | root = node::clone_node(rhs.root, this); |
| 99 | } |
| 100 | |
| 101 | tst& assign(tst const& rhs) |
| 102 | { |
| 103 | if (this != &rhs) |
| 104 | { |
| 105 | clear(); |
| 106 | copy(rhs); |
| 107 | } |
| 108 | return *this; |
| 109 | } |
| 110 | |
| 111 | node* root; |
| 112 | |
| 113 | node* new_node(Char id) |
| 114 | { |
| 115 | return new node(id); |
| 116 | } |
| 117 | |
| 118 | T* new_data(typename boost::call_traits<T>::param_type val) |
| 119 | { |
| 120 | return new T(val); |
| 121 | } |
| 122 | |
| 123 | void delete_node(node* p) |
| 124 | { |
| 125 | delete p; |
| 126 | } |
| 127 | |
| 128 | void delete_data(T* p) |
| 129 | { |
| 130 | delete p; |
| 131 | } |
| 132 | }; |
| 133 | }}} |
| 134 | |
| 135 | #endif |
| 136 | |