aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/lltreenode.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmath/lltreenode.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llmath/lltreenode.h89
1 files changed, 13 insertions, 76 deletions
diff --git a/linden/indra/llmath/lltreenode.h b/linden/indra/llmath/lltreenode.h
index 160a5bd..64beed8 100644
--- a/linden/indra/llmath/lltreenode.h
+++ b/linden/indra/llmath/lltreenode.h
@@ -40,23 +40,6 @@ template <class T> class LLTreeTraveler;
40template <class T> class LLTreeListener; 40template <class T> class LLTreeListener;
41 41
42template <class T> 42template <class T>
43class LLTreeState
44{
45public:
46 LLTreeState(LLTreeNode<T>* node) { setNode(node); }
47 virtual ~LLTreeState() { };
48 virtual bool insert(T* data) = 0;
49 virtual bool remove(T* data) = 0;
50 virtual void setNode(LLTreeNode<T>* node);
51 virtual const LLTreeNode<T>* getNode() const { return mNode; }
52 virtual LLTreeNode<T>* getNode() { return mNode; }
53 virtual void accept(LLTreeTraveler<T>* traveler) const = 0;
54 virtual LLTreeListener<T>* getListener(U32 index) const;
55private:
56 LLTreeNode<T>* mNode;
57};
58
59template <class T>
60class LLTreeListener: public LLRefCount 43class LLTreeListener: public LLRefCount
61{ 44{
62public: 45public:
@@ -70,19 +53,14 @@ template <class T>
70class LLTreeNode 53class LLTreeNode
71{ 54{
72public: 55public:
73 LLTreeNode(LLTreeState<T>* state) { setState(state); }
74 virtual ~LLTreeNode(); 56 virtual ~LLTreeNode();
75 LLTreeState<T>* getState() { return mState; } 57
76 const LLTreeState<T>* getState() const { return mState; } 58 virtual bool insert(T* data);
77 59 virtual bool remove(T* data);
78 void setState(LLTreeState<T>* state); 60 virtual void notifyRemoval(T* data);
79 void insert(T* data); 61 virtual U32 getListenerCount() { return mListeners.size(); }
80 bool remove(T* data); 62 virtual LLTreeListener<T>* getListener(U32 index) const { return mListeners[index]; }
81 void notifyRemoval(T* data); 63 virtual void addListener(LLTreeListener<T>* listener) { mListeners.push_back(listener); }
82 inline U32 getListenerCount() { return mListeners.size(); }
83 inline LLTreeListener<T>* getListener(U32 index) const { return mListeners[index]; }
84 inline void addListener(LLTreeListener<T>* listener) { mListeners.push_back(listener); }
85 inline void removeListener(U32 index) { mListeners.erase(mListeners.begin()+index); }
86 64
87protected: 65protected:
88 void destroyListeners() 66 void destroyListeners()
@@ -94,7 +72,6 @@ protected:
94 mListeners.clear(); 72 mListeners.clear();
95 } 73 }
96 74
97 LLTreeState<T>* mState;
98public: 75public:
99 std::vector<LLPointer<LLTreeListener<T> > > mListeners; 76 std::vector<LLPointer<LLTreeListener<T> > > mListeners;
100}; 77};
@@ -105,7 +82,7 @@ class LLTreeTraveler
105public: 82public:
106 virtual ~LLTreeTraveler() { }; 83 virtual ~LLTreeTraveler() { };
107 virtual void traverse(const LLTreeNode<T>* node) = 0; 84 virtual void traverse(const LLTreeNode<T>* node) = 0;
108 virtual void visit(const LLTreeState<T>* state) = 0; 85 virtual void visit(const LLTreeNode<T>* node) = 0;
109}; 86};
110 87
111template <class T> 88template <class T>
@@ -115,25 +92,19 @@ LLTreeNode<T>::~LLTreeNode()
115}; 92};
116 93
117template <class T> 94template <class T>
118void LLTreeNode<T>::insert(T* data) 95bool LLTreeNode<T>::insert(T* data)
119{ 96{
120 if (mState->insert(data)) 97 for (U32 i = 0; i < mListeners.size(); i++)
121 { 98 {
122 for (U32 i = 0; i < mListeners.size(); i++) 99 mListeners[i]->handleInsertion(this, data);
123 {
124 mListeners[i]->handleInsertion(this, data);
125 }
126 } 100 }
101 return true;
127}; 102};
128 103
129template <class T> 104template <class T>
130bool LLTreeNode<T>::remove(T* data) 105bool LLTreeNode<T>::remove(T* data)
131{ 106{
132 if (mState->remove(data)) 107 return true;
133 {
134 return true;
135 }
136 return false;
137}; 108};
138 109
139template <class T> 110template <class T>
@@ -145,38 +116,4 @@ void LLTreeNode<T>::notifyRemoval(T* data)
145 } 116 }
146} 117}
147 118
148template <class T>
149void LLTreeNode<T>::setState(LLTreeState<T>* state)
150{
151 mState = state;
152 if (state)
153 {
154 if (state->getNode() != this)
155 {
156 state->setNode(this);
157 }
158
159 for (U32 i = 0; i < mListeners.size(); i++)
160 {
161 mListeners[i]->handleStateChange(this);
162 }
163 }
164};
165
166template <class T>
167void LLTreeState<T>::setNode(LLTreeNode<T>* node)
168{
169 mNode = node;
170 if (node && node->getState() != this)
171 {
172 node->setState(this);
173 }
174};
175
176template <class T>
177LLTreeListener<T>* LLTreeState<T>::getListener(U32 index) const
178{
179 return mNode->getListener(index);
180}
181
182#endif 119#endif