fbxcolladaiostream.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2012 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00013 #ifndef _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
00014 #define _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
00015 
00016 #include <cctype>
00017 
00018 #include <fbxsdk.h>
00019 
00020 #include <fbxsdk/fbxsdk_nsbegin.h>
00021 
00029 template <typename TYPE> int FromStringToArray(const char * pString, TYPE * pArray, int pSourceUnitOffset, int pSourceValidUnitCount, int pSourceGroupSize, int pDestUnitOffset, int pDestValidUnitCount, int pDestGroupSize, TYPE pDefaultValue = TYPE())
00030 {
00031     if (pString == 0 || pArray == 0)
00032         return 0;
00033 
00034     FBX_ASSERT(pSourceUnitOffset >= 0 && pSourceUnitOffset < pSourceGroupSize);
00035     FBX_ASSERT(pSourceValidUnitCount >= 0 && pSourceUnitOffset + pSourceValidUnitCount <= pSourceGroupSize);
00036     FBX_ASSERT(pDestUnitOffset >= 0 && pDestUnitOffset < pDestGroupSize);
00037     FBX_ASSERT(pDestValidUnitCount >= 0 && pDestUnitOffset + pDestValidUnitCount <= pDestGroupSize);
00038     const char * lSource = pString;
00039     TYPE * lDest = pArray;
00040 
00041     int lReadCount = 0;
00042     int lSourceCounter = 0;
00043     int lDestCounter = 0;
00044     const int lSourceUnitValidEnd = pSourceUnitOffset + pSourceValidUnitCount;
00045     const int lDestUnitGap = pDestGroupSize - pDestValidUnitCount - pDestUnitOffset;
00046     while (lSource && *lSource)
00047     {
00048         TYPE lData;
00049         const char * lSourceStart = lSource;
00050         if (FromString(&lData, lSource, &lSource) && lSourceCounter >= pSourceUnitOffset && lSourceCounter < lSourceUnitValidEnd)
00051         {
00052             if (lDestCounter == 0)
00053             {
00054                 for (int lIndex = 0; lIndex < pDestUnitOffset; ++lIndex)
00055                     *(lDest++) = pDefaultValue;
00056             }
00057 
00058             *lDest++ = lData;
00059             ++lReadCount;
00060             ++lDestCounter;
00061             if (lDestCounter == pDestValidUnitCount)
00062             {
00063                 lDestCounter = 0;
00064                 for (int lIndex = 0; lIndex < lDestUnitGap; ++lIndex)
00065                     *lDest++ = pDefaultValue;
00066             }
00067         }
00068         else
00069         {
00070             // we met a stop condition of FromString. In the normal case, lSource should now be "" or ' '. If not,
00071             // the converted string is corrupted and we have to break the loop. We can detect this by checking
00072             // if lSource pointer has moved.
00073             if (lSource == lSourceStart)
00074             {
00075                 break;
00076             }
00077         }
00078         ++lSourceCounter;
00079         if (lSourceCounter == pSourceGroupSize)
00080             lSourceCounter = 0;
00081     }
00082     return lReadCount;
00083 }
00084 
00085 //----------------------------------------------------------------------------//
00086 
00093 template <typename T> bool FromString(T * pDest, const char * pSourceBegin, const char ** pSourceEnd = NULL);
00094 template <> bool FromString(int * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00095 template <> bool FromString(double * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00096 template <> bool FromString(FbxString * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00097 template <> bool FromString(FbxDouble2 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00098 template <> bool FromString(FbxDouble3 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00099 template <> bool FromString(FbxDouble4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00100 template <> bool FromString(FbxVector4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00101 template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00102 template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
00103 
00104 //----------------------------------------------------------------------------//
00105 
00106 template <typename T>
00107 const FbxString ToString(const T & pValue)
00108 {
00109     return FbxString(pValue);
00110 }
00111 template <>
00112 const FbxString ToString(const FbxVector4 & pValue);
00113 template <>
00114 const FbxString ToString(const FbxAMatrix & pValue);
00115 
00116 //----------------------------------------------------------------------------//
00117 
00123 const FbxString DecodePercentEncoding(const FbxString & pEncodedString);
00124 
00125 #include <fbxsdk/fbxsdk_nsend.h>
00126 
00127 #endif /* _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_ */