node_enum.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2011-2016 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include "util/util_map.h"
  18. #include "util/util_param.h"
  19. CCL_NAMESPACE_BEGIN
  20. /* Enum
  21. *
  22. * Utility class for enum values. */
  23. struct NodeEnum {
  24. bool empty() const
  25. {
  26. return left.empty();
  27. }
  28. void insert(const char *x, int y)
  29. {
  30. left[ustring(x)] = y;
  31. right[y] = ustring(x);
  32. }
  33. bool exists(ustring x) const
  34. {
  35. return left.find(x) != left.end();
  36. }
  37. bool exists(int y) const
  38. {
  39. return right.find(y) != right.end();
  40. }
  41. int operator[](const char *x) const
  42. {
  43. return left.find(ustring(x))->second;
  44. }
  45. int operator[](ustring x) const
  46. {
  47. return left.find(x)->second;
  48. }
  49. ustring operator[](int y) const
  50. {
  51. return right.find(y)->second;
  52. }
  53. unordered_map<ustring, int, ustringHash>::const_iterator begin() const
  54. {
  55. return left.begin();
  56. }
  57. unordered_map<ustring, int, ustringHash>::const_iterator end() const
  58. {
  59. return left.end();
  60. }
  61. private:
  62. unordered_map<ustring, int, ustringHash> left;
  63. unordered_map<int, ustring> right;
  64. };
  65. CCL_NAMESPACE_END