FBX C++ API Reference
fbxcolladaiostream.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2017 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 pArraySize, 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 (lReadCount >= pArraySize)
72  {
73  // we are trying to write past the allocated buffer
74  return 0;
75  }
76 
77  if (lDestCounter == 0)
78  {
79  for (int lIndex = 0; lIndex < pDestUnitOffset; ++lIndex)
80  *(lDest++) = pDefaultValue;
81  }
82 
83  *lDest++ = lData;
84  ++lReadCount;
85  ++lDestCounter;
86  if (lDestCounter == pDestValidUnitCount)
87  {
88  lDestCounter = 0;
89  for (int lIndex = 0; lIndex < lDestUnitGap; ++lIndex)
90  *lDest++ = pDefaultValue;
91  }
92  }
93  else
94  {
95  // we met a stop condition of FromString. In the normal case, lSource should now be "" or ' '. If not,
96  // the converted string is corrupted and we have to break the loop. We can detect this by checking
97  // if lSource pointer has moved.
98  if (lSource == lSourceStart)
99  {
100  break;
101  }
102  }
103  ++lSourceCounter;
104  if (lSourceCounter == pSourceGroupSize)
105  lSourceCounter = 0;
106  }
107  return lReadCount;
108 }
109 
110 //----------------------------------------------------------------------------//
111 
112 template <typename T>
113 const FbxString ToString(const T & pValue)
114 {
115  return FbxString(pValue);
116 }
117 template <>
118 const FbxString ToString(const FbxVector4 & pValue);
119 template <>
120 const FbxString ToString(const FbxAMatrix & pValue);
121 
122 //----------------------------------------------------------------------------//
123 
129 const FbxString DecodePercentEncoding(const FbxString & pEncodedString);
130 
131 #include <fbxsdk/fbxsdk_nsend.h>
132 
133 #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&#39;s an error.
Utility class to manipulate strings.
Definition: fbxstring.h:66
int FromStringToArray(const char *pString, TYPE *pArray, int pArraySize, int pSourceUnitOffset, int pSourceValidUnitCount, int pSourceGroupSize, int pDestUnitOffset, int pDestValidUnitCount, int pDestGroupSize, TYPE pDefaultValue=TYPE())
Parse the string into an array.
A four double mathematic vector class.
Definition: fbxvector4.h:25
FBX SDK affine matrix class.