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_CollectMatchingBrushFacesVisitor 21 #define TrenchBroom_CollectMatchingBrushFacesVisitor 22 23 #include "CollectionUtils.h" 24 #include "Model/Brush.h" 25 #include "Model/BrushFace.h" 26 #include "Model/BrushFacePredicates.h" 27 #include "Model/ModelTypes.h" 28 #include "Model/NodeVisitor.h" 29 30 namespace TrenchBroom { 31 namespace Model { 32 template <typename P> 33 class CollectMatchingBrushFacesVisitor : public NodeVisitor { 34 private: 35 P m_p; 36 BrushFaceList m_faces; 37 public: m_p(p)38 CollectMatchingBrushFacesVisitor(const P& p = P()) : m_p(p) {} faces()39 const BrushFaceList& faces() const { return m_faces; } 40 private: doVisit(World * world)41 void doVisit(World* world) {} doVisit(Layer * layer)42 void doVisit(Layer* layer) {} doVisit(Group * group)43 void doVisit(Group* group) {} doVisit(Entity * entity)44 void doVisit(Entity* entity) {} doVisit(Brush * brush)45 void doVisit(Brush* brush) { 46 const BrushFaceList& faces = brush->faces(); 47 BrushFaceList::const_iterator it, end; 48 for (it = faces.begin(), end = faces.end(); it != end; ++it) { 49 BrushFace* face = *it; 50 if (m_p(face)) 51 m_faces.push_back(face); 52 } 53 } 54 }; 55 56 typedef CollectMatchingBrushFacesVisitor<BrushFacePredicates::True> CollectBrushFacesVisitor; 57 } 58 } 59 60 #endif /* defined(TrenchBroom_CollectMatchingBrushFacesVisitor) */ 61