added: travMask to csm viewport
[opensg.git] / Source / Base / Base / OSGBaseTypeTraits.h
blob90648784a726acf0114fc75d7599cc93788c9959
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002,2002 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 _OSGBASETYPETRAITS_H_
40 #define _OSGBASETYPETRAITS_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #ifndef _OSGBASETYPES_H_
46 #error not for direct use, please include OSGBaseTypes.h instead
47 #endif
49 #include "OSGGL.h"
51 #include "OSGIOStream.h"
53 #include <limits>
54 #include <boost/lexical_cast.hpp>
56 // The undef's are needed otherwise the numeric_limits won't work (GV)
58 #if defined(max)
59 #undef max
60 #endif
62 #if defined(min)
63 #undef min
64 #endif
66 OSG_BEGIN_NAMESPACE
68 template <class LookupTypeT>
69 struct TypeTraits;
71 /*! \ingroup GrpBaseBaseBaseTypeTraits
72 \ingroup GrpLibOSGBase
75 struct TypeTraitsBase
77 #ifdef GV_CHECK_CHECK
78 static const bool IsPOD = true;
79 static const MathTypeProperties MathProp = BoolValue;
81 static const bool BitsSet = true ;
82 static const bool BitsClear = false;
84 static bool getZeroElement(void)
86 return false;
89 static bool getOneElement (void)
91 return true;
94 static bool getMax (void)
96 return true;
99 static bool getMin (void)
101 return false;
103 #endif
106 /*! \ingroup GrpBaseBaseBaseTypeTraits
107 \ingroup GrpLibOSGBase
110 template <class LookupTypeT>
111 struct TypeTraitsTemplateBase : public TypeTraitsBase
113 static void putToStream(const LookupTypeT &val,
114 OutStream &str)
116 str << boost::lexical_cast<std::string>(val);
119 #ifdef OSG_1_COMPAT
120 static LookupTypeT getFromString(const Char8 *szString)
122 typedef TypeTraits<LookupTypeT> SelfTraits;
124 return SelfTraits::getFromCString(szString);
126 #endif
130 /*! \ingroup GrpBaseBaseBaseTypeTraits
131 \ingroup GrpLibOSGBase
134 template <class LookupTypeT>
135 struct TypeTraits : public TypeTraitsTemplateBase<LookupTypeT>
137 static const bool IsPOD = true;
139 #ifdef OSG_MICROSOFT_DOTNET_COMPILER_HACKS
140 typedef LookupTypeT RealReturnType;
141 #endif
144 #if defined(__hpux)
145 template <class LookupTypeT>
146 const bool TypeTraits<LookupTypeT>::IsPOD;
147 #endif
150 /*! \ingroup GrpBaseBaseBaseTypeTraits
151 \ingroup GrpLibOSGBase
154 template <>
155 struct TypeTraits<bool> : public TypeTraitsTemplateBase<bool>
157 static const bool IsPOD = true;
158 static const MathTypeProperties MathProp = BoolValue;
160 static const bool BitsSet = true ;
161 static const bool BitsClear = false;
164 static bool getZeroElement(void)
166 return false;
169 static bool getOneElement (void)
171 return true;
174 static bool getMax (void)
176 return true;
179 static bool getMin (void)
181 return false;
184 static bool getFromCString(const Char8 * pData,
185 Char8 *&pDataEnd)
187 if(pData == NULL)
188 return false;
190 if(pData[0] == 'T' || pData[0] == 't')
192 ++pDataEnd;
194 if(pData[1] != 'R' && pData[1] != 'r')
196 return false;
199 ++pDataEnd;
201 if(pData[2] != 'U' && pData[2] != 'u')
203 return false;
206 ++pDataEnd;
208 if(pData[3] != 'E' && pData[3] != 'e')
210 return false;
213 ++pDataEnd;
215 return true;
218 return false;
221 static bool getFromCString(const Char8 *pData)
223 Char8 *pDataEnd;
225 return getFromCString(pData, pDataEnd);
228 static void putToString (const bool &val,
229 std::string &out)
231 if(val == true)
233 out.append("TRUE");
235 else
237 out.append("FALSE");
241 static void putToStream(const bool &val,
242 OutStream &str)
244 if(val == true)
246 str << "TRUE";
248 else
250 str << "FALSE";
257 /*! \ingroup GrpBaseBaseBaseTypeTraits
258 \ingroup GrpLibOSGBase
261 template <>
262 struct TypeTraits<UInt8> : public TypeTraitsTemplateBase<UInt8>
264 typedef Real32 RealReturnType;
267 static const bool IsPOD = true;
268 static const MathTypeProperties MathProp = IntValue;
270 static const UInt8 BitsSet = 0xFF;
271 static const UInt8 BitsClear = 0x00;
274 static UInt8 getDefaultEps(void)
276 return 0;
279 static UInt8 getZeroElement(void)
281 return 0;
284 static UInt8 getOneElement (void)
286 return 1;
289 static UInt8 getMax (void)
291 return std::numeric_limits<UInt8>::max();
294 static UInt8 getMin (void)
296 return std::numeric_limits<UInt8>::min();
300 static Real32 getFraction (UInt8 val)
302 return (Real32(val) / Real32(getMax()));
305 static UInt8 getPortion (Real32 val)
307 #ifdef OSG_WIN32_ICL
308 #pragma warning (disable : 810)
309 #endif
310 return UInt8((val * Real32(getMax())));
311 #ifdef OSG_WIN32_ICL
312 #pragma warning (default : 810)
313 #endif
317 static UInt8 getFromCString(const Char8 * pData,
318 Char8 *&pDataEnd)
320 if(pData != NULL)
322 return UInt8(strtoul(pData, &pDataEnd, 0));
324 else
326 return getZeroElement();
330 static UInt8 getFromCString(const Char8 *pData)
332 Char8 *pDataEnd;
334 return getFromCString(pData, pDataEnd);
337 static void putToString (const UInt8 val,
338 std::string &out)
340 Char8 buffer[10];
342 sprintf(buffer, "%u", val);
344 out.append(buffer);
347 static void putToStream(const UInt8 &val,
348 OutStream &str)
350 str << UInt32(val);
355 /*! \ingroup GrpBaseBaseBaseTypeTraits
356 \ingroup GrpLibOSGBase
359 template <>
360 struct TypeTraits<Int8> : public TypeTraitsTemplateBase<Int8>
362 typedef Real32 RealReturnType;
365 static const bool IsPOD = true;
366 static const MathTypeProperties MathProp = IntValue;
368 static const Int8 BitsSet = -1; //0xFF;
369 static const Int8 BitsClear = 0x00;
372 static Int8 getDefaultEps(void)
374 return 0;
377 static Int8 getZeroElement(void)
379 return 0;
382 static Int8 getOneElement (void)
384 return 1;
387 static Int8 getMin (void)
389 return std::numeric_limits<Int8>::min();
392 static Int8 getMax (void)
394 return std::numeric_limits<Int8>::max();
398 static Real32 getFraction (Int8 val)
400 return (Real32(val) / Real32(getMax()));
403 static Int8 getPortion (Real32 val)
405 return Int8(val * Real32(getMax()));
409 static Int8 getFromCString(const Char8 * pData,
410 Char8 *&pDataEnd)
412 if(pData != NULL)
414 return Int8(strtol(pData, &pDataEnd, 0));
416 else
418 return getZeroElement();
422 static Int8 getFromCString(const Char8 *pData)
424 Char8 *pDataEnd;
426 return getFromCString(pData, pDataEnd);
429 static void putToString (const Int8 val,
430 std::string &out)
432 Char8 buffer[10];
434 sprintf(buffer, "%i", val);
436 out.append(buffer);
439 static void putToStream(const Int8 &val,
440 OutStream &str)
442 str << Int32(val);
447 /*! \ingroup GrpBaseBaseBaseTypeTraits
448 \ingroup GrpLibOSGBase
451 template <>
452 struct TypeTraits<UInt16> : public TypeTraitsTemplateBase<UInt16>
454 typedef Real32 RealReturnType;
457 static const bool IsPOD = true;
458 static const MathTypeProperties MathProp = IntValue;
460 static const UInt16 BitsSet = 0xFFFF;
461 static const UInt16 BitsClear = 0x0000;
464 static UInt16 getDefaultEps(void)
466 return 0;
469 static UInt16 getZeroElement(void)
471 return 0;
474 static UInt16 getOneElement (void)
476 return 1;
479 static UInt16 getMax (void)
481 return std::numeric_limits<UInt16>::max();
484 static UInt16 getMin (void)
486 return std::numeric_limits<UInt16>::min();
490 static Real32 getFraction (UInt16 val)
492 return (Real32(val) / Real32(getMax()));
495 static UInt16 getPortion (Real32 val)
497 return UInt16(val * Real32(getMax()));
501 static UInt16 getFromCString(const Char8 * pData,
502 Char8 *&pDataEnd)
504 if(pData != NULL)
506 return UInt16(strtoul(pData, &pDataEnd, 0));
508 else
510 return getZeroElement();
514 static UInt16 getFromCString(const Char8 *pData)
516 Char8 *pDataEnd;
518 return getFromCString(pData, pDataEnd);
521 static void putToString (const UInt16 val,
522 std::string &out)
524 Char8 buffer[10];
526 // Check WIN32 Version
527 #ifdef WIN32
528 sprintf(buffer, "%u", UInt32(val));
529 #else
530 sprintf(buffer, "%u", val);
531 #endif
533 out.append(buffer);
538 /*! \ingroup GrpBaseBaseBaseTypeTraits
539 \ingroup GrpLibOSGBase
542 template <>
543 struct TypeTraits<Int16> : public TypeTraitsTemplateBase<Int16>
545 typedef Real32 RealReturnType;
548 static const bool IsPOD = true;
549 static const MathTypeProperties MathProp = IntValue;
551 static const Int16 BitsSet = -1; //0xFFFF;
552 static const Int16 BitsClear = 0x0000;
555 static Int16 getDefaultEps(void)
557 return 0;
560 static Int16 getZeroElement(void)
562 return 0;
565 static Int16 getOneElement (void)
567 return 1;
570 static Int16 getMax (void)
572 return std::numeric_limits<Int16>::max();
575 static Int16 getMin (void)
577 return std::numeric_limits<Int16>::min();
581 static Real32 getFraction (Int16 val)
583 return (Real32(val) / Real32(getMax()));
586 static Int16 getPortion (Real32 val)
588 return Int16(val * Real32(getMax()));
592 static Int16 getFromCString(const Char8 * pData,
593 Char8 *&pDataEnd)
595 if(pData != NULL)
597 return Int16(strtol(pData, &pDataEnd, 0));
599 else
601 return getZeroElement();
605 static Int16 getFromCString(const Char8 *pData)
607 Char8 *pDataEnd;
609 return getFromCString(pData, pDataEnd);
612 static void putToString (const Int16 val,
613 std::string &out)
615 Char8 buffer[10];
617 sprintf(buffer, "%i", val);
619 out.append(buffer);
624 /*! \ingroup GrpBaseBaseBaseTypeTraits
625 \ingroup GrpLibOSGBase
628 template <>
629 struct TypeTraits<UInt32> : public TypeTraitsTemplateBase<UInt32>
631 typedef Real32 RealReturnType;
634 static const bool IsPOD = true;
635 static const MathTypeProperties MathProp = IntValue;
637 static const UInt32 BitsSet = 0xFFFFFFFF;
638 static const UInt32 BitsClear = 0x00000000;
641 static UInt32 getDefaultEps(void)
643 return 0;
646 static UInt32 getZeroElement(void)
648 return 0;
651 static UInt32 getOneElement (void)
653 return 1;
656 static UInt32 getMax (void)
658 return std::numeric_limits<UInt32>::max();
661 static UInt32 getMin (void)
663 return std::numeric_limits<UInt32>::min();
667 static Real32 getFraction (UInt32 val)
669 return (Real32(val) / Real32(getMax()));
672 static UInt32 getPortion (Real32 val)
674 return UInt32(val * Real32(getMax()));
678 static UInt32 getFromCString(const Char8 * pData,
679 Char8 *&pDataEnd)
681 if(pData != NULL)
683 return UInt32(strtoul(pData, &pDataEnd, 0));
685 else
687 return getZeroElement();
692 static UInt32 getFromCString(const Char8 *pData)
694 Char8 *pDataEnd;
696 return getFromCString(pData, pDataEnd);
700 static void putToString (const UInt32 val,
701 std::string &out)
703 Char8 buffer[15];
705 sprintf(buffer, "%u", val);
707 out.append(buffer);
712 /*! \ingroup GrpBaseBaseBaseTypeTraits
713 \ingroup GrpLibOSGBase
716 template <>
717 struct TypeTraits<Int32> : public TypeTraitsTemplateBase<Int32>
719 typedef Real32 RealReturnType;
722 static const bool IsPOD = true;
723 static const MathTypeProperties MathProp = IntValue;
725 static const Int32 BitsSet = 0xFFFFFFFF;
726 static const Int32 BitsClear = 0x00000000;
728 static Int32 getDefaultEps(void)
730 return 0;
733 static Int32 getZeroElement(void)
735 return 0;
738 static Int32 getOneElement (void)
740 return 1;
743 static Int32 getMax (void)
745 return std::numeric_limits<Int32>::max();
748 static Int32 getMin (void)
750 return std::numeric_limits<Int32>::min();
754 static Real32 getFraction (Int32 val)
756 return (Real32(val) / Real32(getMax()));
759 static Int32 getPortion (Real32 val)
761 return Int32(val * Real32(getMax()));
765 static Int32 getFromCString(const Char8 * pData,
766 Char8 *&pDataEnd)
768 if(pData != NULL)
770 return Int32(strtol(pData, &pDataEnd, 0));
772 else
774 return getZeroElement();
778 static Int32 getFromCString(const Char8 *pData)
780 Char8 *pDataEnd;
782 return getFromCString(pData, pDataEnd);
785 static void putToString (const Int32 val,
786 std::string &out)
788 Char8 buffer[15];
790 sprintf(buffer, "%i", val);
792 out.append(buffer);
797 /*! \ingroup GrpBaseBaseBaseTypeTraits
798 \ingroup GrpLibOSGBase
801 template <>
802 struct TypeTraits<UInt64> : public TypeTraitsTemplateBase<UInt64>
804 typedef Real32 RealReturnType;
807 static const bool IsPOD = true;
808 static const MathTypeProperties MathProp = IntValue;
810 static const UInt64 BitsSet = OSGLL(0xFFFFFFFFFFFFFFFF);
811 static const UInt64 BitsClear = OSGLL(0x0000000000000000);
813 static const UInt64 Zero = OSGLL(0x0000000000000000);
814 static const UInt64 One = OSGLL(0x0000000000000001);
817 static UInt64 getDefaultEps(void)
819 return 0;
822 static UInt64 getZeroElement(void)
824 return 0;
827 static UInt64 getOneElement (void)
829 return 1;
833 static UInt64 getMax (void)
835 return std::numeric_limits<UInt64>::max();
838 static UInt64 getMin (void)
840 return std::numeric_limits<UInt64>::min();
844 static Real32 getFraction (UInt64 val)
846 return (Real32(val) / Real32(getMax()));
849 static UInt64 getPortion (Real32 val)
851 return UInt64(val * Real32(getMax()));
855 static UInt64 getFromCString(const Char8 * pData,
856 Char8 *&pDataEnd)
858 if(pData != NULL)
860 #ifndef WIN32
861 return UInt64(strtoull(pData, &pDataEnd, 0));
862 #else
863 // FIXME
864 return _atoi64(pData);
865 #endif
867 else
869 return getZeroElement();
873 static UInt64 getFromCString(const Char8 *pData)
875 Char8 *pDataEnd;
877 return getFromCString(pData, pDataEnd);
880 static void putToString (const UInt64 val,
881 std::string &out)
883 Char8 buffer[25];
884 #if defined(__x86_64__) && ! defined(__APPLE__)
885 sprintf(buffer, "%lu", val);
886 #else
887 sprintf(buffer, "%llu", val);
888 #endif
889 out.append(buffer);
894 /*! \ingroup GrpBaseBaseBaseTypeTraits
895 \ingroup GrpLibOSGBase
898 template <>
899 struct TypeTraits<Int64> : public TypeTraitsTemplateBase<Int64>
901 typedef Real32 RealReturnType;
904 static const bool IsPOD = true;
905 static const MathTypeProperties MathProp = IntValue;
907 static const Int64 BitsSet = OSGLL(0xFFFFFFFFFFFFFFFF);
908 static const Int64 BitsClear = OSGLL(0x0000000000000000);
911 static Int64 getDefaultEps(void)
913 return 0;
916 static Int64 getZeroElement(void)
918 return 0;
921 static Int64 getOneElement (void)
923 return 1;
926 static Int64 getMax (void)
928 return std::numeric_limits<Int64>::max();
931 static Int64 getMin (void)
933 return std::numeric_limits<Int64>::min();
937 static Real32 getFraction (Int64 val)
939 return (Real32(val) / Real32(getMax()));
942 static Int64 getPortion (Real32 val)
944 return Int64(val * Real32(getMax()));
948 static Int64 getFromCString(const Char8 * pData,
949 Char8 *&pDataEnd)
951 if(pData != NULL)
953 #ifndef WIN32
954 return Int64(strtoll(pData, &pDataEnd, 0));
955 #else
956 // FIXME
957 return _atoi64(pData);
958 #endif
960 else
962 return getZeroElement();
966 static Int64 getFromCString(const Char8 *pData)
968 Char8 *pDataEnd;
970 return getFromCString(pData, pDataEnd);
973 static void putToString (const Int64 val,
974 std::string &out)
976 Char8 buffer[25];
978 #if defined(__x86_64__) && ! defined(__APPLE__)
979 sprintf(buffer, "%li", val);
980 #else
981 sprintf(buffer, "%lli", val);
982 #endif
984 out.append(buffer);
988 /*! \ingroup GrpBaseBaseBaseTypeTraits
989 \ingroup GrpLibOSGBase
992 template <>
993 struct TypeTraits<Real16> : public TypeTraitsTemplateBase<Real16>
995 typedef Real16 RealReturnType;
998 static const bool IsPOD = true;
999 static const MathTypeProperties MathProp = RealValue;
1001 static Real16 getDefaultEps(void)
1003 return Real16(1E-06f);
1006 static Real16 getZeroElement(void)
1008 return Real16(0.f);
1011 static Real16 getOneElement (void)
1013 return Real16(1.f);
1016 static Real16 getMax (void)
1018 return REAL16_MAX;
1021 static Real16 getMin (void)
1023 return -REAL16_MAX;
1027 static Real16 getFraction (Real16 rVal) { return rVal; };
1028 static Real16 getPortion (Real16 rVal) { return rVal; };
1031 static Real16 getFromCString (const Char8 *szString,
1032 Char8 *&pDataEnd)
1034 if(szString != NULL)
1036 #if defined(__sgi) || defined(WIN32) || defined(__sun)
1037 return Real16(Real32(atof (szString)));
1038 #else
1039 return Real16(Real32(strtof(szString, &pDataEnd)));
1040 #endif
1042 else
1044 return getZeroElement();
1048 static Real16 getFromCString (const Char8 *pData)
1050 Char8 *pDataEnd;
1052 return getFromCString(pData, pDataEnd);
1055 static void putToString(const Real16 val,
1056 std::string &out)
1058 Char8 buffer[20];
1060 sprintf(buffer, "%e", Real32(val));
1062 out.append(buffer);
1067 /*! \ingroup GrpBaseBaseBaseTypeTraits
1068 \ingroup GrpLibOSGBase
1071 template <>
1072 struct TypeTraits<Real32> : public TypeTraitsTemplateBase<Real32>
1074 typedef Real32 RealReturnType;
1077 static const bool IsPOD = true;
1078 static const MathTypeProperties MathProp = RealValue;
1080 static Real32 ZeroEps(void)
1082 return 1E-30f;
1085 static Real32 getDefaultEps(void)
1087 return 1E-06f;
1090 static Real32 getZeroElement(void)
1092 return 0.f;
1095 static Real32 getOneElement (void)
1097 return 1.f;
1100 static Real32 getMax (void)
1102 return std::numeric_limits<float>::max();
1105 static Real32 getMin (void)
1107 return -std::numeric_limits<float>::max();
1111 static Real32 getFraction (Real32 rVal) { return rVal; };
1112 static Real32 getPortion (Real32 rVal) { return rVal; };
1115 static Real32 getFromCString (const Char8 * pData,
1116 Char8 *&pDataEnd)
1118 if(pData != NULL)
1120 #if defined(__sgi) || defined(WIN32) || defined(__sun)
1121 // FIXME
1122 return Real32(atof (pData));
1123 #else
1124 return Real32(strtof(pData, &pDataEnd));
1125 #endif
1127 else
1129 return getZeroElement();
1133 static Real32 getFromCString (const Char8 *pData)
1135 Char8 *pDataEnd;
1137 return getFromCString(pData, pDataEnd);
1140 static void putToString(const Real32 val,
1141 std::string &out)
1143 out.append(boost::lexical_cast<std::string>(val));
1148 /*! \ingroup GrpBaseBaseBaseTypeTraits
1149 \ingroup GrpLibOSGBase
1152 template <>
1153 struct TypeTraits<Fixed32> : public TypeTraitsTemplateBase<Fixed32>
1155 typedef Fixed32 RealReturnType;
1158 static const bool IsPOD = true;
1159 static const MathTypeProperties MathProp = RealValue;
1162 static Fixed32 ZeroEps(void)
1164 return Fixed32(0.00009f);
1167 static Fixed32 getDefaultEps (void)
1169 return Fixed32(1E-06f);
1172 static Fixed32 getZeroElement(void)
1174 return Fixed32(0.f);
1177 static Fixed32 getOneElement (void)
1179 return Fixed32(1.f);
1182 static Fixed32 getMax (void)
1184 return Fixed32(REAL16_MAX);
1187 static Fixed32 getMin (void)
1189 return Fixed32(-REAL16_MAX);
1192 static Fixed32 getFromCString (const Char8 * pData,
1193 Char8 *&OSG_CHECK_ARG(pDataEnd))
1195 // XXX TODO: implement
1197 if(pData != NULL)
1199 return getZeroElement();
1201 else
1203 return getZeroElement();
1207 static Fixed32 getFromCString (const Char8 *pData)
1209 // XXX TODO: implement
1211 Char8 *pDataEnd;
1213 return getFromCString(pData, pDataEnd);
1216 static void putToString(const Fixed32 OSG_CHECK_ARG(val),
1217 std::string & OSG_CHECK_ARG(out))
1219 // XXX TODO: implement
1224 /*! \ingroup GrpBaseBaseBaseTypeTraits
1225 \ingroup GrpLibOSGBase
1228 template <>
1229 struct TypeTraits<Real64> : public TypeTraitsTemplateBase<Real64>
1231 typedef Real64 RealReturnType;
1234 static const bool IsPOD = true;
1235 static const MathTypeProperties MathProp = RealValue;
1237 static Real64 ZeroEps(void)
1239 return 1E-30;
1242 static Real64 getDefaultEps (void)
1244 return 1E-12;
1247 static Real64 getZeroElement(void)
1249 return 0.0;
1252 static Real64 getOneElement (void)
1254 return 1.0;
1257 static Real64 getMax (void)
1259 return std::numeric_limits<double>::max();
1262 static Real64 getMin (void)
1264 return -std::numeric_limits<double>::max();
1268 static Real64 getFraction (Real64 rVal) { return rVal; };
1269 static Real64 getPortion (Real64 rVal) { return rVal; };
1272 static Real64 getFromCString (const Char8 * pData,
1273 Char8 *&pDataEnd)
1275 if(pData != NULL)
1277 return Real64(strtod(pData, &pDataEnd));
1279 else
1281 return getZeroElement();
1285 static Real64 getFromCString (const Char8 *pData)
1287 Char8 *pDataEnd;
1289 return getFromCString(pData, pDataEnd);
1292 static void putToString(const Real64 val,
1293 std::string &out)
1295 out.append(boost::lexical_cast<std::string>(val));
1300 /*! \ingroup GrpBaseBaseBaseTypeTraits
1301 \ingroup GrpLibOSGBase
1304 template <>
1305 struct TypeTraits<Real128> : public TypeTraitsTemplateBase<Real128>
1307 typedef Real128 RealReturnType;
1310 static const bool IsPOD = true;
1311 static const MathTypeProperties MathProp = RealValue;
1313 static Real64 getDefaultEps (void)
1315 return 1E-24;
1318 static Real128 getZeroElement(void)
1320 return 0.0;
1323 static Real128 getOneElement (void)
1325 return 1.0;
1328 static Real128 getMax (void)
1330 return std::numeric_limits<long double>::max();
1333 static Real128 getMin (void)
1335 return -std::numeric_limits<long double>::max();
1339 static Real128 getFraction (Real128 rVal) { return rVal; };
1340 static Real128 getPortion (Real128 rVal) { return rVal; };
1343 static Real128 getFromCString (const Char8 * pData,
1344 Char8 *&pDataEnd)
1346 if(pData != NULL)
1348 #if defined(WIN32) || defined(__sun)
1349 return Real128(strtod (pData, &pDataEnd));
1350 #else
1351 return Real128(strtold(pData, &pDataEnd));
1352 #endif
1354 else
1356 return getZeroElement();
1360 static Real128 getFromCString (const Char8 *pData)
1362 Char8 *pDataEnd;
1364 return getFromCString(pData, pDataEnd);
1367 static void putToString(const Real128 val,
1368 std::string &out)
1370 out.append(boost::lexical_cast<std::string>(val));
1375 #ifdef SIZE_T_NEQ_UINT32
1377 /*! \ingroup GrpBaseBaseBaseTypeTraits
1378 \ingroup GrpLibOSGBase
1381 #ifdef SIZE_T_64BIT
1382 template <>
1383 struct TypeTraits<size_t> : public TypeTraits<UInt64> {};
1384 #else
1385 template <>
1386 struct TypeTraits<size_t> : public TypeTraits<UInt32> {};
1387 #endif
1389 #if 0
1390 template <>
1391 struct TypeTraits<size_t> : public TypeTraitsTemplateBase<size_t>
1393 typedef Real32 RealReturnType;
1396 static const bool IsPOD = true;
1397 static const MathTypeProperties MathProp = IntValue;
1399 static const UInt32 BitsSet = 0xFFFFFFFF;
1400 static const UInt32 BitsClear = 0x00000000;
1403 static size_t getZeroElement(void)
1405 return 0;
1408 static size_t getOneElement (void)
1410 return 1;
1413 static size_t getMax (void)
1415 return std::numeric_limits<size_t>::max();
1418 static size_t getMin (void)
1420 return std::numeric_limits<size_t>::min();
1424 static size_t getFromCString(const Char8 * pData,
1425 Char8 *&pDataEnd)
1427 if(pData != NULL)
1429 return size_t(strtoul(pData, &pDataEnd, 0));
1431 else
1433 return getZeroElement();
1438 static size_t getFromCString(const Char8 *pData)
1440 Char8 *pDataEnd;
1442 return getFromCString(pData, pDataEnd);
1446 static void putToString (const size_t val,
1447 std::string &out)
1449 Char8 buffer[15];
1451 sprintf(buffer, "%u", val);
1453 out.append(buffer);
1456 #endif
1458 #endif
1461 #ifdef OSG_GLENUM_NEQ_UINT32
1463 /*! \ingroup GrpBaseBaseBaseTypeTraits
1464 \ingroup GrpLibOSGBase
1467 template <>
1468 struct TypeTraits<GLenum> : public TypeTraitsTemplateBase<GLenum>
1470 typedef Real32 RealReturnType;
1473 static const bool IsPOD = true;
1474 static const MathTypeProperties MathProp = IntValue;
1476 static const UInt32 BitsSet = 0xFFFFFFFF;
1477 static const UInt32 BitsClear = 0x00000000;
1480 static GLenum getZeroElement(void)
1482 return 0;
1485 static GLenum getOneElement (void)
1487 return 1;
1490 static GLenum getMax (void)
1492 return 0xFFFFFFFF;
1495 static GLenum getMin (void)
1497 return 0x00000000;
1501 static GLenum getFromCString(const Char8 * pData,
1502 Char8 *&pDataEnd)
1504 if(pData != NULL)
1506 return GLenum(strtoul(pData, reinterpret_cast<char**>(pDataEnd), 0));
1508 else
1510 return getZeroElement();
1514 static GLenum getFromCString(const Char8 *pData)
1516 Char8 *pDataEnd;
1518 return getFromCString(pData, pDataEnd);
1521 static void putToString (const GLenum val,
1522 std::string &out)
1524 Char8 buffer[15];
1526 sprintf(buffer, "%lu", static_cast<unsigned long>(val));
1528 out.append(buffer);
1532 #endif
1534 OSG_END_NAMESPACE
1536 #ifndef OSG_DISABLE_DEPRECATED
1537 #define TypeConstants TypeTraits
1538 #define getAllSet() BitsSet
1539 #endif
1541 #endif /* _OSGBASETYPETRAITS_H_ */