X3DImporter_Macro.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /// \file X3DImporter_Macro.hpp
  34. /// \brief Useful macrodefines.
  35. /// \date 2015-2016
  36. /// \author [email protected]
  37. #ifndef X3DIMPORTER_MACRO_HPP_INCLUDED
  38. #define X3DIMPORTER_MACRO_HPP_INCLUDED
  39. /// \def MACRO_USE_CHECKANDAPPLY(pDEF, pUSE, pNE)
  40. /// Used for regular checking while attribute "USE" is defined.
  41. /// \param [in] pDEF - string holding "DEF" value.
  42. /// \param [in] pUSE - string holding "USE" value.
  43. /// \param [in] pType - type of element to find.
  44. /// \param [out] pNE - pointer to found node element.
  45. #define MACRO_USE_CHECKANDAPPLY(pDEF, pUSE, pType, pNE) \
  46. do { \
  47. XML_CheckNode_MustBeEmpty(); \
  48. if(!pDEF.empty()) Throw_DEF_And_USE(); \
  49. if(!FindNodeElement(pUSE, CX3DImporter_NodeElement::pType, &pNE)) Throw_USE_NotFound(pUSE); \
  50. \
  51. NodeElement_Cur->Child.push_back(pNE);/* add found object as child to current element */ \
  52. } while(false)
  53. /// \def MACRO_ATTRREAD_LOOPBEG
  54. /// Begin of loop that read attributes values.
  55. #define MACRO_ATTRREAD_LOOPBEG \
  56. for(int idx = 0, idx_end = mReader->getAttributeCount(); idx < idx_end; idx++) \
  57. { \
  58. std::string an(mReader->getAttributeName(idx));
  59. /// \def MACRO_ATTRREAD_LOOPEND
  60. /// End of loop that read attributes values.
  61. #define MACRO_ATTRREAD_LOOPEND \
  62. Throw_IncorrectAttr(an); \
  63. }
  64. /// \def MACRO_ATTRREAD_CHECK_REF
  65. /// Check curent attribute name and if it equal to requested then read value. Result write to output variable by reference. If result was read then
  66. /// "continue" will called.
  67. /// \param [in] pAttrName - attribute name.
  68. /// \param [out] pVarName - output variable name.
  69. /// \param [in] pFunction - function which read attribute value and write it to pVarName.
  70. #define MACRO_ATTRREAD_CHECK_REF(pAttrName, pVarName, pFunction) \
  71. if(an == pAttrName) \
  72. { \
  73. pFunction(idx, pVarName); \
  74. continue; \
  75. }
  76. /// \def MACRO_ATTRREAD_CHECK_RET
  77. /// Check curent attribute name and if it equal to requested then read value. Result write to output variable using return value of \ref pFunction.
  78. /// If result was read then "continue" will called.
  79. /// \param [in] pAttrName - attribute name.
  80. /// \param [out] pVarName - output variable name.
  81. /// \param [in] pFunction - function which read attribute value and write it to pVarName.
  82. #define MACRO_ATTRREAD_CHECK_RET(pAttrName, pVarName, pFunction) \
  83. if(an == pAttrName) \
  84. { \
  85. pVarName = pFunction(idx); \
  86. continue; \
  87. }
  88. /// \def MACRO_ATTRREAD_CHECKUSEDEF_RET
  89. /// Compact variant for checking "USE" and "DEF". Also skip bbox attributes: "bboxCenter", "bboxSize".
  90. /// If result was read then "continue" will called.
  91. /// \param [out] pDEF_Var - output variable name for "DEF" value.
  92. /// \param [out] pUSE_Var - output variable name for "USE" value.
  93. #define MACRO_ATTRREAD_CHECKUSEDEF_RET(pDEF_Var, pUSE_Var) \
  94. MACRO_ATTRREAD_CHECK_RET("DEF", pDEF_Var, mReader->getAttributeValue); \
  95. MACRO_ATTRREAD_CHECK_RET("USE", pUSE_Var, mReader->getAttributeValue); \
  96. if(an == "bboxCenter") continue; \
  97. if(an == "bboxSize") continue; \
  98. if(an == "containerField") continue; \
  99. do {} while(false)
  100. /// \def MACRO_NODECHECK_LOOPBEGIN(pNodeName)
  101. /// Begin of loop of parsing child nodes. Do not add ';' at end.
  102. /// \param [in] pNodeName - current node name.
  103. #define MACRO_NODECHECK_LOOPBEGIN(pNodeName) \
  104. do { \
  105. bool close_found = false; \
  106. \
  107. while(mReader->read()) \
  108. { \
  109. if(mReader->getNodeType() == irr::io::EXN_ELEMENT) \
  110. {
  111. /// \def MACRO_NODECHECK_LOOPEND(pNodeName)
  112. /// End of loop of parsing child nodes.
  113. /// \param [in] pNodeName - current node name.
  114. #define MACRO_NODECHECK_LOOPEND(pNodeName) \
  115. }/* if(mReader->getNodeType() == irr::io::EXN_ELEMENT) */ \
  116. else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) \
  117. { \
  118. if(XML_CheckNode_NameEqual(pNodeName)) \
  119. { \
  120. close_found = true; \
  121. \
  122. break; \
  123. } \
  124. }/* else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) */ \
  125. }/* while(mReader->read()) */ \
  126. \
  127. if(!close_found) Throw_CloseNotFound(pNodeName); \
  128. \
  129. } while(false)
  130. #define MACRO_NODECHECK_METADATA(pNodeName) \
  131. MACRO_NODECHECK_LOOPBEGIN(pNodeName) \
  132. /* and childs must be metadata nodes */ \
  133. if(!ParseHelper_CheckRead_X3DMetadataObject()) XML_CheckNode_SkipUnsupported(pNodeName); \
  134. MACRO_NODECHECK_LOOPEND(pNodeName)
  135. /// \def MACRO_FACE_ADD_QUAD_FA(pCCW, pOut, pIn, pP1, pP2, pP3, pP4)
  136. /// Add points as quad. Means that pP1..pP4 set in CCW order.
  137. #define MACRO_FACE_ADD_QUAD_FA(pCCW, pOut, pIn, pP1, pP2, pP3, pP4) \
  138. do { \
  139. if(pCCW) \
  140. { \
  141. pOut.push_back(pIn[pP1]); \
  142. pOut.push_back(pIn[pP2]); \
  143. pOut.push_back(pIn[pP3]); \
  144. pOut.push_back(pIn[pP4]); \
  145. } \
  146. else \
  147. { \
  148. pOut.push_back(pIn[pP4]); \
  149. pOut.push_back(pIn[pP3]); \
  150. pOut.push_back(pIn[pP2]); \
  151. pOut.push_back(pIn[pP1]); \
  152. } \
  153. } while(false)
  154. /// \def MACRO_FACE_ADD_QUAD(pCCW, pOut, pP1, pP2, pP3, pP4)
  155. /// Add points as quad. Means that pP1..pP4 set in CCW order.
  156. #define MACRO_FACE_ADD_QUAD(pCCW, pOut, pP1, pP2, pP3, pP4) \
  157. do { \
  158. if(pCCW) \
  159. { \
  160. pOut.push_back(pP1); \
  161. pOut.push_back(pP2); \
  162. pOut.push_back(pP3); \
  163. pOut.push_back(pP4); \
  164. } \
  165. else \
  166. { \
  167. pOut.push_back(pP4); \
  168. pOut.push_back(pP3); \
  169. pOut.push_back(pP2); \
  170. pOut.push_back(pP1); \
  171. } \
  172. } while(false)
  173. #endif // X3DIMPORTER_MACRO_HPP_INCLUDED