]>
Commit | Line | Data |
---|---|---|
36fed23c | 1 | // -*- C++ -*- |
2 | ||
fbd26352 | 3 | // Copyright (C) 2005-2019 Free Software Foundation, Inc. |
36fed23c | 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 | |
6bc9506f | 8 | // Foundation; either version 3, or (at your option) any later |
36fed23c | 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 | ||
6bc9506f | 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. | |
36fed23c | 19 | |
6bc9506f | 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/>. | |
36fed23c | 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 | /** | |
4f4a327e | 37 | * @file detail/tree_trace_base.hpp |
36fed23c | 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 | ||
4f4a327e | 46 | #include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> |
47 | #include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> | |
36fed23c | 48 | |
b34535d7 | 49 | namespace __gnu_pbds |
36fed23c | 50 | { |
36fed23c | 51 | namespace detail |
52 | { | |
36fed23c | 53 | #ifdef PB_DS_TREE_TRACE |
54 | ||
55 | #define PB_DS_CLASS_T_DEC \ | |
4f4a327e | 56 | template<typename Node_CItr, typename Node_Itr, \ |
57 | typename Cmp_Fn, bool Node_Based, typename _Alloc> | |
36fed23c | 58 | |
59 | #define PB_DS_CLASS_C_DEC \ | |
4f4a327e | 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 | |
36fed23c | 70 | { |
71 | public: | |
72 | void | |
73 | trace() const; | |
74 | ||
75 | private: | |
4f4a327e | 76 | typedef PB_DS_TRACE_BASE base_type; |
77 | typedef Node_CItr node_const_iterator; | |
78 | typedef typename _Alloc::size_type size_type; | |
36fed23c | 79 | |
36fed23c | 80 | void |
4f4a327e | 81 | trace_node(node_const_iterator, size_type) const; |
36fed23c | 82 | |
83 | virtual bool | |
84 | empty() const = 0; | |
85 | ||
4f4a327e | 86 | virtual node_const_iterator |
36fed23c | 87 | node_begin() const = 0; |
88 | ||
4f4a327e | 89 | virtual node_const_iterator |
36fed23c | 90 | node_end() const = 0; |
91 | ||
92 | static void | |
4f4a327e | 93 | print_node_pointer(Node_CItr, integral_constant<int,true>); |
36fed23c | 94 | |
95 | static void | |
4f4a327e | 96 | print_node_pointer(Node_CItr, integral_constant<int,false>); |
36fed23c | 97 | |
98 | template<typename Metadata_> | |
99 | static void | |
4f4a327e | 100 | trace_it_metadata(Node_CItr, type_to_type<Metadata_>); |
36fed23c | 101 | |
102 | static void | |
4f4a327e | 103 | trace_it_metadata(Node_CItr, type_to_type<null_type>); |
36fed23c | 104 | }; |
105 | ||
106 | PB_DS_CLASS_T_DEC | |
107 | void | |
108 | PB_DS_CLASS_C_DEC:: | |
109 | trace() const | |
110 | { | |
111 | if (empty()) | |
4f4a327e | 112 | return; |
36fed23c | 113 | trace_node(node_begin(), 0); |
114 | } | |
115 | ||
116 | PB_DS_CLASS_T_DEC | |
117 | void | |
118 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 119 | trace_node(node_const_iterator nd_it, size_type level) const |
36fed23c | 120 | { |
121 | if (nd_it.get_r_child() != node_end()) | |
4f4a327e | 122 | trace_node(nd_it.get_r_child(), level + 1); |
36fed23c | 123 | |
124 | for (size_type i = 0; i < level; ++i) | |
4f4a327e | 125 | std::cerr << ' '; |
36fed23c | 126 | |
127 | print_node_pointer(nd_it, integral_constant<int,Node_Based>()); | |
128 | std::cerr << base_type::extract_key(*(*nd_it)); | |
129 | ||
4f4a327e | 130 | typedef type_to_type<typename node_const_iterator::metadata_type> |
131 | m_type_ind_t; | |
36fed23c | 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()) | |
4f4a327e | 138 | trace_node(nd_it.get_l_child(), level + 1); |
36fed23c | 139 | } |
140 | ||
141 | PB_DS_CLASS_T_DEC | |
142 | template<typename Metadata_> | |
143 | void | |
144 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 145 | trace_it_metadata(Node_CItr nd_it, type_to_type<Metadata_>) |
36fed23c | 146 | { |
4f4a327e | 147 | const unsigned long ul = static_cast<unsigned long>(nd_it.get_metadata()); |
148 | std::cerr << " (" << ul << ") "; | |
36fed23c | 149 | } |
150 | ||
151 | PB_DS_CLASS_T_DEC | |
152 | void | |
153 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 154 | trace_it_metadata(Node_CItr, type_to_type<null_type>) |
36fed23c | 155 | { } |
156 | ||
157 | PB_DS_CLASS_T_DEC | |
158 | void | |
159 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 160 | print_node_pointer(Node_CItr nd_it, integral_constant<int,true>) |
161 | { std::cerr << nd_it.m_p_nd << " "; } | |
36fed23c | 162 | |
163 | PB_DS_CLASS_T_DEC | |
164 | void | |
165 | PB_DS_CLASS_C_DEC:: | |
4f4a327e | 166 | print_node_pointer(Node_CItr nd_it, integral_constant<int,false>) |
167 | { std::cerr << *nd_it << " "; } | |
36fed23c | 168 | |
169 | #undef PB_DS_CLASS_T_DEC | |
36fed23c | 170 | #undef PB_DS_CLASS_C_DEC |
4f4a327e | 171 | #undef PB_DS_TRACE_BASE |
36fed23c | 172 | #endif // #ifdef PB_DS_TREE_TRACE |
173 | ||
174 | } // namespace detail | |
b34535d7 | 175 | } // namespace __gnu_pbds |
36fed23c | 176 | |
177 | #endif // #ifdef PB_DS_TREE_TRACE | |
178 | ||
179 | #endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP |