PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmath/lltreenode.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 117 lines | 78 code | 15 blank | 24 comment | 3 complexity | 43849b67300a6ca4f79ac4084e1a4541 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltreenode.h
  3. *
  4. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #ifndef LL_LLTREENODE_H
  26. #define LL_LLTREENODE_H
  27. #include "stdtypes.h"
  28. #include "xform.h"
  29. #include "llpointer.h"
  30. #include "llrefcount.h"
  31. #include <vector>
  32. template <class T> class LLTreeNode;
  33. template <class T> class LLTreeTraveler;
  34. template <class T> class LLTreeListener;
  35. template <class T>
  36. class LLTreeListener: public LLRefCount
  37. {
  38. public:
  39. virtual void handleInsertion(const LLTreeNode<T>* node, T* data) = 0;
  40. virtual void handleRemoval(const LLTreeNode<T>* node, T* data) = 0;
  41. virtual void handleDestruction(const LLTreeNode<T>* node) = 0;
  42. virtual void handleStateChange(const LLTreeNode<T>* node) = 0;
  43. };
  44. template <class T>
  45. class LLTreeNode
  46. {
  47. public:
  48. virtual ~LLTreeNode();
  49. virtual bool insert(T* data);
  50. virtual bool remove(T* data);
  51. virtual void notifyRemoval(T* data);
  52. virtual U32 getListenerCount() { return mListeners.size(); }
  53. virtual LLTreeListener<T>* getListener(U32 index) const { return mListeners[index]; }
  54. virtual void addListener(LLTreeListener<T>* listener) { mListeners.push_back(listener); }
  55. protected:
  56. void destroyListeners()
  57. {
  58. for (U32 i = 0; i < mListeners.size(); i++)
  59. {
  60. mListeners[i]->handleDestruction(this);
  61. }
  62. mListeners.clear();
  63. }
  64. public:
  65. std::vector<LLPointer<LLTreeListener<T> > > mListeners;
  66. };
  67. template <class T>
  68. class LLTreeTraveler
  69. {
  70. public:
  71. virtual ~LLTreeTraveler() { };
  72. virtual void traverse(const LLTreeNode<T>* node) = 0;
  73. virtual void visit(const LLTreeNode<T>* node) = 0;
  74. };
  75. template <class T>
  76. LLTreeNode<T>::~LLTreeNode()
  77. {
  78. destroyListeners();
  79. };
  80. template <class T>
  81. bool LLTreeNode<T>::insert(T* data)
  82. {
  83. for (U32 i = 0; i < mListeners.size(); i++)
  84. {
  85. mListeners[i]->handleInsertion(this, data);
  86. }
  87. return true;
  88. };
  89. template <class T>
  90. bool LLTreeNode<T>::remove(T* data)
  91. {
  92. return true;
  93. };
  94. template <class T>
  95. void LLTreeNode<T>::notifyRemoval(T* data)
  96. {
  97. for (U32 i = 0; i < mListeners.size(); i++)
  98. {
  99. mListeners[i]->handleRemoval(this, data);
  100. }
  101. }
  102. #endif