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_BrushFacePredicates
21 #define TrenchBroom_BrushFacePredicates
22 
23 namespace TrenchBroom {
24     namespace Model {
25         class BrushFace;
26 
27         namespace BrushFacePredicates {
28             struct True {
29                 bool operator()(const BrushFace* face) const;
30             };
31 
32             struct False {
33                 bool operator()(const BrushFace* face) const;
34             };
35 
36             template <typename P>
37             class Not {
38             private:
39                 P m_p;
40             public:
Not(const P & p)41                 Not(const P& p) :
42                 m_p(p) {}
43 
operator()44                 bool operator()(const BrushFace* face) const { return !m_p(face);  }
operator()45                 bool operator()(BrushFace* face) const       { return !m_p(face);  }
46             };
47 
48             template <typename P1, typename P2>
49             class And {
50             private:
51                 P1 m_p1;
52                 P2 m_p2;
53             public:
And(const P1 & p1,const P2 & p2)54                 And(const P1& p1, const P2& p2) :
55                 m_p1(p1),
56                 m_p2(p2) {}
57 
operator()58                 bool operator()(const BrushFace* face) const { return m_p1(face) && m_p2(face);  }
operator()59                 bool operator()(BrushFace* face) const       { return m_p1(face) && m_p2(face);  }
60             };
61 
62             template <typename P1, typename P2>
63             class Or {
64             private:
65                 P1 m_p1;
66                 P2 m_p2;
67             public:
Or(const P1 & p1,const P2 & p2)68                 Or(const P1& p1, const P2& p2) :
69                 m_p1(p1),
70                 m_p2(p2) {}
71 
operator()72                 bool operator()(const BrushFace* face) const { return m_p1(face) || m_p2(face);  }
operator()73                 bool operator()(BrushFace* face) const       { return m_p1(face) || m_p2(face);  }
74             };
75         }
76     }
77 }
78 
79 #endif /* defined(TrenchBroom_BrushFacePredicates) */
80