nux-0.9.46
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NODEITEM_H 00024 #define NODEITEM_H 00025 00026 namespace nux 00027 { 00028 00029 class NodeItem 00030 { 00031 #ifndef NUX_STANDALONE 00032 NUX_DECLARE_ROOT_OBJECT_TYPE (NodeItem); 00033 #endif 00034 public: 00035 NodeItem(); 00036 virtual ~NodeItem(); 00037 00038 int get_num_child() 00039 { 00040 int num = 0; 00041 NodeItem *item = child_head; 00042 00043 while (item) 00044 { 00045 num++; 00046 item = item->Next(); 00047 } 00048 00049 return num; 00050 } 00051 00052 NodeItem *FirstSibling ( void ); 00053 NodeItem *LastSibling ( void ); 00054 NodeItem *Prev ( void ) 00055 { 00056 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Prev() ); 00057 } 00058 NodeItem *Next ( void ) 00059 { 00060 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Next() ); 00061 } 00062 const NodeItem *Prev ( void ) const; 00063 const NodeItem *Next ( void ) const; 00064 00065 NodeItem *FirstChildNode ( void ) 00066 { 00067 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->FirstChildNode() ); 00068 } 00069 const NodeItem *FirstChildNode ( void ) const 00070 { 00071 return child_head; 00072 }; 00073 00074 NodeItem *LastChildNode ( void ) 00075 { 00076 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->LastChildNode() ); 00077 } 00078 const NodeItem *LastChildNode ( void ) const 00079 { 00080 return child_tail; 00081 }; 00082 00083 NodeItem *Parent (void) 00084 { 00085 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->Parent() ); 00086 } 00087 const NodeItem *Parent (void) const 00088 { 00089 return parent_node; 00090 }; 00091 00092 bool FindNode (NodeItem *); 00093 00094 NodeItem *RootNode() 00095 { 00096 return const_cast< NodeItem * > ( (const_cast< const NodeItem * > (this) )->RootNode() ); 00097 } 00098 const NodeItem *RootNode() const; 00099 00100 int NumChild() const; 00101 int Depth() const; 00102 virtual void PushChildFront ( NodeItem *child ); 00103 virtual void PushChildBack ( NodeItem *child ); 00104 virtual void AddNextSibling ( NodeItem *sibling ); 00105 virtual void AddPrevSibling ( NodeItem *sibling ); 00106 virtual void Unlink ( void ); 00107 virtual void Unlink ( NodeItem *child ); 00108 00109 void DeleteTree(); 00110 00111 // Sometimes it may be necessary to skip the child of some elements because the elements takes care of them. 00112 // See Vector4PropertyItem. 00113 virtual bool SkipChild() const 00114 { 00115 return false; 00116 } 00117 00118 void link_this_to_parent_last ( NodeItem *parent ); 00119 void link_this_to_parent_first ( NodeItem *parent ); 00120 void link_this_to_sibling_next ( NodeItem *sibling ); 00121 void link_this_to_sibling_prev ( NodeItem *sibling ); 00122 00123 protected: 00124 NodeItem *parent_node; 00125 NodeItem *child_head; 00126 NodeItem *child_tail; 00127 NodeItem *next_sibling; 00128 NodeItem *prev_sibling; 00129 }; 00130 00131 } 00132 00133 #endif // NODEITEM_H