fbxcolladaiostream.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxcolladaiostream.h
  9. #ifndef _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
  10. #define _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_
  11. #include <fbxsdk.h>
  12. #include <fbxsdk/fbxsdk_nsbegin.h>
  13. //----------------------------------------------------------------------------//
  14. /** Convert part of the source string into destination type.
  15. * \param pDest The destination with a specific type.
  16. * \param pSourceBegin The begin of the source string.
  17. * \param pSourceEnd Return the end of the part of the source string.
  18. * \return Return \c true on success and \c false if else.
  19. */
  20. template <typename T> bool FromString(T * pDest, const char * pSourceBegin, const char ** pSourceEnd = NULL);
  21. template <> bool FromString(int * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  22. template <> bool FromString(double * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  23. template <> bool FromString(FbxString * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  24. template <> bool FromString(FbxDouble2 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  25. template <> bool FromString(FbxDouble3 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  26. template <> bool FromString(FbxDouble4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  27. template <> bool FromString(FbxVector4 * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  28. template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  29. template <> bool FromString(FbxAMatrix * pDest, const char * pSourceBegin, const char ** pSourceEnd);
  30. /** Parse the string into an array.
  31. * The source string is made up with many groups and each group contains pSourceGroupSize units separated by spaces;
  32. * The destination array is also made up with many groups and each unit contains pDestGroupSize units.
  33. * The valid unit range in each source group is [pSourceUnitOffset, pSourceUnitOffset + pSourceValidUnitCount).
  34. * The valid unit range in each destination unit is [pDestUnitOffset, pDestUnitOffset + pDestValidUnitCount).
  35. * The units in invalid range of destination is set to a default value.
  36. */
  37. 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())
  38. {
  39. if (pString == 0 || pArray == 0)
  40. return 0;
  41. FBX_ASSERT(pSourceUnitOffset >= 0 && pSourceUnitOffset < pSourceGroupSize);
  42. FBX_ASSERT(pSourceValidUnitCount >= 0 && pSourceUnitOffset + pSourceValidUnitCount <= pSourceGroupSize);
  43. FBX_ASSERT(pDestUnitOffset >= 0 && pDestUnitOffset < pDestGroupSize);
  44. FBX_ASSERT(pDestValidUnitCount >= 0 && pDestUnitOffset + pDestValidUnitCount <= pDestGroupSize);
  45. const char * lSource = pString;
  46. TYPE * lDest = pArray;
  47. int lReadCount = 0;
  48. int lSourceCounter = 0;
  49. int lDestCounter = 0;
  50. const int lSourceUnitValidEnd = pSourceUnitOffset + pSourceValidUnitCount;
  51. const int lDestUnitGap = pDestGroupSize - pDestValidUnitCount - pDestUnitOffset;
  52. while (lSource && *lSource)
  53. {
  54. TYPE lData;
  55. const char * lSourceStart = lSource;
  56. if (FromString(&lData, lSource, &lSource) && lSourceCounter >= pSourceUnitOffset && lSourceCounter < lSourceUnitValidEnd)
  57. {
  58. if (lDestCounter == 0)
  59. {
  60. for (int lIndex = 0; lIndex < pDestUnitOffset; ++lIndex)
  61. *(lDest++) = pDefaultValue;
  62. }
  63. *lDest++ = lData;
  64. ++lReadCount;
  65. ++lDestCounter;
  66. if (lDestCounter == pDestValidUnitCount)
  67. {
  68. lDestCounter = 0;
  69. for (int lIndex = 0; lIndex < lDestUnitGap; ++lIndex)
  70. *lDest++ = pDefaultValue;
  71. }
  72. }
  73. else
  74. {
  75. // we met a stop condition of FromString. In the normal case, lSource should now be "" or ' '. If not,
  76. // the converted string is corrupted and we have to break the loop. We can detect this by checking
  77. // if lSource pointer has moved.
  78. if (lSource == lSourceStart)
  79. {
  80. break;
  81. }
  82. }
  83. ++lSourceCounter;
  84. if (lSourceCounter == pSourceGroupSize)
  85. lSourceCounter = 0;
  86. }
  87. return lReadCount;
  88. }
  89. //----------------------------------------------------------------------------//
  90. template <typename T>
  91. const FbxString ToString(const T & pValue)
  92. {
  93. return FbxString(pValue);
  94. }
  95. template <>
  96. const FbxString ToString(const FbxVector4 & pValue);
  97. template <>
  98. const FbxString ToString(const FbxAMatrix & pValue);
  99. //----------------------------------------------------------------------------//
  100. /** Decode percent encoded characters, returns an empty string if there's an error.
  101. * For example, a string like "abc%20abc" is converted into "abc abc".
  102. * \param pEncodedString The percent encoded string.
  103. * \return The decoded string.
  104. */
  105. const FbxString DecodePercentEncoding(const FbxString & pEncodedString);
  106. #include <fbxsdk/fbxsdk_nsend.h>
  107. #endif /* _FBXSDK_FILEIO_COLLADA_IO_STREAM_H_ */