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 17 #pragma once 18 19 #include "util/util_map.h" 20 #include "util/util_param.h" 21 22 CCL_NAMESPACE_BEGIN 23 24 /* Enum 25 * 26 * Utility class for enum values. */ 27 28 struct NodeEnum { emptyNodeEnum29 bool empty() const 30 { 31 return left.empty(); 32 } insertNodeEnum33 void insert(const char *x, int y) 34 { 35 left[ustring(x)] = y; 36 right[y] = ustring(x); 37 } 38 existsNodeEnum39 bool exists(ustring x) const 40 { 41 return left.find(x) != left.end(); 42 } existsNodeEnum43 bool exists(int y) const 44 { 45 return right.find(y) != right.end(); 46 } 47 48 int operator[](const char *x) const 49 { 50 return left.find(ustring(x))->second; 51 } 52 int operator[](ustring x) const 53 { 54 return left.find(x)->second; 55 } 56 ustring operator[](int y) const 57 { 58 return right.find(y)->second; 59 } 60 beginNodeEnum61 unordered_map<ustring, int, ustringHash>::const_iterator begin() const 62 { 63 return left.begin(); 64 } endNodeEnum65 unordered_map<ustring, int, ustringHash>::const_iterator end() const 66 { 67 return left.end(); 68 } 69 70 private: 71 unordered_map<ustring, int, ustringHash> left; 72 unordered_map<int, ustring> right; 73 }; 74 75 CCL_NAMESPACE_END 76