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