]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
a345e45d | 3 | // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc. |
4569a895 AT |
4 | // |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
9 | // version. |
10 | ||
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. | |
15 | ||
748086b7 JJ |
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. | |
4569a895 | 19 | |
748086b7 JJ |
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/>. | |
4569a895 AT |
24 | |
25 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
26 | ||
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 | |
34 | // warranty. | |
35 | ||
36 | /** | |
a345e45d | 37 | * @file detail/tree_trace_base.hpp |
4569a895 AT |
38 | * Contains tree-related policies. |
39 | */ | |
40 | ||
41 | #ifndef PB_DS_TREE_TRACE_BASE_HPP | |
42 | #define PB_DS_TREE_TRACE_BASE_HPP | |
43 | ||
44 | #ifdef PB_DS_TREE_TRACE | |
45 | ||
a345e45d BK |
46 | #include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> |
47 | #include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> | |
4569a895 | 48 | |
5e11f978 | 49 | namespace __gnu_pbds |
4569a895 | 50 | { |
4569a895 AT |
51 | namespace detail |
52 | { | |
4569a895 AT |
53 | #ifdef PB_DS_TREE_TRACE |
54 | ||
55 | #define PB_DS_CLASS_T_DEC \ | |
a345e45d BK |
56 | template<typename Node_CItr, typename Node_Itr, \ |
57 | typename Cmp_Fn, bool Node_Based, typename _Alloc> | |
4569a895 AT |
58 | |
59 | #define PB_DS_CLASS_C_DEC \ | |
a345e45d BK |
60 | tree_trace_base<Node_CItr, Node_Itr, Cmp_Fn, \ |
61 | Node_Based, _Alloc> | |
62 | ||
63 | #define PB_DS_TRACE_BASE \ | |
64 | branch_policy<Node_CItr, Node_Itr, _Alloc> | |
65 | ||
66 | /// Tracing base class. | |
67 | template<typename Node_CItr, typename Node_Itr, | |
68 | typename Cmp_Fn, bool Node_Based, typename _Alloc> | |
69 | class tree_trace_base : private PB_DS_TRACE_BASE | |
4569a895 AT |
70 | { |
71 | public: | |
72 | void | |
73 | trace() const; | |
74 | ||
75 | private: | |
a345e45d BK |
76 | typedef PB_DS_TRACE_BASE base_type; |
77 | typedef Node_CItr node_const_iterator; | |
78 | typedef typename _Alloc::size_type size_type; | |
4569a895 | 79 | |
4569a895 | 80 | void |
a345e45d | 81 | trace_node(node_const_iterator, size_type) const; |
4569a895 AT |
82 | |
83 | virtual bool | |
84 | empty() const = 0; | |
85 | ||
a345e45d | 86 | virtual node_const_iterator |
4569a895 AT |
87 | node_begin() const = 0; |
88 | ||
a345e45d | 89 | virtual node_const_iterator |
4569a895 AT |
90 | node_end() const = 0; |
91 | ||
92 | static void | |
a345e45d | 93 | print_node_pointer(Node_CItr, integral_constant<int,true>); |
4569a895 AT |
94 | |
95 | static void | |
a345e45d | 96 | print_node_pointer(Node_CItr, integral_constant<int,false>); |
4569a895 AT |
97 | |
98 | template<typename Metadata_> | |
99 | static void | |
a345e45d | 100 | trace_it_metadata(Node_CItr, type_to_type<Metadata_>); |
4569a895 AT |
101 | |
102 | static void | |
a345e45d | 103 | trace_it_metadata(Node_CItr, type_to_type<null_type>); |
4569a895 AT |
104 | }; |
105 | ||
106 | PB_DS_CLASS_T_DEC | |
107 | void | |
108 | PB_DS_CLASS_C_DEC:: | |
109 | trace() const | |
110 | { | |
111 | if (empty()) | |
a345e45d | 112 | return; |
4569a895 AT |
113 | trace_node(node_begin(), 0); |
114 | } | |
115 | ||
116 | PB_DS_CLASS_T_DEC | |
117 | void | |
118 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 119 | trace_node(node_const_iterator nd_it, size_type level) const |
4569a895 AT |
120 | { |
121 | if (nd_it.get_r_child() != node_end()) | |
a345e45d | 122 | trace_node(nd_it.get_r_child(), level + 1); |
4569a895 AT |
123 | |
124 | for (size_type i = 0; i < level; ++i) | |
a345e45d | 125 | std::cerr << ' '; |
4569a895 AT |
126 | |
127 | print_node_pointer(nd_it, integral_constant<int,Node_Based>()); | |
128 | std::cerr << base_type::extract_key(*(*nd_it)); | |
129 | ||
a345e45d BK |
130 | typedef type_to_type<typename node_const_iterator::metadata_type> |
131 | m_type_ind_t; | |
4569a895 AT |
132 | |
133 | trace_it_metadata(nd_it, m_type_ind_t()); | |
134 | ||
135 | std::cerr << std::endl; | |
136 | ||
137 | if (nd_it.get_l_child() != node_end()) | |
a345e45d | 138 | trace_node(nd_it.get_l_child(), level + 1); |
4569a895 AT |
139 | } |
140 | ||
141 | PB_DS_CLASS_T_DEC | |
142 | template<typename Metadata_> | |
143 | void | |
144 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 145 | trace_it_metadata(Node_CItr nd_it, type_to_type<Metadata_>) |
4569a895 | 146 | { |
a345e45d BK |
147 | const unsigned long ul = static_cast<unsigned long>(nd_it.get_metadata()); |
148 | std::cerr << " (" << ul << ") "; | |
4569a895 AT |
149 | } |
150 | ||
151 | PB_DS_CLASS_T_DEC | |
152 | void | |
153 | PB_DS_CLASS_C_DEC:: | |
a345e45d | 154 | trace_it_metadata(Node_CItr, type_to_type<null_type>) |
4569a895 AT |
155 | { } |
156 | ||
157 | PB_DS_CLASS_T_DEC | |
158 | void | |
159 | PB_DS_CLASS_C_DEC:: | |
a345e45d BK |
160 | print_node_pointer(Node_CItr nd_it, integral_constant<int,true>) |
161 | { std::cerr << nd_it.m_p_nd << " "; } | |
4569a895 AT |
162 | |
163 | PB_DS_CLASS_T_DEC | |
164 | void | |
165 | PB_DS_CLASS_C_DEC:: | |
a345e45d BK |
166 | print_node_pointer(Node_CItr nd_it, integral_constant<int,false>) |
167 | { std::cerr << *nd_it << " "; } | |
4569a895 AT |
168 | |
169 | #undef PB_DS_CLASS_T_DEC | |
4569a895 | 170 | #undef PB_DS_CLASS_C_DEC |
a345e45d | 171 | #undef PB_DS_TRACE_BASE |
4569a895 AT |
172 | #endif // #ifdef PB_DS_TREE_TRACE |
173 | ||
174 | } // namespace detail | |
5e11f978 | 175 | } // namespace __gnu_pbds |
4569a895 AT |
176 | |
177 | #endif // #ifdef PB_DS_TREE_TRACE | |
178 | ||
179 | #endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP |