PageRenderTime 97ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/lldepthstack.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 99 lines | 61 code | 12 blank | 26 comment | 2 complexity | ef27ddac0a06e9853568279ac229f842 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldepthstack.h
  3. * @brief Declaration of the LLDepthStack class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLDEPTHSTACK_H
  27. #define LL_LLDEPTHSTACK_H
  28. #include "linked_lists.h"
  29. template <class DATA_TYPE> class LLDepthStack
  30. {
  31. private:
  32. LLLinkedList<DATA_TYPE> mStack;
  33. U32 mCurrentDepth;
  34. U32 mMaxDepth;
  35. public:
  36. LLDepthStack() : mCurrentDepth(0), mMaxDepth(0) {}
  37. ~LLDepthStack() {}
  38. void setDepth(U32 depth)
  39. {
  40. mMaxDepth = depth;
  41. }
  42. U32 getDepth(void) const
  43. {
  44. return mCurrentDepth;
  45. }
  46. void push(DATA_TYPE *data)
  47. {
  48. if (mCurrentDepth < mMaxDepth)
  49. {
  50. mStack.addData(data);
  51. mCurrentDepth++;
  52. }
  53. else
  54. {
  55. // the last item falls off stack and is deleted
  56. mStack.getLastData();
  57. mStack.deleteCurrentData();
  58. mStack.addData(data);
  59. }
  60. }
  61. DATA_TYPE *pop()
  62. {
  63. DATA_TYPE *tempp = mStack.getFirstData();
  64. if (tempp)
  65. {
  66. mStack.removeCurrentData();
  67. mCurrentDepth--;
  68. }
  69. return tempp;
  70. }
  71. DATA_TYPE *check()
  72. {
  73. DATA_TYPE *tempp = mStack.getFirstData();
  74. return tempp;
  75. }
  76. void deleteAllData()
  77. {
  78. mCurrentDepth = 0;
  79. mStack.deleteAllData();
  80. }
  81. void removeAllNodes()
  82. {
  83. mCurrentDepth = 0;
  84. mStack.removeAllNodes();
  85. }
  86. };
  87. #endif