AMFImporter_Macro.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2020, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /// \file AMFImporter_Macro.hpp
  35. /// \brief Useful macrodefines.
  36. /// \date 2016
  37. /// \author [email protected]
  38. #pragma once
  39. #ifndef AMFIMPORTER_MACRO_HPP_INCLUDED
  40. #define AMFIMPORTER_MACRO_HPP_INCLUDED
  41. /// \def MACRO_ATTRREAD_LOOPBEG
  42. /// Begin of loop that read attributes values.
  43. #define MACRO_ATTRREAD_LOOPBEG \
  44. for(int idx = 0, idx_end = mReader->getAttributeCount(); idx < idx_end; idx++) \
  45. { \
  46. std::string an(mReader->getAttributeName(idx));
  47. /// \def MACRO_ATTRREAD_LOOPEND
  48. /// End of loop that read attributes values.
  49. #define MACRO_ATTRREAD_LOOPEND \
  50. Throw_IncorrectAttr(an); \
  51. }
  52. /// \def MACRO_ATTRREAD_LOOPEND_WSKIP
  53. /// End of loop that read attributes values. Difference from \ref MACRO_ATTRREAD_LOOPEND in that: current macro skip unknown attributes, but
  54. /// \ref MACRO_ATTRREAD_LOOPEND throw an exception.
  55. #define MACRO_ATTRREAD_LOOPEND_WSKIP \
  56. continue; \
  57. }
  58. /// \def MACRO_ATTRREAD_CHECK_REF
  59. /// Check current attribute name and if it equal to requested then read value. Result write to output variable by reference. If result was read then
  60. /// "continue" will called.
  61. /// \param [in] pAttrName - attribute name.
  62. /// \param [out] pVarName - output variable name.
  63. /// \param [in] pFunction - function which read attribute value and write it to pVarName.
  64. #define MACRO_ATTRREAD_CHECK_REF(pAttrName, pVarName, pFunction) \
  65. if(an == pAttrName) \
  66. { \
  67. pFunction(idx, pVarName); \
  68. continue; \
  69. }
  70. /// \def MACRO_ATTRREAD_CHECK_RET
  71. /// Check current attribute name and if it equal to requested then read value. Result write to output variable using return value of \ref pFunction.
  72. /// If result was read then "continue" will called.
  73. /// \param [in] pAttrName - attribute name.
  74. /// \param [out] pVarName - output variable name.
  75. /// \param [in] pFunction - function which read attribute value and write it to pVarName.
  76. #define MACRO_ATTRREAD_CHECK_RET(pAttrName, pVarName, pFunction) \
  77. if(an == pAttrName) \
  78. { \
  79. pVarName = pFunction(idx); \
  80. continue; \
  81. }
  82. /// \def MACRO_NODECHECK_LOOPBEGIN(pNodeName)
  83. /// Begin of loop of parsing child nodes. Do not add ';' at end.
  84. /// \param [in] pNodeName - current node name.
  85. #define MACRO_NODECHECK_LOOPBEGIN(pNodeName) \
  86. do { \
  87. bool close_found = false; \
  88. \
  89. while(mReader->read()) \
  90. { \
  91. if(mReader->getNodeType() == irr::io::EXN_ELEMENT) \
  92. {
  93. /// \def MACRO_NODECHECK_LOOPEND(pNodeName)
  94. /// End of loop of parsing child nodes.
  95. /// \param [in] pNodeName - current node name.
  96. #define MACRO_NODECHECK_LOOPEND(pNodeName) \
  97. XML_CheckNode_SkipUnsupported(pNodeName); \
  98. }/* if(mReader->getNodeType() == irr::io::EXN_ELEMENT) */ \
  99. else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) \
  100. { \
  101. if(XML_CheckNode_NameEqual(pNodeName)) \
  102. { \
  103. close_found = true; \
  104. \
  105. break; \
  106. } \
  107. }/* else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) */ \
  108. }/* while(mReader->read()) */ \
  109. \
  110. if(!close_found) Throw_CloseNotFound(pNodeName); \
  111. \
  112. } while(false)
  113. /// \def MACRO_NODECHECK_READCOMP_F
  114. /// Check current node name and if it equal to requested then read value. Result write to output variable of type "float".
  115. /// If result was read then "continue" will called. Also check if node data already read then raise exception.
  116. /// \param [in] pNodeName - node name.
  117. /// \param [in, out] pReadFlag - read flag.
  118. /// \param [out] pVarName - output variable name.
  119. #define MACRO_NODECHECK_READCOMP_F(pNodeName, pReadFlag, pVarName) \
  120. if(XML_CheckNode_NameEqual(pNodeName)) \
  121. { \
  122. /* Check if field already read before. */ \
  123. if(pReadFlag) Throw_MoreThanOnceDefined(pNodeName, "Only one component can be defined."); \
  124. /* Read color component and assign it to object. */ \
  125. pVarName = XML_ReadNode_GetVal_AsFloat(); \
  126. pReadFlag = true; \
  127. continue; \
  128. }
  129. /// \def MACRO_NODECHECK_READCOMP_U32
  130. /// Check current node name and if it equal to requested then read value. Result write to output variable of type "uint32_t".
  131. /// If result was read then "continue" will called. Also check if node data already read then raise exception.
  132. /// \param [in] pNodeName - node name.
  133. /// \param [in, out] pReadFlag - read flag.
  134. /// \param [out] pVarName - output variable name.
  135. #define MACRO_NODECHECK_READCOMP_U32(pNodeName, pReadFlag, pVarName) \
  136. if(XML_CheckNode_NameEqual(pNodeName)) \
  137. { \
  138. /* Check if field already read before. */ \
  139. if(pReadFlag) Throw_MoreThanOnceDefined(pNodeName, "Only one component can be defined."); \
  140. /* Read color component and assign it to object. */ \
  141. pVarName = XML_ReadNode_GetVal_AsU32(); \
  142. pReadFlag = true; \
  143. continue; \
  144. }
  145. #endif // AMFIMPORTER_MACRO_HPP_INCLUDED