Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  

tree.h

00001 /***************************************************************************
00002     copyright            : (C) 2002-2005 by Stefano Barbato
00003     email                : [email protected]
00004 
00005     $Id: tree_8h-source.html,v 1.4 2006-03-12 12:28:32 tat Exp $
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _MIMETIC_TREE_H_
00017 #define _MIMETIC_TREE_H_
00018 #include <list>
00019 #include <iostream>
00020 
00021 namespace mimetic
00022 {
00023 
00024 /// INTERNAL: N-tree impl.
00025 template<typename value_type>
00026 struct TreeNode 
00027 {
00028     typedef TreeNode<value_type> self_type;
00029     typedef std::list<TreeNode<value_type> > NodeList;
00030     TreeNode()
00031     {
00032     }
00033     TreeNode(const value_type& data)
00034     : m_data(data)
00035     {
00036     }
00037     void set(const value_type& data)
00038     {
00039         m_data = data;
00040     }
00041     value_type& get()
00042     {
00043         return m_data;
00044     }
00045     const value_type& get() const
00046     {
00047         return m_data;
00048     }
00049     NodeList& childList()
00050     {
00051         return m_nList;
00052     }
00053     const NodeList& childList() const
00054     {
00055         return m_nList;
00056     }
00057 private:
00058     NodeList m_nList;
00059     value_type m_data;
00060 };
00061 
00062 template<typename value_type>
00063 struct FindNodePred
00064 {
00065     FindNodePred(const value_type& data)
00066     : m_data(data)
00067     {
00068     }
00069     inline bool operator()(const TreeNode<value_type>& node) const
00070     {
00071         return node.get() == m_data;
00072     }
00073 private:
00074     value_type m_data;
00075 };
00076 
00077 }
00078 
00079 #endif
00080