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

/indra/llcommon/lldlinked.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 93 lines | 57 code | 11 blank | 25 comment | 4 complexity | 0021c8b1a19bef39fda025a4743ee18a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldlinked.h
  3. * @brief Declaration of the LLDLinked 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_LLDLINKED_H
  27. #define LL_LLDLINKED_H
  28. template <class Type> class LLDLinked
  29. {
  30. LLDLinked* mNextp;
  31. LLDLinked* mPrevp;
  32. public:
  33. Type* getNext() { return (Type*)mNextp; }
  34. Type* getPrev() { return (Type*)mPrevp; }
  35. Type* getFirst() { return (Type*)mNextp; }
  36. void init()
  37. {
  38. mNextp = mPrevp = NULL;
  39. }
  40. void unlink()
  41. {
  42. if (mPrevp) mPrevp->mNextp = mNextp;
  43. if (mNextp) mNextp->mPrevp = mPrevp;
  44. }
  45. LLDLinked() { mNextp = mPrevp = NULL; }
  46. virtual ~LLDLinked() { unlink(); }
  47. virtual void deleteAll()
  48. {
  49. Type *curp = getFirst();
  50. while(curp)
  51. {
  52. Type *nextp = curp->getNext();
  53. curp->unlink();
  54. delete curp;
  55. curp = nextp;
  56. }
  57. }
  58. void relink(Type &after)
  59. {
  60. LLDLinked *afterp = (LLDLinked*)&after;
  61. afterp->mPrevp = this;
  62. mNextp = afterp;
  63. }
  64. virtual void append(Type& after)
  65. {
  66. LLDLinked *afterp = (LLDLinked*)&after;
  67. afterp->mPrevp = this;
  68. afterp->mNextp = mNextp;
  69. if (mNextp) mNextp->mPrevp = afterp;
  70. mNextp = afterp;
  71. }
  72. virtual void insert(Type& before)
  73. {
  74. LLDLinked *beforep = (LLDLinked*)&before;
  75. beforep->mNextp = this;
  76. beforep->mPrevp = mPrevp;
  77. if (mPrevp) mPrevp->mNextp = beforep;
  78. mPrevp = beforep;
  79. }
  80. virtual void put(Type& obj) { append(obj); }
  81. };
  82. #endif