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_CollectMatchingIssuesVisitor
21 #define TrenchBroom_CollectMatchingIssuesVisitor
22 
23 #include "Model/NodeVisitor.h"
24 #include "Model/Brush.h"
25 #include "Model/Entity.h"
26 #include "Model/Group.h"
27 #include "Model/Layer.h"
28 #include "Model/ModelTypes.h"
29 #include "Model/World.h"
30 
31 namespace TrenchBroom {
32     namespace Model {
33         template <typename P>
34         class CollectMatchingIssuesVisitor : public NodeVisitor {
35         private:
36             const IssueGeneratorList& m_issueGenerators;
37             P m_p;
38             IssueList m_issues;
39         public:
40             CollectMatchingIssuesVisitor(const IssueGeneratorList& issueGenerators, const P& p = P()) :
m_issueGenerators(issueGenerators)41             m_issueGenerators(issueGenerators),
42             m_p(p) {}
43 
issues()44             const IssueList& issues() const {
45                 return m_issues;
46             }
47         private:
doVisit(World * world)48             void doVisit(World* world)   { collectIssues(world);  }
doVisit(Layer * layer)49             void doVisit(Layer* layer)   { collectIssues(layer);  }
doVisit(Group * group)50             void doVisit(Group* group)   { collectIssues(group);  }
doVisit(Entity * entity)51             void doVisit(Entity* entity) { collectIssues(entity); }
doVisit(Brush * brush)52             void doVisit(Brush* brush)   { collectIssues(brush);  }
53 
collectIssues(Node * node)54             void collectIssues(Node* node) {
55                 const IssueList& issues = node->issues(m_issueGenerators);
56                 IssueList::const_iterator it, end;
57                 for (it = issues.begin(), end = issues.end(); it != end; ++it) {
58                     Issue* issue = *it;
59                     if (m_p(issue))
60                         m_issues.push_back(issue);
61                 }
62             }
63         };
64     }
65 }
66 
67 #endif /* defined(TrenchBroom_CollectMatchingIssuesVisitor) */
68