QUAOAR STUDIO // Mobius API
poly_Handles.h
1 //-----------------------------------------------------------------------------
2 // Created on: 18 September 2018
3 //-----------------------------------------------------------------------------
4 // Copyright (c) 2013-present, Sergey Slyadnev
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Sergey Slyadnev nor the
16 // names of all contributors may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 // DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
23 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //-----------------------------------------------------------------------------
30 
31 #ifndef poly_Handles_HeaderFile
32 #define poly_Handles_HeaderFile
33 
34 // Poly includes
35 #include <mobius/poly.h>
36 
37 #define Mobius_InvalidHandleIndex -1
38 
39 namespace mobius {
40 
41 //-----------------------------------------------------------------------------
42 
49 {
50 public:
51 
55  explicit poly_BaseHandle(const int _idx = Mobius_InvalidHandleIndex) : iIdx(_idx) {}
56 
57 public:
58 
60  int GetIdx() const { return iIdx; }
61 
63  bool IsValid() const { return iIdx >= 0; }
64 
66  void Invalidate() { iIdx = Mobius_InvalidHandleIndex; }
67 
71  bool operator==(const poly_BaseHandle& _rhs) const
72  {
73  return this->iIdx == _rhs.iIdx;
74  }
75 
79  bool operator!=(const poly_BaseHandle& _rhs) const
80  {
81  return this->iIdx != _rhs.iIdx;
82  }
83 
87  bool operator<(const poly_BaseHandle& _rhs) const
88  {
89  return this->iIdx < _rhs.iIdx;
90  }
91 
92 protected:
93 
94  void increment() { ++iIdx; }
95  void decrement() { --iIdx; }
96 
99  void increment(const int amount) { iIdx += amount; }
100 
103  void decrement(const int amount) { iIdx -= amount; }
104 
105 public:
106 
107  int iIdx;
108 
109 };
110 
111 //-----------------------------------------------------------------------------
112 
117 {
121  explicit poly_VertexHandle(const int _idx = Mobius_InvalidHandleIndex) : poly_BaseHandle(_idx) {}
122 };
123 
124 //-----------------------------------------------------------------------------
125 
130 {
134  explicit poly_EdgeHandle(const int _idx = Mobius_InvalidHandleIndex) : poly_BaseHandle(_idx) {}
135 };
136 
137 //-----------------------------------------------------------------------------
138 
143 {
147  explicit poly_TriangleHandle(const int _idx = Mobius_InvalidHandleIndex) : poly_BaseHandle(_idx) {}
148 };
149 
150 //-----------------------------------------------------------------------------
151 
156 {
160  explicit poly_QuadHandle(const int _idx = Mobius_InvalidHandleIndex) : poly_BaseHandle(_idx) {}
161 };
162 
163 }
164 
165 //-----------------------------------------------------------------------------
166 // Hashers
167 //-----------------------------------------------------------------------------
168 
169 // Std includes.
170 #include <functional>
171 
172 namespace std {
173 
175 template <>
176 struct hash<mobius::poly_BaseHandle>
177 {
179  typedef std::size_t result_type;
180 
184  std::size_t operator()(const mobius::poly_BaseHandle& h) const
185  {
186  return h.GetIdx();
187  }
188 };
189 
191 template <>
192 struct hash<mobius::poly_VertexHandle>
193 {
195  typedef std::size_t result_type;
196 
200  std::size_t operator()(const mobius::poly_VertexHandle& h) const
201  {
202  return h.GetIdx();
203  }
204 };
205 
207 template <>
208 struct hash<mobius::poly_EdgeHandle>
209 {
211  typedef std::size_t result_type;
212 
216  std::size_t operator()(const mobius::poly_EdgeHandle& h) const
217  {
218  return h.GetIdx();
219  }
220 };
221 
223 template <>
224 struct hash<mobius::poly_TriangleHandle>
225 {
227  typedef std::size_t result_type;
228 
232  std::size_t operator()(const mobius::poly_TriangleHandle& h) const
233  {
234  return h.GetIdx();
235  }
236 };
237 
239 template <>
240 struct hash<mobius::poly_QuadHandle>
241 {
243  typedef std::size_t result_type;
244 
248  std::size_t operator()(const mobius::poly_QuadHandle& h) const
249  {
250  return h.GetIdx();
251  }
252 };
253 
254 }
255 
256 #endif
mobius::poly_EdgeHandle
Definition: poly_Handles.h:129
mobius
Defines an exception class C1 that inherits an exception class C2.
Definition: bspl_Decompose.h:41
mobius::poly_BaseHandle
Definition: poly_Handles.h:48
std::hash< mobius::poly_EdgeHandle >::operator()
std::size_t operator()(const mobius::poly_EdgeHandle &h) const
Definition: poly_Handles.h:216
mobius::poly_QuadHandle
Definition: poly_Handles.h:155
mobius::poly_BaseHandle::poly_BaseHandle
poly_BaseHandle(const int _idx=Mobius_InvalidHandleIndex)
Definition: poly_Handles.h:55
mobius::poly_BaseHandle::operator<
bool operator<(const poly_BaseHandle &_rhs) const
Definition: poly_Handles.h:87
mobius::poly_BaseHandle::operator==
bool operator==(const poly_BaseHandle &_rhs) const
Definition: poly_Handles.h:71
mobius::poly_TriangleHandle
Definition: poly_Handles.h:142
mobius::poly_VertexHandle::poly_VertexHandle
poly_VertexHandle(const int _idx=Mobius_InvalidHandleIndex)
Definition: poly_Handles.h:121
mobius::poly_TriangleHandle::poly_TriangleHandle
poly_TriangleHandle(const int _idx=Mobius_InvalidHandleIndex)
Definition: poly_Handles.h:147
std::hash< mobius::poly_BaseHandle >::operator()
std::size_t operator()(const mobius::poly_BaseHandle &h) const
Definition: poly_Handles.h:184
mobius::poly_BaseHandle::increment
void increment(const int amount)
Definition: poly_Handles.h:99
mobius::poly_BaseHandle::IsValid
bool IsValid() const
The handle is valid iff the index is not negative.
Definition: poly_Handles.h:63
mobius::poly_BaseHandle::operator!=
bool operator!=(const poly_BaseHandle &_rhs) const
Definition: poly_Handles.h:79
mobius::poly_BaseHandle::GetIdx
int GetIdx() const
Definition: poly_Handles.h:60
mobius::poly_BaseHandle::iIdx
int iIdx
0-based index of the handle.
Definition: poly_Handles.h:107
mobius::poly_EdgeHandle::poly_EdgeHandle
poly_EdgeHandle(const int _idx=Mobius_InvalidHandleIndex)
Definition: poly_Handles.h:134
std::hash< mobius::poly_VertexHandle >::operator()
std::size_t operator()(const mobius::poly_VertexHandle &h) const
Definition: poly_Handles.h:200
std::hash< mobius::poly_QuadHandle >::operator()
std::size_t operator()(const mobius::poly_QuadHandle &h) const
Definition: poly_Handles.h:248
mobius::poly_BaseHandle::Invalidate
void Invalidate()
Invalidates this handle.
Definition: poly_Handles.h:66
std::hash< mobius::poly_TriangleHandle >::operator()
std::size_t operator()(const mobius::poly_TriangleHandle &h) const
Definition: poly_Handles.h:232
mobius::poly_QuadHandle::poly_QuadHandle
poly_QuadHandle(const int _idx=Mobius_InvalidHandleIndex)
Definition: poly_Handles.h:160
mobius::poly_BaseHandle::decrement
void decrement(const int amount)
Definition: poly_Handles.h:103
mobius::poly_VertexHandle
Definition: poly_Handles.h:116