3 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file tree_trace_base.hpp
38 * Contains tree-related policies.
41 #ifndef PB_DS_TREE_TRACE_BASE_HPP
42 #define PB_DS_TREE_TRACE_BASE_HPP
44 #ifdef PB_DS_TREE_TRACE
46 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
47 #include <ext/pb_ds/detail/basic_tree_policy/null_node_metadata.hpp>
55 #ifdef PB_DS_TREE_TRACE
57 #define PB_DS_CLASS_T_DEC \
59 class Const_Node_Iterator, \
60 class Node_Iterator, \
65 #define PB_DS_CLASS_C_DEC \
67 Const_Node_Iterator, \
73 #define PB_DS_BASE_C_DEC \
74 basic_tree_policy_base< \
75 Const_Node_Iterator, \
79 template<typename Const_Node_Iterator,
84 class tree_trace_base : private PB_DS_BASE_C_DEC
91 typedef PB_DS_BASE_C_DEC base_type;
93 typedef Const_Node_Iterator const_node_iterator;
95 typedef typename Allocator::size_type size_type;
99 trace_node(const_node_iterator nd_it, size_type level) const;
104 virtual const_node_iterator
105 node_begin() const = 0;
107 virtual const_node_iterator
108 node_end() const = 0;
111 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>);
114 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>);
116 template<typename Metadata_>
118 trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>);
121 trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>);
132 trace_node(node_begin(), 0);
138 trace_node(const_node_iterator nd_it, size_type level) const
140 if (nd_it.get_r_child() != node_end())
141 trace_node(nd_it.get_r_child(), level + 1);
143 for (size_type i = 0; i < level; ++i)
146 print_node_pointer(nd_it, integral_constant<int,Node_Based>());
147 std::cerr << base_type::extract_key(*(*nd_it));
151 typename const_node_iterator::metadata_type>
154 trace_it_metadata(nd_it, m_type_ind_t());
156 std::cerr << std::endl;
158 if (nd_it.get_l_child() != node_end())
159 trace_node(nd_it.get_l_child(), level + 1);
163 template<typename Metadata_>
166 trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>)
169 static_cast<unsigned long>(nd_it.get_metadata()) << ") ";
175 trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>)
181 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>)
183 std::cerr << nd_it.m_p_nd << " ";
189 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>)
191 std::cerr <<* nd_it << " ";
194 #undef PB_DS_CLASS_T_DEC
196 #undef PB_DS_CLASS_C_DEC
198 #undef PB_DS_BASE_C_DEC
200 #endif // #ifdef PB_DS_TREE_TRACE
202 } // namespace detail
204 } // namespace __gnu_pbds
206 #endif // #ifdef PB_DS_TREE_TRACE
208 #endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP