Field3D
FieldMetadata.h
Go to the documentation of this file.
1 
2 //----------------------------------------------------------------------------//
3 
4 /*
5  * Copyright (c) 2010 Sony Pictures Imageworks Inc
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the
18  * distribution. Neither the name of Sony Pictures Imageworks nor the
19  * names of its contributors may be used to endorse or promote
20  * products derived from this software without specific prior written
21  * permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34  * OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 //----------------------------------------------------------------------------//
38 
46 //----------------------------------------------------------------------------//
47 
48 #ifndef _INCLUDED_Field3D_FieldMetadata_H_
49 #define _INCLUDED_Field3D_FieldMetadata_H_
50 
51 //----------------------------------------------------------------------------//
52 
53 #include <list>
54 #include <string>
55 #include <vector>
56 #include <map>
57 
58 #include "Types.h"
59 
60 //----------------------------------------------------------------------------//
61 
62 #include "ns.h"
63 
65 
66 //----------------------------------------------------------------------------//
67 
68 template <class CallBack_T>
70 {
71  public:
72 
73  // Typedefs ------------------------------------------------------------------
74 
75  typedef std::map<std::string, std::string> StrMetadata;
76  typedef std::map<std::string, int> IntMetadata;
77  typedef std::map<std::string, float> FloatMetadata;
78  typedef std::map<std::string, V3i> VecIntMetadata;
79  typedef std::map<std::string, V3f> VecFloatMetadata;
80 
81  // Ctor, dtor ----------------------------------------------------------------
82 
85 
86  FieldMetadata(CallBack_T *owner)
87  : m_owner(owner)
88  { }
89 
90  virtual ~FieldMetadata() {}
91 
93 
94  // Operators -----------------------------------------------------------------
95 
96  void operator = (const FieldMetadata &other)
97  {
103  }
104 
105  // Access to metadata --------------------------------------------------------
106 
109 
112  V3f vecFloatMetadata(const std::string &name, const V3f &defaultVal) const;
113 
116  float floatMetadata(const std::string &name, const float defaultVal) const;
117 
120  V3i vecIntMetadata(const std::string &name, const V3i &defaultVal) const;
121 
124  int intMetadata(const std::string &name, const int defaultVal) const;
125 
128  std::string strMetadata(const std::string &name,
129  const std::string &defaultVal) const;
130 
132  const VecFloatMetadata& vecFloatMetadata() const
133  { return m_vecFloatMetadata; }
134 
136  const FloatMetadata& floatMetadata() const
137  { return m_floatMetadata; }
138 
140  const VecIntMetadata& vecIntMetadata() const
141  { return m_vecIntMetadata; }
142 
144  const IntMetadata& intMetadata() const
145  { return m_intMetadata; }
146 
148  const StrMetadata& strMetadata() const
149  { return m_strMetadata; }
150 
152  void setVecFloatMetadata(const std::string &name, const V3f &val);
153 
155  void setFloatMetadata(const std::string &name, const float val);
156 
158  void setVecIntMetadata(const std::string &name, const V3i &val);
159 
161  void setIntMetadata(const std::string &name, const int val);
162 
164  void setStrMetadata(const std::string &name, const std::string &val);
165 
167 
168  private:
169 
170  // Private member functions --------------------------------------------------
171 
172  FieldMetadata(const FieldMetadata &);
173 
174  // Private data members ------------------------------------------------------
175 
177  VecFloatMetadata m_vecFloatMetadata;
179  FloatMetadata m_floatMetadata;
181  VecIntMetadata m_vecIntMetadata;
183  IntMetadata m_intMetadata;
185  StrMetadata m_strMetadata;
186 
189  CallBack_T *m_owner;
190 
191 };
192 
193 //----------------------------------------------------------------------------//
194 // FieldMetadata implementations
195 //----------------------------------------------------------------------------//
196 
197 template <class CallBack_T>
199  const V3f &val)
200 {
201  m_vecFloatMetadata[name] = val;
202  if (m_owner) {
203  m_owner->metadataHasChanged(name);
204  }
205 }
206 
207 //----------------------------------------------------------------------------//
208 
209 template <class CallBack_T>
210 void FieldMetadata<CallBack_T>::setFloatMetadata(const std::string &name,
211  const float val)
212 {
213  m_floatMetadata[name] = val;
214  if (m_owner) {
215  m_owner->metadataHasChanged(name);
216  }
217 }
218 
219 //----------------------------------------------------------------------------//
220 
221 template <class CallBack_T>
222 void FieldMetadata<CallBack_T>::setVecIntMetadata(const std::string &name,
223  const V3i &val)
224 {
225  m_vecIntMetadata[name] = val;
226  if (m_owner) {
227  m_owner->metadataHasChanged(name);
228  }
229 }
230 
231 //----------------------------------------------------------------------------//
232 
233 template <class CallBack_T>
234 void FieldMetadata<CallBack_T>::setIntMetadata(const std::string &name,
235  const int val)
236 {
237  m_intMetadata[name] = val;
238  if (m_owner) {
239  m_owner->metadataHasChanged(name);
240  }
241 }
242 
243 //----------------------------------------------------------------------------//
244 
245 template <class CallBack_T>
246 void FieldMetadata<CallBack_T>::setStrMetadata(const std::string &name,
247  const std::string &val)
248 {
249  m_strMetadata[name] = val;
250  if (m_owner) {
251  m_owner->metadataHasChanged(name);
252  }
253 }
254 
255 //----------------------------------------------------------------------------//
256 
257 template <class CallBack_T>
259  const V3f& defaultVal) const
260 {
261  V3f retVal = defaultVal;
262 
263  VecFloatMetadata::const_iterator i = m_vecFloatMetadata.find(name);
264  if (i != m_vecFloatMetadata.end()) {
265  retVal = i->second;
266  }
267 
268  return retVal;
269 }
270 
271 //----------------------------------------------------------------------------//
272 
273 template <class CallBack_T>
274 float FieldMetadata<CallBack_T>::floatMetadata(const std::string &name,
275  const float defaultVal) const
276 {
277  float retVal = defaultVal;
278 
279  FloatMetadata::const_iterator i = m_floatMetadata.find(name);
280  if (i != m_floatMetadata.end()) {
281  retVal = i->second;
282  }
283 
284  return retVal;
285 }
286 
287 //----------------------------------------------------------------------------//
288 
289 template <class CallBack_T>
291  const V3i& defaultVal) const
292 {
293  V3i retVal = defaultVal;
294 
295  VecIntMetadata::const_iterator i = m_vecIntMetadata.find(name);
296  if (i != m_vecIntMetadata.end()) {
297  retVal = i->second;
298  }
299 
300  return retVal;
301 }
302 
303 //----------------------------------------------------------------------------//
304 
305 template <class CallBack_T>
306 int FieldMetadata<CallBack_T>::intMetadata(const std::string &name,
307  const int defaultVal) const
308 {
309  int retVal = defaultVal;
310 
311  IntMetadata::const_iterator i = m_intMetadata.find(name);
312  if (i != m_intMetadata.end()) {
313  retVal = i->second;
314  }
315 
316  return retVal;
317 }
318 
319 //----------------------------------------------------------------------------//
320 
321 template <class CallBack_T>
322 std::string FieldMetadata<CallBack_T>::strMetadata(const std::string &name,
323  const std::string &defaultVal) const
324 {
325  std::string retVal = defaultVal;
326 
327  StrMetadata::const_iterator i = m_strMetadata.find(name);
328  if (i != m_strMetadata.end()) {
329  retVal = i->second;
330  }
331 
332  return retVal;
333 }
334 
335 //----------------------------------------------------------------------------//
336 
338 
339 //----------------------------------------------------------------------------//
340 
341 #endif /* _INCLUDED_Field3D_FieldMetadata_H_ */
342 
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
CallBack_T * m_owner
Pointer to owner. It is assumed that this has a lifetime at least as long as the Metadata instance...
virtual ~FieldMetadata()
Definition: FieldMetadata.h:90
std::map< std::string, std::string > StrMetadata
Definition: FieldMetadata.h:75
Contains typedefs for the commonly used types in Field3D.
FloatMetadata m_floatMetadata
Float metadata.
const StrMetadata & strMetadata() const
Read only access to the m_strMetadata dictionary.
std::map< std::string, float > FloatMetadata
Definition: FieldMetadata.h:77
void setFloatMetadata(const std::string &name, const float val)
Set the a float value for the given metadata name.
FieldMetadata(CallBack_T *owner)
Definition: FieldMetadata.h:86
void setVecIntMetadata(const std::string &name, const V3i &val)
Set the a V3i value for the given metadata name.
std::map< std::string, int > IntMetadata
Definition: FieldMetadata.h:76
Imath::V3i V3i
Definition: SpiMathLib.h:71
VecFloatMetadata m_vecFloatMetadata
V3f metadata.
void setVecFloatMetadata(const std::string &name, const V3f &val)
Set the a V3f value for the given metadata name.
StrMetadata m_strMetadata
String metadata.
const VecIntMetadata & vecIntMetadata() const
Read only access to the m_vecIntMetadata dictionary.
void setStrMetadata(const std::string &name, const std::string &val)
Set the a string value for the given metadata name.
const VecFloatMetadata & vecFloatMetadata() const
Read only access to the m_vecFloatMetadata dictionary.
std::map< std::string, V3f > VecFloatMetadata
Definition: FieldMetadata.h:79
void operator=(const FieldMetadata &other)
Definition: FieldMetadata.h:96
const FloatMetadata & floatMetadata() const
Read only access to the m_floatMetadata dictionary.
Imath::V3f V3f
Definition: SpiMathLib.h:73
IntMetadata m_intMetadata
Int metadata.
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
std::map< std::string, V3i > VecIntMetadata
Definition: FieldMetadata.h:78
const IntMetadata & intMetadata() const
Read only access to the m_intMetadata dictionary.
VecIntMetadata m_vecIntMetadata
V3i metadata.