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 
66  while (lSource && *lSource)
67  {
68  TYPE lData;
69  const char * lSourceStart = lSource;
70  if (FromString(&lData, lSource, &lSource) && lSourceCounter >= pSourceUnitOffset && lSourceCounter < lSourceUnitValidEnd)
71  {
72  if (lReadCount >= pArraySize)
73  {
74  // we are trying to write past the allocated buffer
75  return 0;
76  }
77 
78  if (lDestCounter == 0)
79  {
80  for (int lIndex = 0; lIndex < pDestUnitOffset; ++lIndex)
81  *(lDest++) = pDefaultValue;
82  }
83 
84  *lDest++ = lData;
85  ++lReadCount;
86  ++lDestCounter;
87  if (lDestCounter == pDestValidUnitCount)
88  {
89  lDestCounter = 0;
90  for (int lIndex = 0; lIndex < lDestUnitGap; ++lIndex)
91  *lDest++ = pDefaultValue;
92  }
93  }
94  else
95  {
96  // we met a stop condition of FromString. In the normal case, lSource should now be "" or ' '. If not,
97  // the converted string is corrupted and we have to break the loop. We can detect this by checking
98  // if lSource pointer has moved.
99  if (lSource == lSourceStart)
100  {
101  break;
102  }
103  }
104  ++lSourceCounter;
105  if (lSourceCounter == pSourceGroupSize)
106  lSourceCounter = 0;
107  }
108  return lReadCount;
109 }
110 
111 //----------------------------------------------------------------------------//
112 
113 template <typename T>
114 const FbxString ToString(const T & pValue)
115 {
116  return FbxString(pValue);
117 }
118 template <>
119 const FbxString ToString(const FbxVector4 & pValue);
120 template <>
121 const FbxString ToString(const FbxAMatrix & pValue);
122 
123 //----------------------------------------------------------------------------//
124 
130 const FbxString DecodePercentEncoding(const FbxString & pEncodedString);
131 
132 #include <fbxsdk/fbxsdk_nsend.h>
133 
134 #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:213
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
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.