Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGFieldDataType.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-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 
00040 #ifndef _OSG_FIELDDATATYPE_H_
00041 #define _OSG_FIELDDATATYPE_H_
00042 
00043 #include <OSGBase.h>
00044 #include <OSGBaseTypes.h>
00045 #include <OSGBaseFunctions.h>
00046 #include <OSGDataType.h>
00047 #include <OSGBinaryDataHandler.h>
00048 
00049 OSG_BEGIN_NAMESPACE
00050 
00051 #if !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00052 
00053 #ifdef OSG_DOC_FILES_IN_MODULE
00054 
00058 #endif
00059 
00060 
00063 #if !defined(OSG_DOC_DEV_TRAITS)
00064 
00065 #endif
00066 
00067 struct FieldTraits
00068 {
00069     enum 
00070     {
00071         ToStringConvertable   = 0x01,
00072         FromStringConvertable = 0x02
00073     };
00074 
00075     static const Char8 *getPName(void) { return "Field"; }
00076 };
00077 
00078 struct InvalidTrait 
00079 {
00080 };
00081 
00083 #if !defined(OSG_DOC_DEV_TRAITS)
00084 
00085 #endif
00086 
00087 template<class FieldTypeT>
00088 struct FieldDataTraits;
00089 
00091 #if !defined(OSG_DOC_DEV_TRAITS)
00092 
00093 #endif
00094 
00095 template<class FieldTypeT>
00096 struct FieldDataTraits1;
00097 
00099 #if !defined(OSG_DOC_DEV_TRAITS)
00100 
00101 #endif
00102 
00103 template<class FieldTypeT>
00104 struct FieldDataTraits2;
00105 
00107 #if !defined(OSG_DOC_DEV_TRAITS)
00108 
00109 #endif
00110 
00111 template<class FieldTypeT>
00112 struct FieldTraitsRecurseBase : public FieldTraits
00113 {
00114     enum              { bHasParent = 0x00 };
00115 
00116 #ifndef __hpux
00117     static const UInt32 uiTest = TypeTraits<FieldTypeT>::IsPOD == true;
00118 
00119     typedef typename 
00120     osgIF<uiTest == 1, 
00121           const FieldTypeT  , 
00122           const FieldTypeT & >::_IRet  ArgumentType;
00123 #else
00124     typedef typename 
00125     osgIF<TypeTraits<FieldTypeT>::IsPOD, 
00126           const FieldTypeT  , 
00127           const FieldTypeT & >::_IRet  ArgumentType;
00128 #endif
00129 
00130     static       UInt32    getBinSize (const FieldTypeT &oObject)
00131     {
00132         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00133 
00134         std::string value;
00135 
00136         MappedTrait::putToString(oObject, value);
00137 
00138         return value.length() + 1 + sizeof(UInt32);
00139     }
00140 
00141     static       UInt32    getBinSize (const FieldTypeT    *pObjectStore,
00142                                              UInt32         uiNumObjects)
00143     {
00144         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00145 
00146         UInt32 size = 0;
00147 
00148         for(UInt32 i = 0; i < uiNumObjects; ++i)
00149         {
00150             size += MappedTrait::getBinSize(pObjectStore[i]);
00151         }
00152 
00153         return size;
00154     }
00155 
00156     static void copyToBin(      BinaryDataHandler   &pMem, 
00157                           const FieldTypeT          &oObject)
00158     {
00159         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00160         
00161         std::string value;
00162 
00163         MappedTrait::putToString(oObject, value);
00164 
00165         pMem.putValue(value);
00166     }
00167 
00168 
00169     static void copyToBin(      BinaryDataHandler &pMem, 
00170                           const FieldTypeT        *pObjectStore,
00171                                 UInt32             uiNumObjects)
00172     {
00173         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00174 
00175         // defaut: copy each element
00176         for(UInt32 i = 0; i < uiNumObjects; ++i)
00177         {
00178             MappedTrait::copyToBin(pMem, pObjectStore[i]);
00179         }
00180     }
00181 
00182     static void copyFromBin(BinaryDataHandler &pMem, 
00183                             FieldTypeT        &oObject)
00184     {
00185         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00186 
00187         const Char8 *c = NULL;
00188 
00189         std::string value;
00190 
00191         pMem.getValue(value);
00192         c = value.c_str();
00193         MappedTrait::getFromString(oObject, c);
00194     }
00195 
00196     static void copyFromBin(BinaryDataHandler &pMem, 
00197                             FieldTypeT        *pObjectStore,
00198                             UInt32             uiNumObjects)
00199     {
00200         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00201 
00202         // defaut: copy each element
00203         for(UInt32 i = 0; i < uiNumObjects; ++i)
00204         {
00205             MappedTrait::copyFromBin(pMem, pObjectStore[i]);
00206         }
00207     }
00208 
00209     static bool getFromString(      FieldTypeT &outVal,
00210                               const Char8      *inVal  )
00211     {
00212         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00213 
00214         return MappedTrait::getFromString(outVal, inVal);
00215     }
00216 
00217     static void putToString  (const FieldTypeT  &inVal,
00218                                     std::string &outStr)
00219     {
00220         typedef FieldDataTraits<FieldTypeT> MappedTrait;
00221 
00222         MappedTrait::putToString(inVal, outStr);
00223     }
00224 };
00225 
00226 #if defined(__hpuxX)
00227 template <class FieldTypeT> inline
00228 const UInt32 FieldTraitsRecurseBase<FieldTypeT>::uiTest;
00229 #endif
00230 
00232 #if !defined(OSG_DOC_DEV_TRAITS)
00233 
00234 #endif
00235 
00236 template<class FieldTypeT>
00237 struct FieldTraitsRecurseBase1 : public FieldTraits
00238 {
00239     enum              { bHasParent = 0x00 };
00240 
00241 #ifndef __hpux
00242     static const UInt32 uiTest = TypeTraits<FieldTypeT>::IsPOD == true;
00243 
00244     typedef typename 
00245     osgIF<uiTest == 1, 
00246           const FieldTypeT  , 
00247           const FieldTypeT & >::_IRet  ArgumentType;
00248 #else
00249     typedef typename 
00250     osgIF<TypeTraits<FieldTypeT>::IsPOD, 
00251           const FieldTypeT  , 
00252           const FieldTypeT & >::_IRet  ArgumentType;
00253 #endif
00254 
00255     static       UInt32    getBinSize (const FieldTypeT &oObject)
00256     {
00257         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00258 
00259         std::string value;
00260 
00261         MappedTrait::putToString(oObject, value);
00262 
00263         return value.length() + 1 + sizeof(UInt32);
00264     }
00265 
00266     static       UInt32    getBinSize (const FieldTypeT    *pObjectStore,
00267                                              UInt32         uiNumObjects)
00268     {
00269         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00270 
00271         UInt32 size = 0;
00272 
00273         for(UInt32 i = 0; i < uiNumObjects; ++i)
00274         {
00275             size += MappedTrait::getBinSize(pObjectStore[i]);
00276         }
00277 
00278         return size;
00279     }
00280 
00281     static void copyToBin(      BinaryDataHandler   &pMem, 
00282                           const FieldTypeT          &oObject)
00283     {
00284         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00285         
00286         std::string value;
00287 
00288         MappedTrait::putToString(oObject, value);
00289 
00290         pMem.putValue(value);
00291     }
00292 
00293 
00294     static void copyToBin(      BinaryDataHandler &pMem, 
00295                           const FieldTypeT        *pObjectStore,
00296                                 UInt32             uiNumObjects)
00297     {
00298         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00299 
00300         // defaut: copy each element
00301         for(UInt32 i = 0; i < uiNumObjects; ++i)
00302         {
00303             MappedTrait::copyToBin(pMem, pObjectStore[i]);
00304         }
00305     }
00306 
00307     static void copyFromBin(BinaryDataHandler &pMem, 
00308                             FieldTypeT        &oObject)
00309     {
00310         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00311 
00312         const Char8 *c = NULL;
00313 
00314         std::string value;
00315 
00316         pMem.getValue(value);
00317         c = value.c_str();
00318         MappedTrait::getFromString(oObject, c);
00319     }
00320 
00321     static void copyFromBin(BinaryDataHandler &pMem, 
00322                             FieldTypeT        *pObjectStore,
00323                             UInt32             uiNumObjects)
00324     {
00325         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00326 
00327         // defaut: copy each element
00328         for(UInt32 i = 0; i < uiNumObjects; ++i)
00329         {
00330             MappedTrait::copyFromBin(pMem, pObjectStore[i]);
00331         }
00332     }
00333 
00334     static bool getFromString(      FieldTypeT &outVal,
00335                               const Char8      *inVal  )
00336     {
00337         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00338 
00339         return MappedTrait::getFromString(outVal, inVal);
00340     }
00341 
00342     static void putToString  (const FieldTypeT  &inVal,
00343                                     std::string &outStr)
00344     {
00345         typedef FieldDataTraits1<FieldTypeT> MappedTrait;
00346 
00347         MappedTrait::putToString(inVal, outStr);
00348     }
00349 };
00350 
00351 #if defined(__hpuxX)
00352 template <class FieldTypeT> inline
00353 const UInt32 FieldTraitsRecurseBase1<FieldTypeT>::uiTest;
00354 #endif
00355 
00357 #if !defined(OSG_DOC_DEV_TRAITS)
00358 
00359 #endif
00360 
00361 template <class FieldTypeT>
00362 struct FieldTraitsIntegralRecurseMapper : 
00363     public FieldTraitsRecurseBase<FieldTypeT>
00364 {
00365     static UInt32 getBinSize(const FieldTypeT &)
00366     {
00367         return sizeof(FieldTypeT);
00368     }
00369 
00370     static UInt32 getBinSize(const FieldTypeT   *,
00371                                    UInt32        uiNumObjects)
00372     {
00373         return sizeof(FieldTypeT) * uiNumObjects;
00374     }
00375 
00376     static void copyToBin(      BinaryDataHandler &pMem, 
00377                           const FieldTypeT        &oObject)
00378     {
00379         pMem.putValue(oObject);
00380     }
00381 
00382     static void copyToBin(      BinaryDataHandler &pMem, 
00383                           const FieldTypeT        *pObjectStore,
00384                                 UInt32             uiNumObjects)
00385     {
00386         pMem.putValues(&pObjectStore[0], uiNumObjects);
00387     }
00388 
00389     static void copyFromBin(BinaryDataHandler &pMem, 
00390                             FieldTypeT        &oObject)
00391     {
00392         pMem.getValue(oObject);
00393     }
00394 
00395     static void copyFromBin(BinaryDataHandler &pMem, 
00396                             FieldTypeT        *pObjectStore,
00397                             UInt32             uiNumObjects)
00398     {
00399         pMem.getValues(&pObjectStore[0], uiNumObjects);
00400     }
00401 };
00402 
00403 
00405 #if !defined(OSG_DOC_DEV_TRAITS)
00406 
00407 #endif
00408 
00409 template <class FieldTypeT, bool bTypeHasParent>
00410 struct FieldTraitsRecurseMapper : public FieldTraitsRecurseBase<FieldTypeT>
00411 {
00412     typedef typename FieldTypeT::Inherited       Inherited;
00413     typedef          FieldDataTraits<FieldTypeT> FieldTypeTraits;
00414 
00415 #if defined(OSG_WIN32_CL_NET70) 
00416 #pragma warning (disable : 4806)
00417 #endif
00418 
00419     typedef typename osgIF<(bTypeHasParent == true),
00420                            FieldDataTraits<Inherited>, 
00421                            FieldTraitsRecurseBase<FieldTypeT> >::_IRet 
00422         MappedTrait;
00423 
00424 #if defined(OSG_WIN32_CL_NET70) 
00425 #pragma warning (default : 4806)
00426 #endif
00427 
00428     static UInt32 getBinSize(const FieldTypeT &oObject)
00429     {
00430         return MappedTrait::getBinSize(oObject);
00431     }
00432 
00433     static UInt32 getBinSize(const FieldTypeT   *pObjectStore,
00434                                    UInt32        uiNumObjects)
00435     {
00436         return MappedTrait::getBinSize(pObjectStore, uiNumObjects);
00437     }
00438 
00439     static void copyToBin(      BinaryDataHandler &pMem, 
00440                           const FieldTypeT        &oObject)
00441     {
00442         MappedTrait::copyToBin(pMem, oObject);
00443     }
00444 
00445     static void copyToBin(      BinaryDataHandler &pMem, 
00446                           const FieldTypeT        *pObjectStore,
00447                                 UInt32             uiNumObjects)
00448     {
00449         MappedTrait::copyToBin(pMem, pObjectStore, uiNumObjects);
00450     }
00451 
00452     static void copyFromBin(BinaryDataHandler &pMem, 
00453                             FieldTypeT        &oObject)
00454     {
00455         MappedTrait::copyFromBin(pMem, oObject);
00456     }
00457 
00458     static void copyFromBin(BinaryDataHandler &pMem, 
00459                             FieldTypeT        *pObjectStore,
00460                             UInt32             uiNumObjects)
00461     {
00462         MappedTrait::copyFromBin(pMem, pObjectStore, uiNumObjects);
00463     }
00464 
00465     static bool getFromString(      FieldTypeT &outVal,
00466                               const Char8      *inVal  )
00467     {
00468         return MappedTrait::getFromString(outVal, inVal);
00469     }
00470 
00471     static void putToString  (const FieldTypeT  &inVal,
00472                                     std::string &outStr)
00473     {
00474         MappedTrait::putToString(inVal, outStr);
00475     }
00476 };
00477 
00479 #if !defined(OSG_DOC_DEV_TRAITS)
00480 
00481 #endif
00482 
00483 template <class FieldTypeT, bool bTypeHasParent>
00484 struct FieldTraitsRecurseMapper1 : public FieldTraitsRecurseBase<FieldTypeT>
00485 {
00486     typedef typename FieldTypeT::Inherited       Inherited;
00487     typedef          FieldDataTraits<FieldTypeT> FieldTypeTraits;
00488 
00489 #if defined(OSG_WIN32_CL_NET70) 
00490 #pragma warning (disable : 4806)
00491 #endif
00492 
00493     typedef typename osgIF<bTypeHasParent == true,
00494                            FieldDataTraits1<Inherited>, 
00495                            FieldTraitsRecurseBase<FieldTypeT> >::_IRet 
00496         MappedTrait;
00497 
00498 #if defined(OSG_WIN32_CL_NET70) 
00499 #pragma warning (default : 4806)
00500 #endif
00501 
00502     static UInt32 getBinSize(const FieldTypeT &oObject)
00503     {
00504         return MappedTrait::getBinSize(oObject);
00505     }
00506 
00507     static UInt32 getBinSize(const FieldTypeT   *pObjectStore,
00508                                    UInt32        uiNumObjects)
00509     {
00510         return MappedTrait::getBinSize(pObjectStore, uiNumObjects);
00511     }
00512     static void copyToBin(      BinaryDataHandler &pMem, 
00513                           const FieldTypeT        &oObject)
00514     {
00515         MappedTrait::copyToBin(pMem, oObject);
00516     }
00517 
00518     static void copyToBin(      BinaryDataHandler &pMem, 
00519                           const FieldTypeT        *pObjectStore,
00520                                 UInt32             uiNumObjects)
00521     {
00522         MappedTrait::copyToBin(pMem, pObjectStore, uiNumObjects);
00523     }
00524 
00525     static void copyFromBin(const BinaryDataHandler &pMem, 
00526                                   FieldTypeT        &oObject)
00527     {
00528         MappedTrait::copyFromBin(pMem, oObject);
00529     }
00530 
00531     static void copyFromBin(BinaryDataHandler &pMem, 
00532                             FieldTypeT        *pObjectStore,
00533                             UInt32             uiNumObjects)
00534     {
00535         MappedTrait::copyFromBin(pMem, pObjectStore, uiNumObjects);
00536     }
00537 
00538     static bool getFromString(      FieldTypeT &outVal,
00539                               const Char8      *inVal  )
00540     {
00541         return MappedTrait::getFromString(outVal, inVal);
00542     }
00543 
00544     static void putToString  (const FieldTypeT  &inVal,
00545                                     std::string &outStr)
00546     {
00547         MappedTrait::putToString(inVal, outStr);
00548     }
00549 };
00550 
00551 
00553 #if !defined(OSG_DOC_DEV_TRAITS)
00554 
00555 #endif
00556 
00557 template <class FieldTypeT, bool bTypeHasParent>
00558 struct FieldTraitsRecurseMapper2 : public FieldTraitsRecurseBase<FieldTypeT>
00559 {
00560     typedef typename FieldTypeT::Inherited       Inherited;
00561     typedef          FieldDataTraits<FieldTypeT> FieldTypeTraits;
00562 
00563 #if defined(OSG_WIN32_CL_NET70) 
00564 #pragma warning (disable : 4806)
00565 #endif
00566 
00567     typedef typename osgIF<bTypeHasParent == true,
00568                            FieldDataTraits2<Inherited>, 
00569                            FieldTraitsRecurseBase<FieldTypeT> >::_IRet 
00570         MappedTrait;
00571 
00572 #if defined(OSG_WIN32_CL_NET70) 
00573 #pragma warning (default : 4806)
00574 #endif
00575 
00576     static UInt32 getBinSize(const FieldTypeT &oObject)
00577     {
00578         return MappedTrait::getBinSize(oObject);
00579     }
00580 
00581     static UInt32 getBinSize(const FieldTypeT   *pObjectStore,
00582                                    UInt32        uiNumObjects)
00583     {
00584         return MappedTrait::getBinSize(pObjectStore, uiNumObjects);
00585     }
00586     static void copyToBin(      BinaryDataHandler &pMem, 
00587                           const FieldTypeT        &oObject)
00588     {
00589         MappedTrait::copyToBin(pMem, oObject);
00590     }
00591 
00592     static void copyToBin(      BinaryDataHandler &pMem, 
00593                           const FieldTypeT        *pObjectStore,
00594                                 UInt32             uiNumObjects)
00595     {
00596         MappedTrait::copyToBin(pMem, pObjectStore, uiNumObjects);
00597     }
00598 
00599     static void copyFromBin(const BinaryDataHandler &pMem, 
00600                                   FieldTypeT        &oObject)
00601     {
00602         MappedTrait::copyFromBin(pMem, oObject);
00603     }
00604 
00605     static void copyFromBin(BinaryDataHandler &pMem, 
00606                             FieldTypeT        *pObjectStore,
00607                             UInt32             uiNumObjects)
00608     {
00609         MappedTrait::copyFromBin(pMem, pObjectStore, uiNumObjects);
00610     }
00611 
00612     static bool getFromString(      FieldTypeT &outVal,
00613                               const Char8      *inVal  )
00614     {
00615         return MappedTrait::getFromString(outVal, inVal);
00616     }
00617 
00618     static void putToString  (const FieldTypeT  &inVal,
00619                                     std::string &outStr)
00620     {
00621         MappedTrait::putToString(inVal, outStr);
00622     }
00623 };
00624 
00626 #if !defined(OSG_DOC_DEV_TRAITS)
00627 
00628 #endif
00629 
00630 template <class FieldTypeT>
00631 struct FieldDataTraits : public FieldTraitsRecurseMapper<FieldTypeT, false>
00632 {
00633 };
00634 
00635 #if !defined(OSG_DOC_DEV_TRAITS)
00636 
00638 #endif
00639 
00640 #if !defined(OSG_DOC_DEV_TRAITS)
00641 
00642 #endif
00643 
00644 template <class FieldTypeT>
00645 struct FieldDataTraits1 : public FieldTraitsRecurseMapper1<FieldTypeT, false>
00646 {
00647 };
00648 
00649 
00650 #if !defined(OSG_DOC_DEV_TRAITS)
00651 
00653 #endif
00654 
00655 #if !defined(OSG_DOC_DEV_TRAITS)
00656 
00657 #endif
00658 
00659 template <class FieldTypeT>
00660 struct FieldDataTraits2 : public FieldTraitsRecurseMapper2<FieldTypeT, false>
00661 {
00662 };
00663 
00664 #if !defined(OSG_DOC_DEV_TRAITS)
00665 
00667 #endif
00668 
00669 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00670 
00671 OSG_END_NAMESPACE
00672 
00673 #endif /* _OSG_FIELDDATATYPE_H_ */
00674 
00675 

Generated on Thu Aug 25 04:04:49 2005 for OpenSG by  doxygen 1.4.3