fbxsdk/fileio/collada/fbxcolladaiostream.h Source File

fbxcolladaiostream.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
14 #define _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
15 
16 #include <fbxsdk.h>
17 
18 #include <fbxsdk/fbxsdk_nsbegin.h>
19 
20 //----------------------------------------------------------------------------//
21 
28 template <typename T> bool FromString(T * pDest, const char * pSourceBegin, const char ** pSourceEnd = NULL);
29 template <> bool FromString(int * pDest, const char * pSourceBegin, const char ** pSourceEnd);
30 template <> bool FromString(double * pDest, const char * pSourceBegin, const char ** pSourceEnd);
31 template <> bool FromString(FbxString * pDest, const char * pSourceBegin, const char ** pSourceEnd);
32 template <> bool FromString(FbxDouble2 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
33 template <> bool FromString(FbxDouble3 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
34 template <> bool FromString(FbxDouble4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
35 template <> bool FromString(FbxVector4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
36 template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
37 template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
38 
39 
40 
48 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())
49 {
50  if (pString == 0 || pArray == 0)
51  return 0;
52 
53  FBX_ASSERT(pSourceUnitOffset >= 0 && pSourceUnitOffset < pSourceGroupSize);
54  FBX_ASSERT(pSourceValidUnitCount >= 0 && pSourceUnitOffset + pSourceValidUnitCount <= pSourceGroupSize);
55  FBX_ASSERT(pDestUnitOffset >= 0 && pDestUnitOffset < pDestGroupSize);
56  FBX_ASSERT(pDestValidUnitCount >= 0 && pDestUnitOffset + pDestValidUnitCount <= pDestGroupSize);
57  const char * lSource = pString;
58  TYPE * lDest = pArray;
59 
60  int lReadCount = 0;
61  int lSourceCounter = 0;
62  int lDestCounter = 0;
63  const int lSourceUnitValidEnd = pSourceUnitOffset + pSourceValidUnitCount;
64  const int lDestUnitGap = pDestGroupSize - pDestValidUnitCount - pDestUnitOffset;
65  while (lSource && *lSource)
66  {
67  TYPE lData;
68  const char * lSourceStart = lSource;
69  if (FromString(&lData, lSource, &lSource) && lSourceCounter >= pSourceUnitOffset && lSourceCounter < lSourceUnitValidEnd)
70  {
71  if (lDestCounter == 0)
72  {
73  for (int lIndex = 0; lIndex < pDestUnitOffset; ++lIndex)
74  *(lDest++) = pDefaultValue;
75  }
76 
77  *lDest++ = lData;
78  ++lReadCount;
79  ++lDestCounter;
80  if (lDestCounter == pDestValidUnitCount)
81  {
82  lDestCounter = 0;
83  for (int lIndex = 0; lIndex < lDestUnitGap; ++lIndex)
84  *lDest++ = pDefaultValue;
85  }
86  }
87  else
88  {
89  // we met a stop condition of FromString. In the normal case, lSource should now be "" or ' '. If not,
90  // the converted string is corrupted and we have to break the loop. We can detect this by checking
91  // if lSource pointer has moved.
92  if (lSource == lSourceStart)
93  {
94  break;
95  }
96  }
97  ++lSourceCounter;
98  if (lSourceCounter == pSourceGroupSize)
99  lSourceCounter = 0;
100  }
101  return lReadCount;
102 }
103 
104 //----------------------------------------------------------------------------//
105 
106 template <typename T>
107 const FbxString ToString(const T & pValue)
108 {
109  return FbxString(pValue);
110 }
111 template <>
112 const FbxString ToString(const FbxVector4 & pValue);
113 template <>
114 const FbxString ToString(const FbxAMatrix & pValue);
115 
116 //----------------------------------------------------------------------------//
117 
123 const FbxString DecodePercentEncoding(const FbxString & pEncodedString);
124 
125 #include <fbxsdk/fbxsdk_nsend.h>
126 
127 #endif /* _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_ */
const FbxString ToString(const T &pValue)
bool FromString(T *pDest, const char *pSourceBegin, const char **pSourceEnd=((void *) 0))
Convert part of the source string into destination type.
#define NULL
Definition: fbxarch.h:210
const FbxString DecodePercentEncoding(const FbxString &pEncodedString)
Decode percent encoded characters, returns an empty string if there's an error.
Utility class to manipulate strings.
Definition: fbxstring.h:66
A four double mathematic vector class.
Definition: fbxvector4.h:25
FBX SDK affine matrix class.
int FromStringToArray(const char *pString, TYPE *pArray, int pSourceUnitOffset, int pSourceValidUnitCount, int pSourceGroupSize, int pDestUnitOffset, int pDestValidUnitCount, int pDestGroupSize, TYPE pDefaultValue=TYPE())
Parse the string into an array.