Blender  V2.93
Id.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #ifdef WITH_CXX_GUARDEDALLOC
25 # include "MEM_guardedalloc.h"
26 #endif
27 
28 namespace Freestyle {
29 
33 class Id {
34  public:
35  typedef unsigned id_type;
36 
38  Id()
39  {
40  _first = 0;
41  _second = 0;
42  }
43 
47  Id(id_type id)
48  {
49  _first = id;
50  _second = 0;
51  }
52 
54  Id(id_type ifirst, id_type isecond)
55  {
56  _first = ifirst;
57  _second = isecond;
58  }
59 
61  Id(const Id &iBrother)
62  {
63  _first = iBrother._first;
64  _second = iBrother._second;
65  }
66 
68  Id &operator=(const Id &iBrother)
69  {
70  _first = iBrother._first;
71  _second = iBrother._second;
72  return *this;
73  }
74 
76  id_type getFirst() const
77  {
78  return _first;
79  }
80 
83  {
84  return _second;
85  }
86 
88  void setFirst(id_type first)
89  {
90  _first = first;
91  }
92 
94  void setSecond(id_type second)
95  {
96  _second = second;
97  }
98 
100  bool operator==(const Id &id) const
101  {
102  return ((_first == id._first) && (_second == id._second));
103  }
104 
106  bool operator!=(const Id &id) const
107  {
108  return !((*this) == id);
109  }
110 
112  bool operator<(const Id &id) const
113  {
114  if (_first < id._first) {
115  return true;
116  }
117  if (_first == id._first && _second < id._second) {
118  return true;
119  }
120  return false;
121  }
122 
123  private:
124  id_type _first;
125  id_type _second;
126 
127 #ifdef WITH_CXX_GUARDEDALLOC
128  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Id")
129 #endif
130 };
131 
132 // stream operator
133 inline std::ostream &operator<<(std::ostream &s, const Id &id)
134 {
135  s << "[" << id.getFirst() << ", " << id.getSecond() << "]";
136  return s;
137 }
138 
139 } /* namespace Freestyle */
Read Guarded memory(de)allocation.
void setFirst(id_type first)
Definition: Id.h:88
bool operator<(const Id &id) const
Definition: Id.h:112
unsigned id_type
Definition: Id.h:35
id_type getFirst() const
Definition: Id.h:76
Id(const Id &iBrother)
Definition: Id.h:61
id_type getSecond() const
Definition: Id.h:82
Id & operator=(const Id &iBrother)
Definition: Id.h:68
Id()
Definition: Id.h:38
void setSecond(id_type second)
Definition: Id.h:94
Id(id_type ifirst, id_type isecond)
Definition: Id.h:54
Id(id_type id)
Definition: Id.h:47
bool operator==(const Id &id) const
Definition: Id.h:100
bool operator!=(const Id &id) const
Definition: Id.h:106
inherits from class Rep
Definition: AppCanvas.cpp:32
ostream & operator<<(ostream &out, const StrokeAttribute &iStrokeAttribute)
Definition: StrokeIO.cpp:28