trace_fn_imps.hpp revision 169691
155714Skris// -*- C++ -*-
255714Skris
355714Skris// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
455714Skris//
555714Skris// This file is part of the GNU ISO C++ Library.  This library is free
655714Skris// software; you can redistribute it and/or modify it under the terms
755714Skris// of the GNU General Public License as published by the Free Software
8296465Sdelphij// Foundation; either version 2, or (at your option) any later
955714Skris// version.
1055714Skris
1155714Skris// This library is distributed in the hope that it will be useful, but
1255714Skris// WITHOUT ANY WARRANTY; without even the implied warranty of
1355714Skris// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1455714Skris// General Public License for more details.
15296465Sdelphij
1655714Skris// You should have received a copy of the GNU General Public License
1755714Skris// along with this library; see the file COPYING.  If not, write to
1855714Skris// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
1955714Skris// MA 02111-1307, USA.
2055714Skris
2155714Skris// As a special exception, you may use this file as part of a free
22296465Sdelphij// software library without restriction.  Specifically, if other files
2355714Skris// instantiate templates or use macros or inline functions from this
2455714Skris// file, or you compile this file and link it with other files to
2555714Skris// produce an executable, this file does not by itself cause the
2655714Skris// resulting executable to be covered by the GNU General Public
2755714Skris// License.  This exception does not however invalidate any other
2855714Skris// reasons why the executable file might be covered by the GNU General
2955714Skris// Public License.
3055714Skris
3155714Skris// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
3255714Skris
3355714Skris// Permission to use, copy, modify, sell, and distribute this software
3455714Skris// is hereby granted without fee, provided that the above copyright
3555714Skris// notice appears in all copies, and that both that copyright notice
3655714Skris// and this permission notice appear in supporting documentation. None
37296465Sdelphij// of the above authors, nor IBM Haifa Research Laboratories, make any
3855714Skris// representation about the suitability of this software for any
3955714Skris// purpose. It is provided "as is" without express or implied
40296465Sdelphij// warranty.
4155714Skris
4255714Skris/**
4355714Skris * @file trace_fn_imps.hpp
4455714Skris * Contains an implementation class for pat_trie_.
4555714Skris */
4655714Skris
4755714Skris#ifdef PB_DS_PAT_TRIE_TRACE_
4855714Skris
4955714SkrisPB_DS_CLASS_T_DEC
5055714Skrisvoid
5155714SkrisPB_DS_CLASS_C_DEC::
52296465Sdelphijtrace() const
5355714Skris{
5455714Skris  std::cerr << std::endl;
5555714Skris  if (m_p_head->m_p_parent == NULL)
5655714Skris    return;
5755714Skris  trace_node(m_p_head->m_p_parent, 0);
5855714Skris  std::cerr << std::endl;
59296465Sdelphij}
60296465Sdelphij
6155714SkrisPB_DS_CLASS_T_DEC
62296465Sdelphijvoid
63296465SdelphijPB_DS_CLASS_C_DEC::
64296465Sdelphijtrace_node(const_node_pointer p_nd, size_type level)
65296465Sdelphij{
66296465Sdelphij  for (size_type i = 0; i < level; ++i)
67296465Sdelphij    std::cerr << ' ';
68296465Sdelphij  std::cerr << p_nd << " ";
69296465Sdelphij  std::cerr << ((p_nd->m_type == pat_trie_leaf_node_type) ? "l " : "i ");
70160814Ssimon
7155714Skris  trace_node_metadata(p_nd, type_to_type<typename node::metadata_type>());
7255714Skris  typename e_access_traits::const_iterator el_it = pref_begin(p_nd);
73296465Sdelphij  while (el_it != pref_end(p_nd))
7455714Skris    {
7555714Skris      std::cerr <<* el_it;
7655714Skris      ++el_it;
7755714Skris    }
7855714Skris
79160814Ssimon  if (p_nd->m_type == pat_trie_leaf_node_type)
8055714Skris    {
81296465Sdelphij      std::cerr << std::endl;
82296465Sdelphij      return;
83296465Sdelphij    }
84296465Sdelphij
85296465Sdelphij  const_internal_node_pointer p_internal =
86160814Ssimon    static_cast<const_internal_node_pointer>(p_nd);
8755714Skris
8855714Skris  std::cerr << " " <<
8955714Skris    static_cast<unsigned long>(p_internal->get_e_ind()) << std::endl;
9055714Skris
9155714Skris  const size_type num_children = std::distance(p_internal->begin(),
92					       p_internal->end());
93
94  for (size_type child_i = 0; child_i < num_children; ++child_i)
95    {
96      typename internal_node::const_iterator child_it =
97	p_internal->begin();
98      std::advance(child_it, num_children - child_i - 1);
99      trace_node(*child_it, level + 1);
100    }
101}
102
103PB_DS_CLASS_T_DEC
104template<typename Metadata_>
105void
106PB_DS_CLASS_C_DEC::
107trace_node_metadata(const_node_pointer p_nd, type_to_type<Metadata_>)
108{
109  std::cerr << "(" << static_cast<unsigned long>(p_nd->get_metadata()) << ") ";
110}
111
112PB_DS_CLASS_T_DEC
113void
114PB_DS_CLASS_C_DEC::
115trace_node_metadata(const_node_pointer, type_to_type<null_node_metadata>)
116{ }
117
118#endif
119
120