tst.hpp 3.0 KB

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