Field3D
|
00001 00002 //----------------------------------------------------------------------------// 00003 00004 /* 00005 * Copyright (c) 2010 Sony Pictures Imageworks Inc 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the 00018 * distribution. Neither the name of Sony Pictures Imageworks nor the 00019 * names of its contributors may be used to endorse or promote 00020 * products derived from this software without specific prior written 00021 * permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00031 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00032 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00034 * OF THE POSSIBILITY OF SUCH DAMAGE. 00035 */ 00036 00037 //----------------------------------------------------------------------------// 00038 00046 //----------------------------------------------------------------------------// 00047 00048 #ifndef _INCLUDED_Field3D_FieldMetadata_H_ 00049 #define _INCLUDED_Field3D_FieldMetadata_H_ 00050 00051 //----------------------------------------------------------------------------// 00052 00053 #include <list> 00054 #include <string> 00055 #include <vector> 00056 #include <map> 00057 00058 #include "Types.h" 00059 00060 //----------------------------------------------------------------------------// 00061 00062 #include "ns.h" 00063 00064 FIELD3D_NAMESPACE_OPEN 00065 00066 //----------------------------------------------------------------------------// 00067 00068 template <class CallBack_T> 00069 class FieldMetadata 00070 { 00071 public: 00072 00073 // Typedefs ------------------------------------------------------------------ 00074 00075 typedef std::map<std::string, std::string> StrMetadata; 00076 typedef std::map<std::string, int> IntMetadata; 00077 typedef std::map<std::string, float> FloatMetadata; 00078 typedef std::map<std::string, V3i> VecIntMetadata; 00079 typedef std::map<std::string, V3f> VecFloatMetadata; 00080 00081 // Ctor, dtor ---------------------------------------------------------------- 00082 00085 00086 FieldMetadata(CallBack_T *owner) 00087 : m_owner(owner) 00088 { } 00089 00090 virtual ~FieldMetadata() {} 00091 00093 00094 // Operators ----------------------------------------------------------------- 00095 00096 void operator = (const FieldMetadata &other) 00097 { 00098 m_vecFloatMetadata = other.m_vecFloatMetadata; 00099 m_floatMetadata = other.m_floatMetadata; 00100 m_vecIntMetadata = other.m_vecIntMetadata; 00101 m_intMetadata = other.m_intMetadata; 00102 m_strMetadata = other.m_strMetadata; 00103 } 00104 00105 // Access to metadata -------------------------------------------------------- 00106 00109 00112 V3f vecFloatMetadata(const std::string &name, const V3f &defaultVal) const; 00113 00116 float floatMetadata(const std::string &name, const float defaultVal) const; 00117 00120 V3i vecIntMetadata(const std::string &name, const V3i &defaultVal) const; 00121 00124 int intMetadata(const std::string &name, const int defaultVal) const; 00125 00128 std::string strMetadata(const std::string &name, 00129 const std::string &defaultVal) const; 00130 00132 const VecFloatMetadata& vecFloatMetadata() const 00133 { return m_vecFloatMetadata; } 00134 00136 const FloatMetadata& floatMetadata() const 00137 { return m_floatMetadata; } 00138 00140 const VecIntMetadata& vecIntMetadata() const 00141 { return m_vecIntMetadata; } 00142 00144 const IntMetadata& intMetadata() const 00145 { return m_intMetadata; } 00146 00148 const StrMetadata& strMetadata() const 00149 { return m_strMetadata; } 00150 00152 void setVecFloatMetadata(const std::string &name, const V3f &val); 00153 00155 void setFloatMetadata(const std::string &name, const float val); 00156 00158 void setVecIntMetadata(const std::string &name, const V3i &val); 00159 00161 void setIntMetadata(const std::string &name, const int val); 00162 00164 void setStrMetadata(const std::string &name, const std::string &val); 00165 00167 00168 private: 00169 00170 // Private member functions -------------------------------------------------- 00171 00172 FieldMetadata(const FieldMetadata &); 00173 00174 // Private data members ------------------------------------------------------ 00175 00177 VecFloatMetadata m_vecFloatMetadata; 00179 FloatMetadata m_floatMetadata; 00181 VecIntMetadata m_vecIntMetadata; 00183 IntMetadata m_intMetadata; 00185 StrMetadata m_strMetadata; 00186 00189 CallBack_T *m_owner; 00190 00191 }; 00192 00193 //----------------------------------------------------------------------------// 00194 // FieldMetadata implementations 00195 //----------------------------------------------------------------------------// 00196 00197 template <class CallBack_T> 00198 void FieldMetadata<CallBack_T>::setVecFloatMetadata(const std::string &name, 00199 const V3f &val) 00200 { 00201 m_vecFloatMetadata[name] = val; 00202 if (m_owner) { 00203 m_owner->metadataHasChanged(name); 00204 } 00205 } 00206 00207 //----------------------------------------------------------------------------// 00208 00209 template <class CallBack_T> 00210 void FieldMetadata<CallBack_T>::setFloatMetadata(const std::string &name, 00211 const float val) 00212 { 00213 m_floatMetadata[name] = val; 00214 if (m_owner) { 00215 m_owner->metadataHasChanged(name); 00216 } 00217 } 00218 00219 //----------------------------------------------------------------------------// 00220 00221 template <class CallBack_T> 00222 void FieldMetadata<CallBack_T>::setVecIntMetadata(const std::string &name, 00223 const V3i &val) 00224 { 00225 m_vecIntMetadata[name] = val; 00226 if (m_owner) { 00227 m_owner->metadataHasChanged(name); 00228 } 00229 } 00230 00231 //----------------------------------------------------------------------------// 00232 00233 template <class CallBack_T> 00234 void FieldMetadata<CallBack_T>::setIntMetadata(const std::string &name, 00235 const int val) 00236 { 00237 m_intMetadata[name] = val; 00238 if (m_owner) { 00239 m_owner->metadataHasChanged(name); 00240 } 00241 } 00242 00243 //----------------------------------------------------------------------------// 00244 00245 template <class CallBack_T> 00246 void FieldMetadata<CallBack_T>::setStrMetadata(const std::string &name, 00247 const std::string &val) 00248 { 00249 m_strMetadata[name] = val; 00250 if (m_owner) { 00251 m_owner->metadataHasChanged(name); 00252 } 00253 } 00254 00255 //----------------------------------------------------------------------------// 00256 00257 template <class CallBack_T> 00258 V3f FieldMetadata<CallBack_T>::vecFloatMetadata(const std::string &name, 00259 const V3f& defaultVal) const 00260 { 00261 V3f retVal = defaultVal; 00262 00263 VecFloatMetadata::const_iterator i = m_vecFloatMetadata.find(name); 00264 if (i != m_vecFloatMetadata.end()) { 00265 retVal = i->second; 00266 } 00267 00268 return retVal; 00269 } 00270 00271 //----------------------------------------------------------------------------// 00272 00273 template <class CallBack_T> 00274 float FieldMetadata<CallBack_T>::floatMetadata(const std::string &name, 00275 const float defaultVal) const 00276 { 00277 float retVal = defaultVal; 00278 00279 FloatMetadata::const_iterator i = m_floatMetadata.find(name); 00280 if (i != m_floatMetadata.end()) { 00281 retVal = i->second; 00282 } 00283 00284 return retVal; 00285 } 00286 00287 //----------------------------------------------------------------------------// 00288 00289 template <class CallBack_T> 00290 V3i FieldMetadata<CallBack_T>::vecIntMetadata(const std::string &name, 00291 const V3i& defaultVal) const 00292 { 00293 V3i retVal = defaultVal; 00294 00295 VecIntMetadata::const_iterator i = m_vecIntMetadata.find(name); 00296 if (i != m_vecIntMetadata.end()) { 00297 retVal = i->second; 00298 } 00299 00300 return retVal; 00301 } 00302 00303 //----------------------------------------------------------------------------// 00304 00305 template <class CallBack_T> 00306 int FieldMetadata<CallBack_T>::intMetadata(const std::string &name, 00307 const int defaultVal) const 00308 { 00309 int retVal = defaultVal; 00310 00311 IntMetadata::const_iterator i = m_intMetadata.find(name); 00312 if (i != m_intMetadata.end()) { 00313 retVal = i->second; 00314 } 00315 00316 return retVal; 00317 } 00318 00319 //----------------------------------------------------------------------------// 00320 00321 template <class CallBack_T> 00322 std::string FieldMetadata<CallBack_T>::strMetadata(const std::string &name, 00323 const std::string &defaultVal) const 00324 { 00325 std::string retVal = defaultVal; 00326 00327 StrMetadata::const_iterator i = m_strMetadata.find(name); 00328 if (i != m_strMetadata.end()) { 00329 retVal = i->second; 00330 } 00331 00332 return retVal; 00333 } 00334 00335 //----------------------------------------------------------------------------// 00336 00337 FIELD3D_NAMESPACE_HEADER_CLOSE 00338 00339 //----------------------------------------------------------------------------// 00340 00341 #endif /* _INCLUDED_Field3D_FieldMetadata_H_ */ 00342