OSGBaseTypeTraits.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *           Copyright (C) 2000-2002,2002 by the OpenSG Forum                *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 #ifndef _OSGBASETYPETRAITS_H_
00040 #define _OSGBASETYPETRAITS_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #ifndef _OSGBASETYPES_H_
00046 #error not for direct use, please include OSGBaseTypes.h instead
00047 #endif
00048 
00049 #include "OSGGL.h"
00050
00051 #include "OSGIOStream.h"
00052
00053 #include <limits>
00054
00055 // The undef's are needed otherwise the numeric_limits won't work (GV)
00056
00057 #if defined(max)
00058 #undef max
00059 #endif
00060 
00061 #if defined(min)
00062 #undef min
00063 #endif
00064 
00065 OSG_BEGIN_NAMESPACE
00066
00067 template <class LookupTypeT>
00068 struct TypeTraits;
00069
00074 struct TypeTraitsBase
00075 {
00076 #ifdef GV_CHECK_CHECK
00077     static const  bool               IsPOD    = true;
00078     static const  MathTypeProperties MathProp = BoolValue;
00079
00080     static const  bool               BitsSet     = true ;
00081     static const  bool               BitsClear   = false;
00082
00083     static        bool              getZeroElement(void)
00084     {
00085         return false;
00086     }
00087
00088     static        bool              getOneElement (void)
00089     {
00090         return true;
00091     }
00092
00093     static        bool              getMax        (void)
00094     {
00095         return true;
00096     }
00097
00098     static        bool              getMin        (void)
00099     {
00100         return false;
00101     }
00102 #endif
00103 };
00104
00109 template <class LookupTypeT>
00110 struct TypeTraitsTemplateBase : public TypeTraitsBase
00111 {
00112     static void putToStream(const LookupTypeT &val,
00113                                   OutStream   &str)
00114     {
00115         str << val;
00116     }
00117
00118 #ifdef OSG_1_COMPAT
00119     static LookupTypeT getFromString(const Char8 *szString)
00120     {
00121         typedef TypeTraits<LookupTypeT> SelfTraits;
00122
00123         return SelfTraits::getFromCString(szString);
00124     }
00125 #endif
00126 };
00127
00128
00133 template <class LookupTypeT>
00134 struct TypeTraits : public TypeTraitsTemplateBase<LookupTypeT>
00135 {
00136     static const bool IsPOD = true;
00137
00138 #ifdef OSG_MICROSOFT_DOTNET_COMPILER_HACKS
00139     typedef LookupTypeT RealReturnType;
00140 #endif
00141 };
00142
00143 #if defined(__hpux)
00144 template <class LookupTypeT>
00145 const bool TypeTraits<LookupTypeT>::IsPOD;
00146 #endif
00147 
00148
00153 template <>
00154 struct TypeTraits<bool> : public TypeTraitsTemplateBase<bool>
00155 {
00156     static const  bool               IsPOD     = true;
00157     static const  MathTypeProperties MathProp  = BoolValue;
00158
00159     static const  bool               BitsSet   = true ;
00160     static const  bool               BitsClear = false;
00161
00162
00163     static        bool               getZeroElement(void)
00164     {
00165         return false;
00166     }
00167
00168     static        bool               getOneElement (void)
00169     {
00170         return true;
00171     }
00172
00173     static        bool               getMax        (void)
00174     {
00175         return true;
00176     }
00177
00178     static        bool               getMin        (void)
00179     {
00180         return false;
00181     }
00182
00183     static bool getFromCString(const Char8 * pData,
00184                                      Char8 *&pDataEnd)
00185     {
00186         if(pData == NULL)
00187             return false;
00188
00189         if(pData[0] == 'T' || pData[0] == 't')
00190         {
00191             ++pDataEnd;
00192
00193             if(pData[1] != 'R' && pData[1] != 'r')
00194             {
00195                 return false;
00196             }
00197
00198             ++pDataEnd;
00199
00200             if(pData[2] != 'U' && pData[2] != 'u')
00201             {
00202                 return false;
00203             }
00204
00205             ++pDataEnd;
00206
00207             if(pData[3] != 'E' && pData[3] != 'e')
00208             {
00209                 return false;
00210             }
00211
00212             ++pDataEnd;
00213
00214             return true;
00215         }
00216
00217         return false;
00218     }
00219
00220     static bool getFromCString(const Char8 *pData)
00221     {
00222         Char8 *pDataEnd;
00223
00224         return getFromCString(pData, pDataEnd);
00225     }
00226
00227 };
00228
00229
00234 template <>
00235 struct TypeTraits<UInt8> : public TypeTraitsTemplateBase<UInt8>
00236 {
00237     typedef       Real32             RealReturnType;
00238
00239
00240     static const  bool               IsPOD     = true;
00241     static const  MathTypeProperties MathProp  = IntValue;
00242
00243     static const  UInt8              BitsSet   = 0xFF;
00244     static const  UInt8              BitsClear = 0x00;
00245
00246
00247     static        UInt8              getZeroElement(void)
00248     {
00249         return 0;
00250     }
00251
00252     static        UInt8              getOneElement (void)
00253     {
00254         return 1;
00255     }
00256
00257     static        UInt8              getMax        (void)
00258     {
00259         return std::numeric_limits<UInt8>::max();
00260     }
00261
00262     static        UInt8              getMin        (void)
00263     {
00264         return std::numeric_limits<UInt8>::min();
00265     }
00266
00267
00268     static Real32      getFraction  (UInt8 val)
00269     {
00270         return (Real32(val) / Real32(getMax()));
00271     };
00272
00273     static UInt8       getPortion   (Real32 val)
00274     {
00275 #ifdef OSG_WIN32_ICL
00276 #pragma warning (disable : 810)
00277 #endif
00278         return UInt8((val * Real32(getMax())));
00279 #ifdef OSG_WIN32_ICL
00280 #pragma warning (default : 810)
00281 #endif
00282     };
00283
00284
00285     static UInt8       getFromCString(const Char8 * pData,
00286                                             Char8 *&pDataEnd)
00287     {
00288         if(pData != NULL)
00289         {
00290             return UInt8(strtoul(pData, &pDataEnd, 0));
00291         }
00292         else
00293         {
00294             return getZeroElement();
00295         }
00296     }
00297
00298     static UInt8       getFromCString(const Char8 *pData)
00299     {
00300         Char8 *pDataEnd;
00301
00302         return getFromCString(pData, pDataEnd);
00303     }
00304
00305     static void putToString  (const UInt8        val,
00306                                     std::string &out)
00307     {
00308         Char8 buffer[10];
00309
00310         sprintf(buffer, "%u", val);
00311
00312         out.append(buffer);
00313     }
00314
00315     static void putToStream(const UInt8     &val,
00316                                   OutStream &str)
00317     {
00318         str << UInt32(val);
00319     }
00320 };
00321
00322
00327 template <>
00328 struct TypeTraits<Int8> : public TypeTraitsTemplateBase<Int8>
00329 {
00330     typedef       Real32             RealReturnType;
00331
00332
00333     static const  bool               IsPOD       = true;
00334     static const  MathTypeProperties MathProp    = IntValue;
00335
00336     static const  Int8               BitsSet     =  -1; //0xFF;
00337     static const  Int8               BitsClear   =  0x00;
00338
00339
00340     static        Int8               getZeroElement(void)
00341     {
00342         return 0;
00343     }
00344
00345     static        Int8               getOneElement (void)
00346     {
00347         return 1;
00348     }
00349
00350     static        Int8               getMin        (void)
00351     {
00352         return std::numeric_limits<Int8>::min();
00353     }
00354
00355     static        Int8               getMax        (void)
00356     {
00357         return std::numeric_limits<Int8>::max();
00358     }
00359
00360
00361     static Real32      getFraction  (Int8   val)
00362     {
00363         return (Real32(val) / Real32(getMax()));
00364     };
00365
00366     static Int8        getPortion   (Real32 val)
00367     {
00368         return Int8(val * Real32(getMax()));
00369     };
00370
00371
00372     static Int8        getFromCString(const Char8 * pData,
00373                                              Char8 *&pDataEnd)
00374     {
00375         if(pData != NULL)
00376         {
00377             return Int8(strtol(pData, &pDataEnd, 0));
00378         }
00379         else
00380         {
00381             return getZeroElement();
00382         }
00383     }
00384
00385     static Int8        getFromCString(const Char8 *pData)
00386     {
00387         Char8 *pDataEnd;
00388
00389         return getFromCString(pData, pDataEnd);
00390     }
00391
00392     static void putToString  (const Int8         val,
00393                                     std::string &out)
00394     {
00395         Char8 buffer[10];
00396
00397         sprintf(buffer, "%i", val);
00398
00399         out.append(buffer);
00400     }
00401
00402     static void putToStream(const Int8      &val,
00403                                   OutStream &str)
00404     {
00405         str << Int32(val);
00406     }
00407 };
00408
00409
00414 template <>
00415 struct TypeTraits<UInt16> : public TypeTraitsTemplateBase<UInt16>
00416 {
00417     typedef       Real32             RealReturnType;
00418
00419
00420     static const  bool               IsPOD       = true;
00421     static const  MathTypeProperties MathProp    = IntValue;
00422
00423     static const  UInt16             BitsSet     = 0xFFFF;
00424     static const  UInt16             BitsClear   = 0x0000;
00425
00426
00427     static        UInt16             getZeroElement(void)
00428     {
00429         return 0;
00430     }
00431
00432     static        UInt16             getOneElement (void)
00433     {
00434         return 1;
00435     }
00436
00437     static        UInt16             getMax        (void)
00438     {
00439         return std::numeric_limits<UInt16>::max();
00440     }
00441
00442     static        UInt16             getMin        (void)
00443     {
00444         return std::numeric_limits<UInt16>::min();
00445     }
00446
00447
00448     static Real32      getFraction  (UInt16 val)
00449     {
00450         return (Real32(val) / Real32(getMax()));
00451     };
00452
00453     static UInt16      getPortion   (Real32 val)
00454     {
00455         return UInt16(val * Real32(getMax()));
00456     };
00457
00458
00459     static UInt16      getFromCString(const Char8 * pData,
00460                                             Char8 *&pDataEnd)
00461     {
00462         if(pData != NULL)
00463         {
00464             return UInt16(strtoul(pData, &pDataEnd, 0));
00465         }
00466         else
00467         {
00468             return getZeroElement();
00469         }
00470     }
00471
00472     static UInt16      getFromCString(const Char8 *pData)
00473     {
00474         Char8 *pDataEnd;
00475
00476         return getFromCString(pData, pDataEnd);
00477     }
00478
00479     static void putToString  (const UInt16       val,
00480                                     std::string &out)
00481     {
00482         Char8 buffer[10];
00483
00484 //      Check WIN32 Version
00485 #ifdef WIN32
00486         sprintf(buffer, "%u", UInt32(val));
00487 #else
00488         sprintf(buffer, "%u", val);
00489 #endif
00490 
00491         out.append(buffer);
00492     }
00493 };
00494
00495
00500 template <>
00501 struct TypeTraits<Int16> : public TypeTraitsTemplateBase<Int16>
00502 {
00503     typedef       Real32             RealReturnType;
00504
00505
00506     static const  bool               IsPOD       = true;
00507     static const  MathTypeProperties MathProp    = IntValue;
00508
00509     static const  Int16              BitsSet     =  -1; //0xFFFF;
00510     static const  Int16              BitsClear   =  0x0000;
00511
00512
00513     static        Int16              getZeroElement(void)
00514     {
00515         return 0;
00516     }
00517
00518     static        Int16              getOneElement (void)
00519     {
00520         return 1;
00521     }
00522
00523     static        Int16              getMax        (void)
00524     {
00525         return std::numeric_limits<Int16>::max();
00526     }
00527
00528     static        Int16              getMin        (void)
00529     {
00530         return std::numeric_limits<Int16>::min();
00531     }
00532
00533
00534     static Real32      getFraction  (Int16  val)
00535     {
00536         return (Real32(val) / Real32(getMax()));
00537     };
00538
00539     static Int16       getPortion   (Real32 val)
00540     {
00541         return Int16(val * Real32(getMax()));
00542     };
00543
00544
00545     static Int16       getFromCString(const Char8 * pData,
00546                                             Char8 *&pDataEnd)
00547     {
00548         if(pData != NULL)
00549         {
00550             return Int16(strtol(pData, &pDataEnd, 0));
00551         }
00552         else
00553         {
00554             return getZeroElement();
00555         }
00556     }
00557
00558     static Int16       getFromCString(const Char8 *pData)
00559     {
00560         Char8 *pDataEnd;
00561
00562         return getFromCString(pData, pDataEnd);
00563     }
00564
00565     static void putToString  (const Int16        val,
00566                                     std::string &out)
00567     {
00568         Char8 buffer[10];
00569
00570         sprintf(buffer, "%i", val);
00571
00572         out.append(buffer);
00573     }
00574 };
00575
00576
00581 template <>
00582 struct TypeTraits<UInt32> : public TypeTraitsTemplateBase<UInt32>
00583 {
00584     typedef       Real32                RealReturnType;
00585
00586
00587     static const  bool               IsPOD       = true;
00588     static const  MathTypeProperties MathProp    = IntValue;
00589
00590     static const  UInt32             BitsSet     = 0xFFFFFFFF;
00591     static const  UInt32             BitsClear   = 0x00000000;
00592
00593
00594     static        UInt32             getZeroElement(void)
00595     {
00596         return 0;
00597     }
00598
00599     static        UInt32             getOneElement (void)
00600     {
00601         return 1;
00602     }
00603
00604     static        UInt32             getMax        (void)
00605     {
00606         return std::numeric_limits<UInt32>::max();
00607     }
00608
00609     static        UInt32             getMin        (void)
00610     {
00611         return std::numeric_limits<UInt32>::min();
00612     }
00613
00614
00615     static Real32      getFraction  (UInt32 val)
00616     {
00617         return (Real32(val) / Real32(getMax()));
00618     };
00619
00620     static UInt32      getPortion   (Real32 val)
00621     {
00622         return UInt32(val * Real32(getMax()));
00623     };
00624
00625
00626     static UInt32      getFromCString(const Char8 * pData,
00627                                             Char8 *&pDataEnd)
00628     {
00629         if(pData != NULL)
00630         {
00631             return UInt32(strtoul(pData, &pDataEnd, 0));
00632         }
00633         else
00634         {
00635             return getZeroElement();
00636         }
00637     }
00638
00639
00640     static UInt32      getFromCString(const Char8 *pData)
00641     {
00642         Char8 *pDataEnd;
00643
00644         return getFromCString(pData, pDataEnd);
00645     }
00646
00647
00648     static void putToString  (const UInt32       val,
00649                                     std::string &out)
00650     {
00651         Char8 buffer[15];
00652
00653         sprintf(buffer, "%u", val);
00654
00655         out.append(buffer);
00656     }
00657 };
00658
00659
00664 template <>
00665 struct TypeTraits<Int32> : public TypeTraitsTemplateBase<Int32>
00666 {
00667     typedef       Real32             RealReturnType;
00668
00669
00670     static const  bool               IsPOD       = true;
00671     static const  MathTypeProperties MathProp    = IntValue;
00672
00673     static const  Int32              BitsSet     =  0xFFFFFFFF;
00674     static const  Int32              BitsClear   =  0x00000000;
00675
00676
00677     static        Int32              getZeroElement(void)
00678     {
00679         return 0;
00680     }
00681
00682     static        Int32              getOneElement (void)
00683     {
00684         return 1;
00685     }
00686
00687     static        Int32              getMax        (void)
00688     {
00689         return std::numeric_limits<Int32>::max();
00690     }
00691
00692     static        Int32              getMin        (void)
00693     {
00694         return std::numeric_limits<Int32>::min();
00695     }
00696
00697
00698     static Real32      getFraction  (Int32  val)
00699     {
00700         return (Real32(val) / Real32(getMax()));
00701     };
00702
00703     static Int32       getPortion   (Real32 val)
00704     {
00705         return Int32(val * Real32(getMax()));
00706     };
00707
00708
00709     static Int32       getFromCString(const Char8 * pData,
00710                                             Char8 *&pDataEnd)
00711     {
00712         if(pData != NULL)
00713         {
00714             return Int32(strtol(pData, &pDataEnd, 0));
00715         }
00716         else
00717         {
00718             return getZeroElement();
00719         }
00720     }
00721
00722     static Int32       getFromCString(const Char8 *pData)
00723     {
00724         Char8 *pDataEnd;
00725
00726         return getFromCString(pData, pDataEnd);
00727     }
00728
00729     static void putToString  (const Int32        val,
00730                                     std::string &out)
00731     {
00732         Char8 buffer[15];
00733
00734         sprintf(buffer, "%i", val);
00735
00736         out.append(buffer);
00737     }
00738 };
00739
00740
00745 template <>
00746 struct TypeTraits<UInt64> : public TypeTraitsTemplateBase<UInt64>
00747 {
00748     typedef       Real32             RealReturnType;
00749
00750
00751     static const  bool               IsPOD       = true;
00752     static const  MathTypeProperties MathProp    = IntValue;
00753
00754     static const  UInt64             BitsSet     = OSGLL(0xFFFFFFFFFFFFFFFF);
00755     static const  UInt64             BitsClear   = OSGLL(0x0000000000000000);
00756
00757     static const  UInt64             Zero        = OSGLL(0x0000000000000000);
00758     static const  UInt64             One         = OSGLL(0x0000000000000001);
00759
00760
00761
00762     static        UInt64             getZeroElement(void)
00763     {
00764         return 0;
00765     }
00766
00767     static        UInt64             getOneElement (void)
00768     {
00769         return 1;
00770     }
00771
00772
00773     static        UInt64             getMax        (void)
00774     {
00775         return std::numeric_limits<UInt64>::max();
00776     }
00777
00778     static        UInt64             getMin        (void)
00779     {
00780         return std::numeric_limits<UInt64>::min();
00781     }
00782
00783
00784     static Real32      getFraction  (UInt64 val)
00785     {
00786         return (Real32(val) / Real32(getMax()));
00787     };
00788
00789     static UInt64      getPortion   (Real32 val)
00790     {
00791         return UInt64(val * Real32(getMax()));
00792     };
00793
00794
00795     static UInt64      getFromCString(const Char8 * pData,
00796                                             Char8 *&pDataEnd)
00797     {
00798         if(pData != NULL)
00799         {
00800 #ifndef WIN32
00801             return UInt64(strtoull(pData, &pDataEnd, 0));
00802 #else
00803             // FIXME
00804             return _atoi64(pData);
00805 #endif
00806         }
00807         else
00808         {
00809             return getZeroElement();
00810         }
00811     }
00812
00813     static UInt64      getFromCString(const Char8 *pData)
00814     {
00815         Char8 *pDataEnd;
00816
00817         return getFromCString(pData, pDataEnd);
00818     }
00819
00820     static void putToString  (const UInt64       val,
00821                                     std::string &out)
00822     {
00823         Char8 buffer[25];
00824 #if defined(__x86_64__) && ! defined(__APPLE__)
00825         sprintf(buffer, "%lu", val);
00826 #else
00827         sprintf(buffer, "%llu", val);
00828 #endif
00829         out.append(buffer);
00830     }
00831 };
00832
00833
00838 template <>
00839 struct TypeTraits<Int64> : public TypeTraitsTemplateBase<Int64>
00840 {
00841     typedef       Real32 RealReturnType;
00842
00843
00844     static const  bool               IsPOD       = true;
00845     static const  MathTypeProperties MathProp    = IntValue;
00846
00847     static const  Int64              BitsSet     =  OSGLL(0xFFFFFFFFFFFFFFFF);
00848     static const  Int64              BitsClear   =  OSGLL(0x0000000000000000);
00849
00850
00851     static        Int64              getZeroElement(void)
00852     {
00853         return 0;
00854     }
00855
00856     static        Int64              getOneElement (void)
00857     {
00858         return 1;
00859     }
00860
00861     static        Int64              getMax        (void)
00862     {
00863         return std::numeric_limits<Int64>::max();
00864     }
00865
00866     static        Int64              getMin        (void)
00867     {
00868         return std::numeric_limits<Int64>::min();
00869     }
00870
00871
00872     static Real32      getFraction  (Int64  val)
00873     {
00874         return (Real32(val) / Real32(getMax()));
00875     };
00876
00877     static Int64       getPortion   (Real32 val)
00878     {
00879         return Int64(val * Real32(getMax()));
00880     };
00881
00882
00883     static Int64       getFromCString(const Char8 * pData,
00884                                             Char8 *&pDataEnd)
00885     {
00886         if(pData != NULL)
00887         {
00888 #ifndef WIN32
00889             return  Int64(strtoll(pData, &pDataEnd, 0));
00890 #else
00891             // FIXME
00892             return _atoi64(pData);
00893 #endif
00894         }
00895         else
00896         {
00897             return getZeroElement();
00898         }
00899     }
00900
00901     static Int64       getFromCString(const Char8 *pData)
00902     {
00903         Char8 *pDataEnd;
00904
00905         return getFromCString(pData, pDataEnd);
00906     }
00907
00908     static void putToString  (const Int64        val,
00909                                     std::string &out)
00910     {
00911         Char8 buffer[25];
00912
00913 #if defined(__x86_64__) && ! defined(__APPLE__)
00914         sprintf(buffer, "%li", val);
00915 #else
00916         sprintf(buffer, "%lli", val);
00917 #endif
00918 
00919         out.append(buffer);
00920     }
00921 };
00922
00927 template <>
00928 struct TypeTraits<Real16> : public TypeTraitsTemplateBase<Real16>
00929 {
00930     typedef       Real16             RealReturnType;
00931
00932
00933     static const  bool               IsPOD       = true;
00934     static const  MathTypeProperties MathProp    = RealValue;
00935
00936     static        Real16             getZeroElement(void)
00937     {
00938         return Real16(0.f);
00939     }
00940
00941     static        Real16             getOneElement (void)
00942     {
00943         return Real16(1.f);
00944     }
00945
00946     static        Real16             getMax        (void)
00947     {
00948         return  REAL16_MAX;
00949     }
00950
00951     static        Real16             getMin        (void)
00952     {
00953         return -REAL16_MAX;
00954     }
00955
00956
00957     static Real16 getFraction     (Real16 rVal) { return rVal; };
00958     static Real16 getPortion      (Real16 rVal) { return rVal; };
00959
00960
00961     static Real16 getFromCString   (const Char8 *szString,
00962                                           Char8 *&pDataEnd)
00963     {
00964         if(szString != NULL)
00965         {
00966 #if defined(__sgi) || defined(WIN32) || defined(__sun)
00967             return Real16(Real32(atof  (szString)));
00968 #else
00969             return Real16(Real32(strtof(szString, &pDataEnd)));
00970 #endif
00971         }
00972         else
00973         {
00974             return getZeroElement();
00975         }
00976     }
00977
00978     static Real16 getFromCString   (const Char8 *pData)
00979     {
00980         Char8 *pDataEnd;
00981
00982         return getFromCString(pData, pDataEnd);
00983     }
00984
00985     static void putToString(const Real16       val,
00986                                   std::string &out)
00987     {
00988         Char8 buffer[20];
00989
00990         sprintf(buffer, "%e", Real32(val));
00991
00992         out.append(buffer);
00993     }
00994 };
00995
00996
01001 template <>
01002 struct TypeTraits<Real32> : public TypeTraitsTemplateBase<Real32>
01003 {
01004     typedef       Real32             RealReturnType;
01005
01006
01007     static const  bool               IsPOD       = true;
01008     static const  MathTypeProperties MathProp    = RealValue;
01009
01010     static        Real32             ZeroEps(void)
01011     {
01012         return 1E-30f;
01013     }
01014
01015     static        Real32             getZeroElement(void)
01016     {
01017         return 0.f;
01018     }
01019
01020     static        Real32             getOneElement (void)
01021     {
01022         return 1.f;
01023     }
01024
01025     static        Real32             getMax        (void)
01026     {
01027         return  FLT_MAX;
01028     }
01029
01030     static        Real32             getMin        (void)
01031     {
01032         return -FLT_MAX;
01033     }
01034
01035
01036     static Real32 getFraction     (Real32 rVal) { return rVal; };
01037     static Real32 getPortion      (Real32 rVal) { return rVal; };
01038
01039
01040     static Real32 getFromCString   (const Char8 * pData,
01041                                           Char8 *&pDataEnd)
01042     {
01043         if(pData != NULL)
01044         {
01045 #if defined(__sgi) || defined(WIN32) || defined(__sun)
01046             // FIXME
01047             return Real32(atof  (pData));
01048 #else
01049             return Real32(strtof(pData, &pDataEnd));
01050 #endif
01051         }
01052         else
01053         {
01054             return getZeroElement();
01055         }
01056     }
01057
01058     static Real32 getFromCString   (const Char8 *pData)
01059     {
01060         Char8 *pDataEnd;
01061
01062         return getFromCString(pData, pDataEnd);
01063     }
01064
01065     static void putToString(const Real32       val,
01066                                   std::string &out)
01067     {
01068         Char8 buffer[20];
01069
01070         sprintf(buffer, "%e", val);
01071
01072         out.append(buffer);
01073     }
01074 };
01075
01076
01081 template <>
01082 struct TypeTraits<Fixed32> : public TypeTraitsTemplateBase<Fixed32>
01083 {
01084     typedef       Fixed32             RealReturnType;
01085
01086
01087     static const  bool               IsPOD       = true;
01088     static const  MathTypeProperties MathProp    = RealValue;
01089
01090
01091     static        Fixed32            ZeroEps(void)
01092     {
01093         return Fixed32(0.00009f);
01094     }
01095
01096     static        Fixed32             getZeroElement(void)
01097     {
01098         return Fixed32(0.f);
01099     }
01100
01101     static        Fixed32             getOneElement (void)
01102     {
01103         return Fixed32(1.f);
01104     }
01105
01106     static        Fixed32             getMax        (void)
01107     {
01108         return Fixed32(REAL16_MAX);
01109     }
01110
01111     static        Fixed32             getMin        (void)
01112     {
01113         return Fixed32(-REAL16_MAX);
01114     }
01115
01116 #if 0
01117 
01118     static Real32 getFraction     (Real32 rVal) { return rVal; };
01119     static Real32 getPortion      (Real32 rVal) { return rVal; };
01120
01121
01122     static Real32 getFromCString   (const Char8 * pData,
01123                                           Char8 *&pDataEnd)
01124     {
01125         if(pData != NULL)
01126         {
01127 #if defined(__sgi) || defined(WIN32) || defined(__sun)
01128             // FIXME
01129             return Real32(atof  (pData));
01130 #else
01131             return Real32(strtof(pData, &pDataEnd));
01132 #endif
01133         }
01134         else
01135         {
01136             return getZeroElement();
01137         }
01138     }
01139
01140     static Real32 getFromCString   (const Char8 *pData)
01141     {
01142         Char8 *pDataEnd;
01143
01144         return getFromCString(pData, pDataEnd);
01145     }
01146
01147     static void putToString(const Real32       val,
01148                                   std::string &out)
01149     {
01150         Char8 buffer[20];
01151
01152         sprintf(buffer, "%e", val);
01153
01154         out.append(buffer);
01155     }
01156 #endif
01157 
01158
01159     static Fixed32 getFromCString   (const Char8 * pData,
01160                                            Char8 *&OSG_CHECK_ARG(pDataEnd))
01161     {
01162         if(pData != NULL)
01163         {
01164             return getZeroElement();
01165         }
01166         else
01167         {
01168             return getZeroElement();
01169         }
01170     }
01171
01172     static Fixed32 getFromCString   (const Char8 *pData)
01173     {
01174         Char8 *pDataEnd;
01175
01176         return getFromCString(pData, pDataEnd);
01177     }
01178
01179     static void putToString(const Fixed32       OSG_CHECK_ARG(val),
01180                                   std::string & OSG_CHECK_ARG(out))
01181     {
01182 /*
01183         Char8 buffer[20];
01184 
01185         sprintf(buffer, "%e", val);
01186 
01187         out.append(buffer);
01188 */
01189     }
01190 };
01191
01192
01197 template <>
01198 struct TypeTraits<Real64> : public TypeTraitsTemplateBase<Real64>
01199 {
01200     typedef       Real64             RealReturnType;
01201
01202
01203     static const  bool               IsPOD       = true;
01204     static const  MathTypeProperties MathProp    = RealValue;
01205
01206     static        Real64             ZeroEps(void)
01207     {
01208         return 1E-30;
01209     }
01210
01211     static        Real64             getZeroElement(void)
01212     {
01213         return 0.0;
01214     }
01215
01216     static        Real64             getOneElement (void)
01217     {
01218         return 1.0;
01219     }
01220
01221     static        Real64             getMax        (void)
01222     {
01223         return  DBL_MAX;
01224     }
01225
01226     static        Real64             getMin        (void)
01227     {
01228         return -DBL_MAX;
01229     }
01230
01231
01232     static Real64 getFraction     (Real64 rVal) { return rVal; };
01233     static Real64 getPortion      (Real64 rVal) { return rVal; };
01234
01235
01236     static Real64 getFromCString   (const Char8 * pData,
01237                                           Char8 *&pDataEnd)
01238     {
01239         if(pData != NULL)
01240         {
01241             return Real64(strtod(pData, &pDataEnd));
01242         }
01243         else
01244         {
01245             return getZeroElement();
01246         }
01247     }
01248
01249     static Real64 getFromCString   (const Char8 *pData)
01250     {
01251         Char8 *pDataEnd;
01252
01253         return getFromCString(pData, pDataEnd);
01254     }
01255
01256     static void putToString(const Real64       val,
01257                                   std::string &out)
01258     {
01259         Char8 buffer[25];
01260
01261         sprintf(buffer, "%e", val);
01262
01263         out.append(buffer);
01264     }
01265 };
01266
01267
01272 template <>
01273 struct TypeTraits<Real128> : public TypeTraitsTemplateBase<Real128>
01274 {
01275     typedef       Real128             RealReturnType;
01276
01277
01278     static const  bool               IsPOD       = true;
01279     static const  MathTypeProperties MathProp    = RealValue;
01280
01281     static        Real128             getZeroElement(void)
01282     {
01283         return 0.0;
01284     }
01285
01286     static        Real128             getOneElement (void)
01287     {
01288         return 1.0;
01289     }
01290
01291     static        Real128             getMax        (void)
01292     {
01293         return  DBL_MAX;
01294     }
01295
01296     static        Real128             getMin        (void)
01297     {
01298         return -DBL_MAX;
01299     }
01300
01301
01302     static Real128 getFraction     (Real128 rVal) { return rVal; };
01303     static Real128 getPortion      (Real128 rVal) { return rVal; };
01304
01305
01306     static Real128 getFromCString   (const Char8 * pData,
01307                                            Char8 *&pDataEnd)
01308     {
01309         if(pData != NULL)
01310         {
01311 #if defined(WIN32) || defined(__sun)
01312             return Real128(strtod (pData, &pDataEnd));
01313 #else
01314             return Real128(strtold(pData, &pDataEnd));
01315 #endif
01316         }
01317         else
01318         {
01319             return getZeroElement();
01320         }
01321     }
01322
01323     static Real128 getFromCString   (const Char8 *pData)
01324     {
01325         Char8 *pDataEnd;
01326
01327         return getFromCString(pData, pDataEnd);
01328     }
01329
01330     static void putToString(const Real128      val,
01331                                   std::string &out)
01332     {
01333         Char8 buffer[25];
01334
01335         sprintf(buffer, "%Le", val);
01336
01337         out.append(buffer);
01338     }
01339 };
01340
01341
01342 #ifdef SIZE_T_NEQ_UINT32
01343 
01348 #ifdef SIZE_T_64BIT
01349 template <>
01350 struct TypeTraits<size_t> : public TypeTraits<UInt64> {};
01351 #else
01352 template <>
01353 struct TypeTraits<size_t> : public TypeTraits<UInt32> {};
01354 #endif
01355 
01356 #if 0
01357 template <>
01358 struct TypeTraits<size_t> : public TypeTraitsTemplateBase<size_t>
01359 {
01360     typedef       Real32                RealReturnType;
01361
01362
01363     static const  bool               IsPOD       = true;
01364     static const  MathTypeProperties MathProp    = IntValue;
01365
01366     static const  UInt32             BitsSet     = 0xFFFFFFFF;
01367     static const  UInt32             BitsClear   = 0x00000000;
01368
01369
01370     static        size_t             getZeroElement(void)
01371     {
01372         return 0;
01373     }
01374
01375     static        size_t             getOneElement (void)
01376     {
01377         return 1;
01378     }
01379
01380     static        size_t             getMax        (void)
01381     {
01382         return std::numeric_limits<size_t>::max();
01383     }
01384
01385     static        size_t             getMin        (void)
01386     {
01387         return std::numeric_limits<size_t>::min();
01388     }
01389
01390
01391     static size_t      getFromCString(const Char8 * pData,
01392                                             Char8 *&pDataEnd)
01393     {
01394         if(pData != NULL)
01395         {
01396             return size_t(strtoul(pData, &pDataEnd, 0));
01397         }
01398         else
01399         {
01400             return getZeroElement();
01401         }
01402     }
01403
01404
01405     static size_t      getFromCString(const Char8 *pData)
01406     {
01407         Char8 *pDataEnd;
01408
01409         return getFromCString(pData, pDataEnd);
01410     }
01411
01412
01413     static void putToString  (const size_t       val,
01414                                     std::string &out)
01415     {
01416         Char8 buffer[15];
01417
01418         sprintf(buffer, "%u", val);
01419
01420         out.append(buffer);
01421     }
01422 };
01423 #endif
01424 
01425 #endif
01426 
01427
01428 #ifdef OSG_GLENUM_NEQ_UINT32
01429 
01434 template <>
01435 struct TypeTraits<GLenum> : public TypeTraitsTemplateBase<GLenum>
01436 {
01437     typedef       Real32                RealReturnType;
01438
01439
01440     static const  bool               IsPOD       = true;
01441     static const  MathTypeProperties MathProp    = IntValue;
01442
01443     static const  UInt32             BitsSet     = 0xFFFFFFFF;
01444     static const  UInt32             BitsClear   = 0x00000000;
01445
01446
01447     static        GLenum             getZeroElement(void)
01448     {
01449         return 0;
01450     }
01451
01452     static        GLenum             getOneElement (void)
01453     {
01454         return 1;
01455     }
01456
01457     static        GLenum             getMax        (void)
01458     {
01459         return 0xFFFFFFFF;
01460     }
01461
01462     static        GLenum             getMin        (void)
01463     {
01464         return 0x00000000;
01465     }
01466
01467
01468     static GLenum      getFromCString(const Char8 * pData,
01469                                             Char8 *&pDataEnd)
01470     {
01471         if(pData != NULL)
01472         {
01473             return GLenum(strtoul(pData, reinterpret_cast<char**>(pDataEnd), 0));
01474         }
01475         else
01476         {
01477             return getZeroElement();
01478         }
01479     }
01480
01481     static GLenum      getFromCString(const Char8 *pData)
01482     {
01483         Char8 *pDataEnd;
01484
01485         return getFromCString(pData, pDataEnd);
01486     }
01487
01488     static void putToString  (const GLenum       val,
01489                                     std::string &out)
01490     {
01491         Char8 buffer[15];
01492
01493         sprintf(buffer, "%lu", static_cast<unsigned long>(val));
01494
01495         out.append(buffer);
01496     }
01497 };
01498
01499 #endif
01500 
01501 OSG_END_NAMESPACE
01502
01503 #ifndef OSG_DISABLE_DEPRECATED
01504 #define TypeConstants TypeTraits
01505 #define getAllSet()   BitsSet
01506 #endif
01507 
01508 #endif /* _OSGBASETYPETRAITS_H_ */