# tree_trace_base.hpp

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the terms
    00007 // of the GNU General Public License as published by the Free Software
    00008 // Foundation; either version 2, or (at your option) any later
    00009 // version.
    00010
    00011 // This library is distributed in the hope that it will be useful, but
    00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014 // General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License
    00017 // along with this library; see the file COPYING.  If not, write to
    00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
    00019 // MA 02111-1307, USA.
    00020
    00021 // As a special exception, you may use this file as part of a free
    00022 // software library without restriction.  Specifically, if other files
    00023 // instantiate templates or use macros or inline functions from this
    00024 // file, or you compile this file and link it with other files to
    00025 // produce an executable, this file does not by itself cause the
    00026 // resulting executable to be covered by the GNU General Public
    00027 // License.  This exception does not however invalidate any other
    00028 // reasons why the executable file might be covered by the GNU General
    00029 // Public License.
    00030
    00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
    00032
    00033 // Permission to use, copy, modify, sell, and distribute this software
    00034 // is hereby granted without fee, provided that the above copyright
    00035 // notice appears in all copies, and that both that copyright notice
    00036 // and this permission notice appear in supporting documentation. None
    00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
    00038 // representation about the suitability of this software for any
    00039 // purpose. It is provided "as is" without express or implied
    00040 // warranty.
    00041
    00042 /**
    00043  * @file tree_trace_base.hpp
    00044  * Contains tree-related policies.
    00045  */
    00046
    00047 #ifndef PB_DS_TREE_TRACE_BASE_HPP
    00048 #define PB_DS_TREE_TRACE_BASE_HPP
    00049
    00050 #ifdef PB_DS_TREE_TRACE
    00051
    00052 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
    00053 #include <ext/pb_ds/detail/basic_tree_policy/null_node_metadata.hpp>
    00054
    00055 namespace __gnu_pbds
    00056 {
    00057
    00058   namespace detail
    00059   {
    00060
    00061 #ifdef PB_DS_TREE_TRACE
    00062
    00063 #define PB_DS_CLASS_T_DEC                       \
    00064     template<                               \
    00065                         class Const_Node_Iterator, \
    00066                         class Node_Iterator,    \
    00067                         class Cmp_Fn,       \
    00068                         bool Node_Based,    \
    00069                         class Allocator>
    00070
    00071 #define PB_DS_CLASS_C_DEC                       \
    00072     tree_trace_base<                            \
    00073                         Const_Node_Iterator,    \
    00074                         Node_Iterator,      \
    00075                         Cmp_Fn,         \
    00076                         Node_Based,     \
    00077                         Allocator>
    00078
    00079 #define PB_DS_BASE_C_DEC                        \
    00080     basic_tree_policy_base<             \
    00081                                 Const_Node_Iterator, \
    00082                                 Node_Iterator, \
    00083                                 Allocator>
    00084
    00085     template<typename Const_Node_Iterator,
    00086          class Node_Iterator,
    00087          class Cmp_Fn,
    00088          bool Node_Based,
    00089          class Allocator>
    00090     class tree_trace_base : private PB_DS_BASE_C_DEC
    00091     {
    00092     public:
    00093       void
    00094       trace() const;
    00095
    00096     private:
    00097       typedef PB_DS_BASE_C_DEC base_type;
    00098
    00099       typedef Const_Node_Iterator const_node_iterator;
    00100
    00101       typedef typename Allocator::size_type size_type;
    00102
    00103     private:
    00104       void
    00105       trace_node(const_node_iterator nd_it, size_type level) const;
    00106
    00107       virtual bool
    00108       empty() const = 0;
    00109
    00110       virtual const_node_iterator
    00111       node_begin() const = 0;
    00112
    00113       virtual const_node_iterator
    00114       node_end() const = 0;
    00115
    00116       static void
    00117       print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>);
    00118
    00119       static void
    00120       print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>);
    00121
    00122       template<typename Metadata_>
    00123       static void
    00124       trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>);
    00125
    00126       static void
    00127       trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>);
    00128     };
    00129
    00130     PB_DS_CLASS_T_DEC
    00131     void
    00132     PB_DS_CLASS_C_DEC::
    00133     trace() const
    00134     {
    00135       if (empty())
    00136         return;
    00137
    00138       trace_node(node_begin(), 0);
    00139     }
    00140
    00141     PB_DS_CLASS_T_DEC
    00142     void
    00143     PB_DS_CLASS_C_DEC::
    00144     trace_node(const_node_iterator nd_it, size_type level) const
    00145     {
    00146       if (nd_it.get_r_child() != node_end())
    00147         trace_node(nd_it.get_r_child(), level + 1);
    00148
    00149       for (size_type i = 0; i < level; ++i)
    00150         std::cerr << ' ';
    00151
    00152       print_node_pointer(nd_it, integral_constant<int,Node_Based>());
    00153       std::cerr << base_type::extract_key(*(*nd_it));
    00154
    00155       typedef
    00156         type_to_type<
    00157     typename const_node_iterator::metadata_type>
    00158         m_type_ind_t;
    00159
    00160       trace_it_metadata(nd_it, m_type_ind_t());
    00161
    00162       std::cerr << std::endl;
    00163
    00164       if (nd_it.get_l_child() != node_end())
    00165         trace_node(nd_it.get_l_child(), level + 1);
    00166     }
    00167
    00168     PB_DS_CLASS_T_DEC
    00169     template<typename Metadata_>
    00170     void
    00171     PB_DS_CLASS_C_DEC::
    00172     trace_it_metadata(Const_Node_Iterator nd_it, type_to_type<Metadata_>)
    00173     {
    00174       std::cerr << " (" <<
    00175         static_cast<unsigned long>(nd_it.get_metadata()) << ") ";
    00176     }
    00177
    00178     PB_DS_CLASS_T_DEC
    00179     void
    00180     PB_DS_CLASS_C_DEC::
    00181     trace_it_metadata(Const_Node_Iterator, type_to_type<null_node_metadata>)
    00182     { }
    00183
    00184     PB_DS_CLASS_T_DEC
    00185     void
    00186     PB_DS_CLASS_C_DEC::
    00187     print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,true>)
    00188     {
    00189       std::cerr << nd_it.m_p_nd << " ";
    00190     }
    00191
    00192     PB_DS_CLASS_T_DEC
    00193     void
    00194     PB_DS_CLASS_C_DEC::
    00195     print_node_pointer(Const_Node_Iterator nd_it, integral_constant<int,false>)
    00196     {
    00197       std::cerr <<* nd_it << " ";
    00198     }
    00199
    00200 #undef PB_DS_CLASS_T_DEC
    00201
    00202 #undef PB_DS_CLASS_C_DEC
    00203
    00204 #undef PB_DS_BASE_C_DEC
    00205
    00206 #endif // #ifdef    PB_DS_TREE_TRACE
    00207
    00208   } // namespace detail
    00209
    00210 } // namespace __gnu_pbds
    00211
    00212 #endif // #ifdef PB_DS_TREE_TRACE
    00213
    00214 #endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP
    00215