fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / Field / OSGMathFieldTraits.h
blob9b8a7de720e0c6ddccba0fd86032a3c26c447483
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2003 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGMATHFIELDTRAITS_H_
40 #define _OSGMATHFIELDTRAITS_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGFieldTraits.h"
46 #include "OSGDataType.h"
48 #include "OSGMatrix.h"
49 #include "OSGQuaternion.h"
51 OSG_BEGIN_NAMESPACE
53 /*! \ingroup GrpBaseFieldTraits
54 \ingroup GrpLibOSGBase
57 template <>
58 struct FieldTraits<Matrix> : public FieldTraitsTemplateBase<Matrix>
60 private:
62 static DataType _type;
64 public:
66 typedef FieldTraits<Matrix> Self;
68 enum { Convertible = (Self::FromStringConvertible |
69 Self::ToStreamConvertible ) };
71 static OSG_BASE_DLLMAPPING
72 DataType &getType (void);
74 static const Char8 *getSName (void) { return "SFMatrix"; }
75 static const Char8 *getMName (void) { return "MFMatrix"; }
77 static Matrix getDefault (void) { return Matrix(); }
80 static bool getFromCString( Matrix &outVal,
81 const Char8 *&inVal)
83 outVal.setValue(inVal, false);
84 return true;
87 static void putToStream(const Matrix &val,
88 OutStream &outStr)
90 typedef TypeTraits<Matrix::ValueType> TypeTrait;
92 TypeTrait::putToStream((val.getValues())[0], outStr);
93 outStr << " ";
94 TypeTrait::putToStream((val.getValues())[4], outStr);
95 outStr << " ";
96 TypeTrait::putToStream((val.getValues())[8], outStr);
97 outStr << " ";
98 TypeTrait::putToStream((val.getValues())[12], outStr);
100 outStr << " ";
101 TypeTrait::putToStream((val.getValues())[1], outStr);
102 outStr << " ";
103 TypeTrait::putToStream((val.getValues())[5], outStr);
104 outStr << " ";
105 TypeTrait::putToStream((val.getValues())[9], outStr);
106 outStr << " ";
107 TypeTrait::putToStream((val.getValues())[13], outStr);
109 outStr << " ";
110 TypeTrait::putToStream((val.getValues())[2], outStr);
111 outStr << " ";
112 TypeTrait::putToStream((val.getValues())[6], outStr);
113 outStr << " ";
114 TypeTrait::putToStream((val.getValues())[10], outStr);
115 outStr << " ";
116 TypeTrait::putToStream((val.getValues())[14], outStr);
118 outStr << " ";
119 TypeTrait::putToStream((val.getValues())[3], outStr);
120 outStr << " ";
121 TypeTrait::putToStream((val.getValues())[7], outStr);
122 outStr << " ";
123 TypeTrait::putToStream((val.getValues())[11], outStr);
124 outStr << " ";
125 TypeTrait::putToStream((val.getValues())[15], outStr);
128 static SizeT getBinSize (const Matrix &)
130 return sizeof(Real32) * 16;
133 static SizeT getBinSize (const Matrix *,
134 SizeT uiNumObjects)
136 return sizeof(Real32) * 16 * uiNumObjects;
139 static void copyToBin ( BinaryDataHandler &pMem,
140 const Matrix &oObject)
142 pMem.putValues(&oObject[0][0], 16);
146 static void copyFromBin( BinaryDataHandler &pMem,
147 Matrix &oObject)
149 pMem.getValues(&oObject[0][0], 16);
152 static void copyToBin ( BinaryDataHandler &pMem,
153 const Matrix *pObjectStore,
154 SizeT uiNumObjects)
156 pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
159 static void copyFromBin ( BinaryDataHandler &pMem,
160 Matrix *pObjectStore,
161 SizeT uiNumObjects)
163 pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
169 /*! \ingroup GrpBaseFieldTraits
170 \ingroup GrpLibOSGBase
173 template <>
174 struct FieldTraits<Matrix4d> : public FieldTraitsTemplateBase<Matrix4d>
176 private:
178 static DataType _type;
180 public:
182 typedef FieldTraits<Matrix4d> Self;
184 enum { Convertible = (Self::FromStringConvertible |
185 Self::ToStreamConvertible ) };
187 static OSG_BASE_DLLMAPPING
188 DataType &getType (void);
190 static const Char8 *getSName (void) { return "SFMatrix4d"; }
191 static const Char8 *getMName (void) { return "MFMatrix4d"; }
193 static Matrix4d getDefault (void) { return Matrix4d(); }
195 static bool getFromCString( Matrix4d &outVal,
196 const Char8 *&inVal)
198 outVal.setValue(inVal, false);
199 return true;
202 static void putToStream (const Matrix4d &val,
203 OutStream &outStr)
205 typedef TypeTraits<Matrix4d::ValueType> TypeTrait;
207 TypeTrait::putToStream((val.getValues())[0], outStr);
208 outStr << " ";
209 TypeTrait::putToStream((val.getValues())[4], outStr);
210 outStr << " ";
211 TypeTrait::putToStream((val.getValues())[8], outStr);
212 outStr << " ";
213 TypeTrait::putToStream((val.getValues())[12], outStr);
215 outStr << " ";
216 TypeTrait::putToStream((val.getValues())[1], outStr);
217 outStr << " ";
218 TypeTrait::putToStream((val.getValues())[5], outStr);
219 outStr << " ";
220 TypeTrait::putToStream((val.getValues())[9], outStr);
221 outStr << " ";
222 TypeTrait::putToStream((val.getValues())[13], outStr);
224 outStr << " ";
225 TypeTrait::putToStream((val.getValues())[2], outStr);
226 outStr << " ";
227 TypeTrait::putToStream((val.getValues())[6], outStr);
228 outStr << " ";
229 TypeTrait::putToStream((val.getValues())[10], outStr);
230 outStr << " ";
231 TypeTrait::putToStream((val.getValues())[14], outStr);
233 outStr << " ";
234 TypeTrait::putToStream((val.getValues())[3], outStr);
235 outStr << " ";
236 TypeTrait::putToStream((val.getValues())[7], outStr);
237 outStr << " ";
238 TypeTrait::putToStream((val.getValues())[11], outStr);
239 outStr << " ";
240 TypeTrait::putToStream((val.getValues())[15], outStr);
243 static SizeT getBinSize (const Matrix4d &)
245 return sizeof(Real64) * 16;
248 static SizeT getBinSize (const Matrix4d *,
249 SizeT uiNumObjects)
251 return sizeof(Real64) * 16 * uiNumObjects;
254 static void copyToBin ( BinaryDataHandler &pMem,
255 const Matrix4d &oObject)
257 pMem.putValues(&oObject[0][0], 16);
261 static void copyFromBin( BinaryDataHandler &pMem,
262 Matrix4d &oObject)
264 pMem.getValues(&oObject[0][0], 16);
267 static void copyToBin ( BinaryDataHandler &pMem,
268 const Matrix4d *pObjectStore,
269 SizeT uiNumObjects)
271 pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
274 static void copyFromBin( BinaryDataHandler &pMem,
275 Matrix4d *pObjectStore,
276 SizeT uiNumObjects)
278 pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
284 /*! \ingroup GrpBaseFieldTraits
285 \ingroup GrpLibOSGBase
288 template <>
289 struct FieldTraits<Matrix4fx> : public FieldTraitsTemplateBase<Matrix4fx>
291 private:
293 static DataType _type;
295 public:
297 typedef FieldTraits<Matrix4fx> Self;
299 enum { Convertible = Self::NotConvertible };
301 static OSG_BASE_DLLMAPPING
302 DataType &getType (void);
304 static const Char8 *getSName (void) { return "SFMatrix4fx"; }
305 static const Char8 *getMName (void) { return "MFMatrix4fx"; }
307 static Matrix4fx getDefault (void) { return Matrix4fx(); }
310 static bool getFromString( Matrix4fx &outVal,
311 const Char8 *&inVal)
313 outVal.setValue(inVal, false);
314 return true;
317 static SizeT getBinSize (const Matrix4fx &)
319 return sizeof(Fixed32) * 16;
322 static SizeT getBinSize (const Matrix4fx *,
323 SizeT uiNumObjects)
325 return sizeof(Fixed32) * 16 * uiNumObjects;
328 static void copyToBin ( BinaryDataHandler &pMem,
329 const Matrix4fx &oObject)
331 pMem.putValues(&oObject[0][0], 16);
335 static void copyFromBin( BinaryDataHandler &pMem,
336 Matrix4fx &oObject)
338 pMem.getValues(&oObject[0][0], 16);
341 static void copyToBin( BinaryDataHandler &pMem,
342 const Matrix4fx *pObjectStore,
343 SizeT uiNumObjects)
345 pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
348 static void copyFromBin( BinaryDataHandler &pMem,
349 Matrix4fx *pObjectStore,
350 SizeT uiNumObjects)
352 pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
358 /*! \ingroup GrpBaseFieldTraits
361 template <>
362 struct FieldTraits<Quaternion> : public FieldTraitsVec4TemplateBase<Quaternion>
364 private:
366 static DataType _type;
368 public:
370 typedef FieldTraits<Quaternion> Self;
372 enum { Convertible = (Self::FromStringConvertible |
373 Self::ToStreamConvertible ) };
375 static OSG_BASE_DLLMAPPING
376 DataType &getType (void);
378 static const Char8 *getSName (void) { return "SFQuaternion"; }
379 static const Char8 *getMName (void) { return "MFQuaternion"; }
381 static Quaternion getDefault (void) { return Quaternion(); }
383 static bool getFromCString( Quaternion &outVal,
384 const Char8 *&inVal)
386 // VRML requires axis and angle in radians
387 outVal.setValueAsAxisRad(inVal);
389 return true;
395 /*! \ingroup GrpBaseFieldTraits
396 \ingroup GrpLibOSGBase
399 template <>
400 struct FieldTraits<Quaternionfx> :
401 public FieldTraitsVec4TemplateBase<Quaternionfx>
403 private:
405 static DataType _type;
407 public:
409 typedef FieldTraits<Quaternionfx> Self;
411 enum { Convertible = Self::ToStreamConvertible };
413 static OSG_BASE_DLLMAPPING
414 DataType &getType (void);
416 static const Char8 *getSName (void) { return "SFQuaternionfx"; }
417 static const Char8 *getMName (void) { return "MFQuaternionfx"; }
419 static Quaternionfx getDefault (void) { return Quaternionfx(); }
423 OSG_END_NAMESPACE
425 #endif /* _OSGMATHFIELDTRAITS_H_ */