Panda3D
|
00001 // Filename: eggMorphList.I 00002 // Created by: drose (29Jan99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: EggMorphList::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 template<class MorphType> 00022 INLINE EggMorphList<MorphType>:: 00023 EggMorphList() { 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: EggMorphList::Copy Constructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 template<class MorphType> 00032 INLINE EggMorphList<MorphType>:: 00033 EggMorphList(const EggMorphList<MorphType> ©) : 00034 _morphs(copy._morphs) 00035 { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: EggMorphList::Copy Assignment Operator 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 template<class MorphType> 00044 INLINE void EggMorphList<MorphType>:: 00045 operator = (const EggMorphList ©) { 00046 _morphs = copy._morphs; 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: EggMorphList::Destructor 00051 // Access: Public 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 template<class MorphType> 00055 INLINE EggMorphList<MorphType>:: 00056 ~EggMorphList() { 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: EggMorphList::operator == 00061 // Access: Public 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 template<class MorphType> 00065 INLINE bool EggMorphList<MorphType>:: 00066 operator == (const EggMorphList<MorphType> &other) const { 00067 return (_morphs == other._morphs); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: EggMorphList::operator != 00072 // Access: Public 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 template<class MorphType> 00076 INLINE bool EggMorphList<MorphType>:: 00077 operator != (const EggMorphList<MorphType> &other) const { 00078 return (_morphs != other._morphs); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: EggMorphList::operator < 00083 // Access: Public 00084 // Description: 00085 //////////////////////////////////////////////////////////////////// 00086 template<class MorphType> 00087 INLINE bool EggMorphList<MorphType>:: 00088 operator < (const EggMorphList<MorphType> &other) const { 00089 return (_morphs < other._morphs); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: EggMorphList::compare_to 00094 // Access: Public 00095 // Description: compare_to() compares a different space than the 00096 // operator methods, which only check the morph's name. 00097 // compare_to() compares the name and the value as well. 00098 //////////////////////////////////////////////////////////////////// 00099 template<class MorphType> 00100 int EggMorphList<MorphType>:: 00101 compare_to(const EggMorphList<MorphType> &other, double threshold) const { 00102 if (_morphs.size() != other._morphs.size()) { 00103 return (int)_morphs.size() - (int)other._morphs.size(); 00104 } 00105 for (size_t i = 0; i < _morphs.size(); i++) { 00106 int compare = _morphs[i].compare_to(other._morphs[i], threshold); 00107 if (compare < 0) { 00108 return compare; 00109 } 00110 } 00111 return 0; 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: EggMorphList::begin 00116 // Access: Public 00117 // Description: 00118 //////////////////////////////////////////////////////////////////// 00119 template<class MorphType> 00120 INLINE TYPENAME EggMorphList<MorphType>::iterator EggMorphList<MorphType>:: 00121 begin() { 00122 return _morphs.begin(); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: EggMorphList::begin 00127 // Access: Public 00128 // Description: 00129 //////////////////////////////////////////////////////////////////// 00130 template<class MorphType> 00131 INLINE TYPENAME EggMorphList<MorphType>::const_iterator EggMorphList<MorphType>:: 00132 begin() const { 00133 return _morphs.begin(); 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: EggMorphList::end 00138 // Access: Public 00139 // Description: 00140 //////////////////////////////////////////////////////////////////// 00141 template<class MorphType> 00142 INLINE TYPENAME EggMorphList<MorphType>::iterator EggMorphList<MorphType>:: 00143 end() { 00144 return _morphs.end(); 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: EggMorphList::end 00149 // Access: Public 00150 // Description: 00151 //////////////////////////////////////////////////////////////////// 00152 template<class MorphType> 00153 INLINE TYPENAME EggMorphList<MorphType>::const_iterator EggMorphList<MorphType>:: 00154 end() const { 00155 return _morphs.end(); 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: EggMorphList::size 00160 // Access: Public 00161 // Description: 00162 //////////////////////////////////////////////////////////////////// 00163 template<class MorphType> 00164 INLINE TYPENAME EggMorphList<MorphType>::size_type EggMorphList<MorphType>:: 00165 size() const { 00166 return _morphs.size(); 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: EggMorphList::empty 00171 // Access: Public 00172 // Description: 00173 //////////////////////////////////////////////////////////////////// 00174 template<class MorphType> 00175 INLINE bool EggMorphList<MorphType>:: 00176 empty() const { 00177 return _morphs.empty(); 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: EggMorphList::insert 00182 // Access: Public 00183 // Description: This is similar to the insert() interface for sets, 00184 // except it does not guarantee that the resulting list 00185 // is sorted. 00186 // 00187 // We have this member function so the EggMorphList 00188 // resembles a set. It used to *be* a set, but we 00189 // cannot export STL sets from a Windows DLL. 00190 //////////////////////////////////////////////////////////////////// 00191 template<class MorphType> 00192 pair<TYPENAME EggMorphList<MorphType>::iterator, bool> EggMorphList<MorphType>:: 00193 insert(const MorphType &value) { 00194 pair<iterator, bool> result; 00195 TYPENAME Morphs::iterator mi; 00196 for (mi = _morphs.begin(); mi != _morphs.end(); ++mi) { 00197 if ((*mi) == value) { 00198 // This value is already present. 00199 result.first = mi; 00200 result.second = false; 00201 return result; 00202 } 00203 } 00204 00205 // This value is not already present; add it to the list. 00206 _morphs.push_back(value); 00207 result.first = _morphs.begin() + _morphs.size() - 1; 00208 result.second = true; 00209 return result; 00210 } 00211 00212 //////////////////////////////////////////////////////////////////// 00213 // Function: EggMorphList::clear 00214 // Access: Public 00215 // Description: Empties the list of morphs. 00216 //////////////////////////////////////////////////////////////////// 00217 template<class MorphType> 00218 INLINE void EggMorphList<MorphType>:: 00219 clear() { 00220 _morphs.clear(); 00221 } 00222 00223 //////////////////////////////////////////////////////////////////// 00224 // Function: EggMorphList::write 00225 // Access: Public 00226 // Description: 00227 //////////////////////////////////////////////////////////////////// 00228 template<class MorphType> 00229 void EggMorphList<MorphType>:: 00230 write(ostream &out, int indent_level, const string &tag, 00231 int num_dimensions) const { 00232 const_iterator i; 00233 00234 for (i = begin(); i != end(); ++i) { 00235 indent(out, indent_level); 00236 i->output(out, tag, num_dimensions); 00237 out << "\n"; 00238 } 00239 } 00240