Panda3D
eggMorphList.I
1 // Filename: eggMorphList.I
2 // Created by: drose (29Jan99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: EggMorphList::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 template<class MorphType>
23 EggMorphList() {
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: EggMorphList::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 template<class MorphType>
34  _morphs(copy._morphs)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: EggMorphList::Copy Assignment Operator
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 template<class MorphType>
44 INLINE void EggMorphList<MorphType>::
45 operator = (const EggMorphList &copy) {
46  _morphs = copy._morphs;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: EggMorphList::Destructor
51 // Access: Public
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 template<class MorphType>
56 ~EggMorphList() {
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: EggMorphList::operator ==
61 // Access: Public
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 template<class MorphType>
65 INLINE bool EggMorphList<MorphType>::
66 operator == (const EggMorphList<MorphType> &other) const {
67  return (_morphs == other._morphs);
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: EggMorphList::operator !=
72 // Access: Public
73 // Description:
74 ////////////////////////////////////////////////////////////////////
75 template<class MorphType>
76 INLINE bool EggMorphList<MorphType>::
77 operator != (const EggMorphList<MorphType> &other) const {
78  return (_morphs != other._morphs);
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: EggMorphList::operator <
83 // Access: Public
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 template<class MorphType>
87 INLINE bool EggMorphList<MorphType>::
88 operator < (const EggMorphList<MorphType> &other) const {
89  return (_morphs < other._morphs);
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: EggMorphList::compare_to
94 // Access: Public
95 // Description: compare_to() compares a different space than the
96 // operator methods, which only check the morph's name.
97 // compare_to() compares the name and the value as well.
98 ////////////////////////////////////////////////////////////////////
99 template<class MorphType>
101 compare_to(const EggMorphList<MorphType> &other, double threshold) const {
102  if (_morphs.size() != other._morphs.size()) {
103  return (int)_morphs.size() - (int)other._morphs.size();
104  }
105  for (size_t i = 0; i < _morphs.size(); i++) {
106  int compare = _morphs[i].compare_to(other._morphs[i], threshold);
107  if (compare < 0) {
108  return compare;
109  }
110  }
111  return 0;
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: EggMorphList::begin
116 // Access: Public
117 // Description:
118 ////////////////////////////////////////////////////////////////////
119 template<class MorphType>
120 INLINE TYPENAME EggMorphList<MorphType>::iterator EggMorphList<MorphType>::
121 begin() {
122  return _morphs.begin();
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: EggMorphList::begin
127 // Access: Public
128 // Description:
129 ////////////////////////////////////////////////////////////////////
130 template<class MorphType>
131 INLINE TYPENAME EggMorphList<MorphType>::const_iterator EggMorphList<MorphType>::
132 begin() const {
133  return _morphs.begin();
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: EggMorphList::end
138 // Access: Public
139 // Description:
140 ////////////////////////////////////////////////////////////////////
141 template<class MorphType>
142 INLINE TYPENAME EggMorphList<MorphType>::iterator EggMorphList<MorphType>::
143 end() {
144  return _morphs.end();
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: EggMorphList::end
149 // Access: Public
150 // Description:
151 ////////////////////////////////////////////////////////////////////
152 template<class MorphType>
153 INLINE TYPENAME EggMorphList<MorphType>::const_iterator EggMorphList<MorphType>::
154 end() const {
155  return _morphs.end();
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: EggMorphList::size
160 // Access: Public
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 template<class MorphType>
164 INLINE TYPENAME EggMorphList<MorphType>::size_type EggMorphList<MorphType>::
165 size() const {
166  return _morphs.size();
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: EggMorphList::empty
171 // Access: Public
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 template<class MorphType>
175 INLINE bool EggMorphList<MorphType>::
176 empty() const {
177  return _morphs.empty();
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: EggMorphList::insert
182 // Access: Public
183 // Description: This is similar to the insert() interface for sets,
184 // except it does not guarantee that the resulting list
185 // is sorted.
186 //
187 // We have this member function so the EggMorphList
188 // resembles a set. It used to *be* a set, but we
189 // cannot export STL sets from a Windows DLL.
190 ////////////////////////////////////////////////////////////////////
191 template<class MorphType>
192 pair<TYPENAME EggMorphList<MorphType>::iterator, bool> EggMorphList<MorphType>::
193 insert(const MorphType &value) {
194  pair<iterator, bool> result;
195  TYPENAME Morphs::iterator mi;
196  for (mi = _morphs.begin(); mi != _morphs.end(); ++mi) {
197  if ((*mi) == value) {
198  // This value is already present.
199  result.first = mi;
200  result.second = false;
201  return result;
202  }
203  }
204 
205  // This value is not already present; add it to the list.
206  _morphs.push_back(value);
207  result.first = _morphs.begin() + _morphs.size() - 1;
208  result.second = true;
209  return result;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: EggMorphList::clear
214 // Access: Public
215 // Description: Empties the list of morphs.
216 ////////////////////////////////////////////////////////////////////
217 template<class MorphType>
218 INLINE void EggMorphList<MorphType>::
219 clear() {
220  _morphs.clear();
221 }
222 
223 ////////////////////////////////////////////////////////////////////
224 // Function: EggMorphList::write
225 // Access: Public
226 // Description:
227 ////////////////////////////////////////////////////////////////////
228 template<class MorphType>
230 write(ostream &out, int indent_level, const string &tag,
231  int num_dimensions) const {
232  const_iterator i;
233 
234  for (i = begin(); i != end(); ++i) {
235  indent(out, indent_level);
236  i->output(out, tag, num_dimensions);
237  out << "\n";
238  }
239 }
240 
pair< iterator, bool > insert(const MorphType &value)
This is similar to the insert() interface for sets, except it does not guarantee that the resulting l...
Definition: eggMorphList.I:193
void clear()
Empties the list of morphs.
Definition: eggMorphList.I:219
A collection of <Dxyz>&#39;s or <Duv>&#39;s or some such.
Definition: eggMorphList.h:31
int compare_to(const EggMorphList< MorphType > &other, double threshold) const
compare_to() compares a different space than the operator methods, which only check the morph&#39;s name...
Definition: eggMorphList.I:101