1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef TrenchBroom_EntityAttributeIndex 21 #define TrenchBroom_EntityAttributeIndex 22 23 #include "StringUtils.h" 24 #include "Model/ModelTypes.h" 25 #include "StringMap.h" 26 27 #include <map> 28 29 namespace TrenchBroom { 30 namespace Model { 31 typedef StringMultiMapValueContainer<AttributableNode*> AttributableNodeIndexValueContainer; 32 typedef StringMap<AttributableNode*, AttributableNodeIndexValueContainer> AttributableNodeStringIndex; 33 34 class AttributableNodeIndexQuery { 35 public: 36 typedef enum { 37 Type_Exact, 38 Type_Prefix, 39 Type_Numbered, 40 Type_Any 41 } Type; 42 private: 43 Type m_type; 44 String m_pattern; 45 public: 46 static AttributableNodeIndexQuery exact(const String& pattern); 47 static AttributableNodeIndexQuery prefix(const String& pattern); 48 static AttributableNodeIndexQuery numbered(const String& pattern); 49 static AttributableNodeIndexQuery any(); 50 51 AttributableNodeSet execute(const AttributableNodeStringIndex& index) const; 52 bool execute(const AttributableNode* node, const String& value) const; 53 private: 54 AttributableNodeIndexQuery(Type type, const String& pattern = ""); 55 }; 56 57 class AttributableNodeIndex { 58 private: 59 AttributableNodeStringIndex m_nameIndex; 60 AttributableNodeStringIndex m_valueIndex; 61 public: 62 void addAttributableNode(AttributableNode* attributable); 63 void removeAttributableNode(AttributableNode* attributable); 64 65 void addAttribute(AttributableNode* attributable, const AttributeName& name, const AttributeValue& value); 66 void removeAttribute(AttributableNode* attributable, const AttributeName& name, const AttributeValue& value); 67 68 AttributableNodeList findAttributableNodes(const AttributableNodeIndexQuery& keyQuery, const AttributeValue& value) const; 69 }; 70 } 71 } 72 73 #endif /* defined(TrenchBroom_EntityAttributeIndex) */ 74