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