llstrider.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @file llstrider.h
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewergpl$
  5. *
  6. * Copyright (c) 2001-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_LLSTRIDER_H
  32. #define LL_LLSTRIDER_H
  33. #include "stdtypes.h"
  34. #include "llpreprocessor.h"
  35. template <class Object> class LLStrider
  36. {
  37. public:
  38. LL_INLINE LLStrider()
  39. : mObjectp(NULL),
  40. mSkip(sizeof(Object))
  41. {
  42. }
  43. LL_INLINE LLStrider(Object* firstp)
  44. : mObjectp(firstp),
  45. mSkip(sizeof(Object))
  46. {
  47. }
  48. LL_INLINE ~LLStrider() {}
  49. LL_INLINE const LLStrider<Object>& operator=(Object* firstp)
  50. {
  51. mObjectp = firstp;
  52. return *this;
  53. }
  54. LL_INLINE void setStride(S32 skip)
  55. {
  56. mSkip = skip ? skip : sizeof(Object);
  57. }
  58. LL_INLINE LLStrider<Object> operator+(const S32& index)
  59. {
  60. LLStrider<Object> ret;
  61. ret.mBytep = mBytep + mSkip * index;
  62. ret.mSkip = mSkip;
  63. return ret;
  64. }
  65. LL_INLINE void skip(U32 index) { mBytep += mSkip * index;}
  66. LL_INLINE U32 getSkip() const { return mSkip; }
  67. LL_INLINE Object* get() { return mObjectp; }
  68. LL_INLINE const Object* get() const { return mObjectp; }
  69. LL_INLINE Object* operator->() { return mObjectp; }
  70. LL_INLINE Object& operator*() { return *mObjectp; }
  71. LL_INLINE Object* operator++(int)
  72. {
  73. Object* old = mObjectp;
  74. mBytep += mSkip;
  75. return old;
  76. }
  77. LL_INLINE Object* operator+=(int i)
  78. {
  79. mBytep += mSkip * i;
  80. return mObjectp;
  81. }
  82. LL_INLINE Object& operator[](U32 index)
  83. {
  84. return *(Object*)(mBytep + mSkip * index);
  85. }
  86. private:
  87. union
  88. {
  89. Object* mObjectp;
  90. U8* mBytep;
  91. };
  92. U32 mSkip;
  93. };
  94. #endif // LL_LLSTRIDER_H