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