Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  

tree.h

00001 /***************************************************************************
00002     copyright            : (C) 2002-2008 by Stefano Barbato
00003     email                : stefano@codesink.org
00004 
00005     $Id: tree.h,v 1.5 2008-10-07 11:06:26 tat Exp $
00006  ***************************************************************************/
00007 #ifndef _MIMETIC_TREE_H_
00008 #define _MIMETIC_TREE_H_
00009 #include <list>
00010 #include <iostream>
00011 
00012 namespace mimetic
00013 {
00014 
00015 /// INTERNAL: N-tree impl.
00016 template<typename value_type>
00017 struct TreeNode 
00018 {
00019     typedef TreeNode<value_type> self_type;
00020     typedef std::list<TreeNode<value_type> > NodeList;
00021     TreeNode()
00022     {
00023     }
00024     TreeNode(const value_type& data)
00025     : m_data(data)
00026     {
00027     }
00028     void set(const value_type& data)
00029     {
00030         m_data = data;
00031     }
00032     value_type& get()
00033     {
00034         return m_data;
00035     }
00036     const value_type& get() const
00037     {
00038         return m_data;
00039     }
00040     NodeList& childList()
00041     {
00042         return m_nList;
00043     }
00044     const NodeList& childList() const
00045     {
00046         return m_nList;
00047     }
00048 private:
00049     NodeList m_nList;
00050     value_type m_data;
00051 };
00052 
00053 template<typename value_type>
00054 struct FindNodePred
00055 {
00056     FindNodePred(const value_type& data)
00057     : m_data(data)
00058     {
00059     }
00060     inline bool operator()(const TreeNode<value_type>& node) const
00061     {
00062         return node.get() == m_data;
00063     }
00064 private:
00065     value_type m_data;
00066 };
00067 
00068 }
00069 
00070 #endif
00071