Main Page Class Hierarchy Alphabetical List Compound List Examples

tree.h
1/***************************************************************************
2 copyright : (C) 2002-2008 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: tree.h,v 1.5 2008-10-07 11:06:26 tat Exp $
6 ***************************************************************************/
7#ifndef _MIMETIC_TREE_H_
8#define _MIMETIC_TREE_H_
9#include <list>
10#include <iostream>
11
12 namespace mimetic
13{
14
15/// INTERNAL: N-tree impl.
16 template<typename value_type>
17 struct TreeNode
18{
19 typedef TreeNode<value_type> self_type;
20 typedef std::list<TreeNode<value_type> > NodeList;
21 TreeNode()
22 {
23 }
24 TreeNode(const value_type& data)
25 : m_data(data)
26 {
27 }
28 void set(const value_type& data)
29 {
30 m_data = data;
31 }
32 value_type& get()
33 {
34 return m_data;
35 }
36 const value_type& get() const
37 {
38 return m_data;
39 }
40 NodeList& childList()
41 {
42 return m_nList;
43 }
44 const NodeList& childList() const
45 {
46 return m_nList;
47 }
48 private:
49 NodeList m_nList;
50 value_type m_data;
51};
52
53 template<typename value_type>
54 struct FindNodePred
55{
56 FindNodePred(const value_type& data)
57 : m_data(data)
58 {
59 }
60 inline bool operator()(const TreeNode<value_type>& node) const
61 {
62 return node.get() == m_data;
63 }
64 private:
65 value_type m_data;
66};
67
68}
69
70#endif
71
mimetic
Definition body.h:18