Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:37

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 #if !defined(BOOST_SPIRIT_X3_TST_JUNE_03_2007_1031AM)
0008 #define BOOST_SPIRIT_X3_TST_JUNE_03_2007_1031AM
0009 
0010 #include <boost/spirit/home/x3/string/detail/tst.hpp>
0011 
0012 #include <string>
0013 
0014 namespace boost { namespace spirit { namespace x3
0015 {
0016     struct tst_pass_through
0017     {
0018         template <typename Char>
0019         Char operator()(Char ch) const
0020         {
0021             return ch;
0022         }
0023     };
0024 
0025     template <typename Char, typename T>
0026     struct tst
0027     {
0028         typedef Char char_type; // the character type
0029         typedef T value_type; // the value associated with each entry
0030         typedef detail::tst_node<Char, T> node;
0031 
0032         tst()
0033           : root(0)
0034         {
0035         }
0036 
0037         ~tst()
0038         {
0039             clear();
0040         }
0041 
0042         tst(tst const& rhs)
0043           : root(0)
0044         {
0045             copy(rhs);
0046         }
0047 
0048         tst& operator=(tst const& rhs)
0049         {
0050             return assign(rhs);
0051         }
0052 
0053         template <typename Iterator, typename CaseCompare>
0054         T* find(Iterator& first, Iterator last, CaseCompare caseCompare) const
0055         {
0056             return node::find(root, first, last, caseCompare);
0057         }
0058 
0059         /*template <typename Iterator>
0060         T* find(Iterator& first, Iterator last) const
0061         {
0062             return find(first, last, case_compare<tst_pass_through());
0063         }*/
0064 
0065         template <typename Iterator>
0066         T* add(
0067             Iterator first
0068           , Iterator last
0069           , typename boost::call_traits<T>::param_type val)
0070         {
0071             return node::add(root, first, last, val, this);
0072         }
0073 
0074         template <typename Iterator>
0075         void remove(Iterator first, Iterator last)
0076         {
0077             node::remove(root, first, last, this);
0078         }
0079 
0080         void clear()
0081         {
0082             node::destruct_node(root, this);
0083             root = 0;
0084         }
0085 
0086         template <typename F>
0087         void for_each(F f) const
0088         {
0089             node::for_each(root, std::basic_string<Char>(), f);
0090         }
0091 
0092     private:
0093 
0094         friend struct detail::tst_node<Char, T>;
0095 
0096         void copy(tst const& rhs)
0097         {
0098             root = node::clone_node(rhs.root, this);
0099         }
0100 
0101         tst& assign(tst const& rhs)
0102         {
0103             if (this != &rhs)
0104             {
0105                 clear();
0106                 copy(rhs);
0107             }
0108             return *this;
0109         }
0110 
0111         node* root;
0112 
0113         node* new_node(Char id)
0114         {
0115             return new node(id);
0116         }
0117 
0118         T* new_data(typename boost::call_traits<T>::param_type val)
0119         {
0120             return new T(val);
0121         }
0122 
0123         void delete_node(node* p)
0124         {
0125             delete p;
0126         }
0127 
0128         void delete_data(T* p)
0129         {
0130             delete p;
0131         }
0132     };
0133 }}}
0134 
0135 #endif