SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TreeMachineNode.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Chiyuan Zhang
8  * Copyright (C) 2012 Chiyuan Zhang
9  */
10 
11 #ifndef TREEMACHINENODE_H__
12 #define TREEMACHINENODE_H__
13 
14 #include <shogun/base/SGObject.h>
15 #include <shogun/base/Parameter.h>
16 
17 namespace shogun
18 {
19 
21 template <typename T>
23  : public CSGObject
24 {
25 public:
28  :m_left(NULL), m_right(NULL), m_parent(NULL), m_machine(-1)
29  {
30  SG_ADD((CSGObject**)&m_left,"m_left", "Left subtree", MS_NOT_AVAILABLE);
31  SG_ADD((CSGObject**)&m_right,"m_right", "Right subtree", MS_NOT_AVAILABLE);
32  SG_ADD((CSGObject**)&m_parent,"m_parent", "Parent node", MS_NOT_AVAILABLE);
33  SG_ADD(&m_machine,"m_machine", "Index of associated machine", MS_NOT_AVAILABLE);
34  }
35 
36 
39  {
40  SG_UNREF(m_left);
41  SG_UNREF(m_right);
42  }
43 
45  virtual const char* get_name() const { return "TreeMachineNode"; }
46 
50  void machine(int32_t idx)
51  {
52  m_machine = idx;
53  }
55  int32_t machine()
56  {
57  return m_machine;
58  }
59 
64  {
65  m_parent = par;
66  }
69  {
70  return m_parent;
71  }
72 
77  {
78  SG_REF(l);
79  SG_UNREF(m_left);
80  m_left = l;
81  m_left->parent(this);
82  }
85  {
86  return m_left;
87  }
88 
93  {
94  SG_REF(r);
95  SG_UNREF(m_right);
96  m_right = r;
97  m_right->parent(this);
98  }
101  {
102  return m_right;
103  }
104 
106  T data;
107 
109  typedef void (*data_print_func_t) (const T&);
113  void debug_print(data_print_func_t data_print_func)
114  {
115  debug_print_impl(data_print_func, this, 0);
116  }
117 
118 private:
119  CTreeMachineNode *m_left;
120  CTreeMachineNode *m_right;
121  CTreeMachineNode *m_parent;
122  int32_t m_machine;
123 
125  static void debug_print_impl(data_print_func_t data_print_func, CTreeMachineNode<T> *node, int32_t depth)
126  {
127  for (int32_t i=0; i < depth; ++i)
128  SG_SPRINT(" ");
129  data_print_func(node->data);
130  if (node->left())
131  debug_print_impl(data_print_func, node->left(), depth+1);
132  if (node->right())
133  debug_print_impl(data_print_func, node->right(), depth+1);
134  }
135 };
136 
137 } /* shogun */
138 
139 #endif /* end of include guard: TREEMACHINENODE_H__ */
140 

SHOGUN Machine Learning Toolbox - Documentation