SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2012 Chiyuan Zhang 00008 * Copyright (C) 2012 Chiyuan Zhang 00009 */ 00010 00011 #ifndef TREEMACHINENODE_H__ 00012 #define TREEMACHINENODE_H__ 00013 00014 #include <shogun/base/SGObject.h> 00015 #include <shogun/base/Parameter.h> 00016 00017 namespace shogun 00018 { 00019 00021 template <typename T> 00022 class CTreeMachineNode 00023 : public CSGObject 00024 { 00025 public: 00027 CTreeMachineNode() 00028 :m_left(NULL), m_right(NULL), m_parent(NULL), m_machine(-1) 00029 { 00030 SG_ADD((CSGObject**)&m_left,"m_left", "Left subtree", MS_NOT_AVAILABLE); 00031 SG_ADD((CSGObject**)&m_right,"m_right", "Right subtree", MS_NOT_AVAILABLE); 00032 SG_ADD((CSGObject**)&m_parent,"m_parent", "Parent node", MS_NOT_AVAILABLE); 00033 SG_ADD(&m_machine,"m_machine", "Index of associated machine", MS_NOT_AVAILABLE); 00034 } 00035 00036 00038 virtual ~CTreeMachineNode() 00039 { 00040 SG_UNREF(m_left); 00041 SG_UNREF(m_right); 00042 } 00043 00045 virtual const char* get_name() const { return "TreeMachineNode"; } 00046 00050 void machine(int32_t idx) 00051 { 00052 m_machine = idx; 00053 } 00055 int32_t machine() 00056 { 00057 return m_machine; 00058 } 00059 00063 void parent(CTreeMachineNode *par) 00064 { 00065 m_parent = par; 00066 } 00068 CTreeMachineNode *parent() 00069 { 00070 return m_parent; 00071 } 00072 00076 void left(CTreeMachineNode *l) 00077 { 00078 SG_REF(l); 00079 SG_UNREF(m_left); 00080 m_left = l; 00081 m_left->parent(this); 00082 } 00084 CTreeMachineNode *left() 00085 { 00086 return m_left; 00087 } 00088 00092 void right(CTreeMachineNode *r) 00093 { 00094 SG_REF(r); 00095 SG_UNREF(m_right); 00096 m_right = r; 00097 m_right->parent(this); 00098 } 00100 CTreeMachineNode *right() 00101 { 00102 return m_right; 00103 } 00104 00106 T data; 00107 00109 typedef void (*data_print_func_t) (const T&); 00113 void debug_print(data_print_func_t data_print_func) 00114 { 00115 debug_print_impl(data_print_func, this, 0); 00116 } 00117 00118 private: 00119 CTreeMachineNode *m_left; 00120 CTreeMachineNode *m_right; 00121 CTreeMachineNode *m_parent; 00122 int32_t m_machine; 00123 00125 static void debug_print_impl(data_print_func_t data_print_func, CTreeMachineNode<T> *node, int32_t depth) 00126 { 00127 for (int32_t i=0; i < depth; ++i) 00128 SG_SPRINT(" ") 00129 data_print_func(node->data); 00130 if (node->left()) 00131 debug_print_impl(data_print_func, node->left(), depth+1); 00132 if (node->right()) 00133 debug_print_impl(data_print_func, node->right(), depth+1); 00134 } 00135 }; 00136 00137 } /* shogun */ 00138 00139 #endif /* end of include guard: TREEMACHINENODE_H__ */ 00140