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

/indra/newview/lltable.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 66 lines | 37 code | 4 blank | 25 comment | 7 complexity | f096db0dd9d34c82c1a7f568eb13c51a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltable.h
  3. * @brief Description of LLTable template class
  4. *
  5. * $LicenseInfo:firstyear=2002&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_LLTABLE_H
  27. #define LL_LLTABLE_H
  28. template<class T> class LLTable
  29. {
  30. private:
  31. T *_tab;
  32. U32 _w;
  33. U32 _h;
  34. U32 _size;
  35. public:
  36. LLTable(U32 w, U32 h = 0) : _tab(0), _w(w), _h(h)
  37. {
  38. if (_w < 0) _w = 0;
  39. if (_h < 0) _h = 0;
  40. if (0 == h)
  41. _h = _w;
  42. _size = _w * _h;
  43. if ((_w > 0) && (_h > 0))
  44. _tab = new T[_size];
  45. }
  46. ~LLTable()
  47. {
  48. delete[] _tab;
  49. _tab = NULL;
  50. }
  51. void init(const T& t)
  52. {
  53. for (U32 i = 0; i < _size; ++i)
  54. _tab[i] = t;
  55. }
  56. const T& at(U32 w, U32 h) const { return _tab[h * _w + w]; }
  57. T& at(U32 w, U32 h) { return _tab[h * _w + w]; }
  58. U32 size() const { return _size; }
  59. U32 w() const { return _w; }
  60. U32 h() const { return _h; }
  61. };
  62. #endif // LL_LLTABLE_H