PageRenderTime 31ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llenum.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 78 lines | 45 code | 7 blank | 26 comment | 5 complexity | 6598cabfefe82e85155d69d10b2805ae MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llenum.h
  3. * @author Tom Yedwab
  4. * @brief Utility class for storing enum value <-> string lookup.
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLENUM_H
  28. #define LL_LLENUM_H
  29. class LLEnum
  30. {
  31. public:
  32. typedef std::pair<const std::string, const U32> enum_t;
  33. enum
  34. {
  35. UNDEFINED = 0xffffffff,
  36. };
  37. LLEnum(const enum_t values_array[], const U32 length)
  38. {
  39. for (U32 i=0; i<length; ++i)
  40. {
  41. mEnumMap.insert(values_array[i]);
  42. if (values_array[i].second >= mEnumArray.size())
  43. {
  44. mEnumArray.resize(values_array[i].second+1);
  45. }
  46. mEnumArray[values_array[i].second] = values_array[i].first;
  47. }
  48. }
  49. U32 operator[](std::string str)
  50. {
  51. std::map<const std::string, const U32>::iterator itor;
  52. itor = mEnumMap.find(str);
  53. if (itor != mEnumMap.end())
  54. {
  55. return itor->second;
  56. }
  57. return UNDEFINED;
  58. }
  59. const std::string operator[](U32 index)
  60. {
  61. if (index < mEnumArray.size())
  62. {
  63. return mEnumArray[index];
  64. }
  65. return "";
  66. }
  67. private:
  68. std::map<const std::string, const U32> mEnumMap;
  69. std::vector<std::string> mEnumArray;
  70. };
  71. #endif // LL_LLENUM_H