Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / tree_trace_base.hpp
blob049a9c57527d816e5d33851076fe3e55f5722349
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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
8 // Foundation; either version 2, or (at your option) any later
9 // version.
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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file tree_trace_base.hpp
44 * Contains tree-related policies.
47 #ifndef PB_DS_TREE_TRACE_BASE_HPP
48 #define PB_DS_TREE_TRACE_BASE_HPP
50 #ifdef PB_DS_TREE_TRACE
52 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
53 #include <ext/pb_ds/detail/basic_tree_policy/null_node_metadata.hpp>
55 namespace __gnu_pbds
58 namespace detail
61 #ifdef PB_DS_TREE_TRACE
63 #define PB_DS_CLASS_T_DEC \
64 template< \
65 class Const_Node_Iterator, \
66 class Node_Iterator, \
67 class Cmp_Fn, \
68 bool Node_Based, \
69 class Allocator>
71 #define PB_DS_CLASS_C_DEC \
72 tree_trace_base< \
73 Const_Node_Iterator, \
74 Node_Iterator, \
75 Cmp_Fn, \
76 Node_Based, \
77 Allocator>
79 #define PB_DS_BASE_C_DEC \
80 basic_tree_policy_base< \
81 Const_Node_Iterator, \
82 Node_Iterator, \
83 Allocator>
85 template<typename Const_Node_Iterator,
86 class Node_Iterator,
87 class Cmp_Fn,
88 bool Node_Based,
89 class Allocator>
90 class tree_trace_base : private PB_DS_BASE_C_DEC
92 public:
93 void
94 trace() const;
96 private:
97 typedef PB_DS_BASE_C_DEC base_type;
99 typedef Const_Node_Iterator const_node_iterator;
101 typedef typename Allocator::size_type size_type;
103 private:
104 void
105 trace_node(const_node_iterator nd_it, size_type level) const;
107 virtual bool
108 empty() const = 0;
110 virtual const_node_iterator
111 node_begin() const = 0;
113 virtual const_node_iterator
114 node_end() const = 0;
116 static void
117 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>);
119 static void
120 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>);
122 template<typename Metadata_>
123 static void
124 trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>);
126 static void
127 trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>);
130 PB_DS_CLASS_T_DEC
131 void
132 PB_DS_CLASS_C_DEC::
133 trace() const
135 if (empty())
136 return;
138 trace_node(node_begin(), 0);
141 PB_DS_CLASS_T_DEC
142 void
143 PB_DS_CLASS_C_DEC::
144 trace_node(const_node_iterator nd_it, size_type level) const
146 if (nd_it.get_r_child() != node_end())
147 trace_node(nd_it.get_r_child(), level + 1);
149 for (size_type i = 0; i < level; ++i)
150 std::cerr << ' ';
152 print_node_pointer(nd_it, integral_constant<int,Node_Based>());
153 std::cerr << base_type::extract_key(*(*nd_it));
155 typedef
156 type_to_type<
157 typename const_node_iterator::metadata_type>
158 m_type_ind_t;
160 trace_it_metadata(nd_it, m_type_ind_t());
162 std::cerr << std::endl;
164 if (nd_it.get_l_child() != node_end())
165 trace_node(nd_it.get_l_child(), level + 1);
168 PB_DS_CLASS_T_DEC
169 template<typename Metadata_>
170 void
171 PB_DS_CLASS_C_DEC::
172 trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>)
174 std::cerr << " (" <<
175 static_cast<unsigned long>(nd_it.get_metadata()) << ") ";
178 PB_DS_CLASS_T_DEC
179 void
180 PB_DS_CLASS_C_DEC::
181 trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>)
184 PB_DS_CLASS_T_DEC
185 void
186 PB_DS_CLASS_C_DEC::
187 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>)
189 std::cerr << nd_it.m_p_nd << " ";
192 PB_DS_CLASS_T_DEC
193 void
194 PB_DS_CLASS_C_DEC::
195 print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>)
197 std::cerr <<* nd_it << " ";
200 #undef PB_DS_CLASS_T_DEC
202 #undef PB_DS_CLASS_C_DEC
204 #undef PB_DS_BASE_C_DEC
206 #endif // #ifdef PB_DS_TREE_TRACE
208 } // namespace detail
210 } // namespace __gnu_pbds
212 #endif // #ifdef PB_DS_TREE_TRACE
214 #endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP