00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef VAR_TREE_HPP
00025 #define VAR_TREE_HPP
00026
00027 #include <list>
00028
00029 #include "variable.hpp"
00030 #include "observer.hpp"
00031 #include "ustring.hpp"
00032 #include "var_percent.hpp"
00033
00035 class VarTree: public Variable, public Subject<VarTree>
00036 {
00037 public:
00038 VarTree( intf_thread_t *pIntf );
00039
00040 VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
00041 const UStringPtr &rcString, bool selected, bool playing,
00042 bool expanded, void *pData );
00043
00044 virtual ~VarTree();
00045
00047 virtual const string &getType() const { return m_type; }
00048
00050 virtual void add( int id, const UStringPtr &rcString, bool selected,
00051 bool playing, bool expanded, void *pData );
00052
00054 virtual void delSelected();
00055
00057 virtual void clear();
00058
00060 int m_id;
00061 UStringPtr m_cString;
00062 bool m_selected;
00063 bool m_playing;
00064 bool m_expanded;
00065 void *m_pData;
00066
00068 int size() const { return m_children.size(); }
00069
00071 typedef list<VarTree>::iterator Iterator;
00072 typedef list<VarTree>::const_iterator ConstIterator;
00073
00075 Iterator begin() { return m_children.begin(); }
00076 ConstIterator begin() const { return m_children.begin(); }
00077
00079 Iterator end() { return m_children.end(); }
00080 ConstIterator end() const { return m_children.end(); }
00081
00083 VarTree &back() { return m_children.back(); }
00084
00086 Iterator operator[]( int n );
00087 ConstIterator operator[]( int n ) const;
00088
00090 VarTree *parent() { return m_pParent; }
00091 void VarTree::checkParents( VarTree *pParent );
00092
00093 Iterator uncle();
00094
00096 VarTree *root()
00097 {
00098 VarTree *parent = this;
00099 while( parent->parent() != NULL )
00100 parent = parent->parent();
00101 return parent;
00102 }
00103
00105 int depth()
00106 {
00107 VarTree *parent = this;
00108 int depth = 0;
00109 while( ( parent = parent->parent() ) != NULL )
00110 depth++;
00111 return depth;
00112 }
00113
00115 virtual void action( VarTree *pItem ) {}
00116
00118 VarPercent &getPositionVar() const
00119 { return *((VarPercent*)m_cPosition.get()); }
00120
00122 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
00123
00125 int visibleItems();
00126
00128 Iterator getVisibleItem( int n );
00129
00131 Iterator getNextVisibleItem( Iterator it );
00132
00134 Iterator findById( int id );
00135
00136 private:
00138 list<VarTree> m_children;
00139
00141 VarTree *m_pParent;
00142
00144 static const string m_type;
00145
00147 VariablePtr m_cPosition;
00148 };
00149
00150 #endif