1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2012, assimp team
6All rights reserved.
7
8Redistribution and use of this software in source and binary forms,
9with or without modification, are permitted provided that the
10following conditions are met:
11
12* Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
15
16* Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
20
21* Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38----------------------------------------------------------------------
39*/
40
41/** @file FBXDocumentUtil.h
42 * @brief FBX internal utilities used by the DOM reading code
43 */
44#ifndef INCLUDED_AI_FBX_DOCUMENT_UTIL_H
45#define INCLUDED_AI_FBX_DOCUMENT_UTIL_H
46
47#include "../include/assimp/defs.h"
48#include <string>
49#include <memory>
50#include "FBXDocument.h"
51
52struct Token;
53struct Element;
54
55namespace Assimp {
56namespace FBX {
57namespace Util {
58
59
60/* DOM/Parse error reporting - does not return */
61AI_WONT_RETURN void DOMError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX;
62AI_WONT_RETURN void DOMError(const std::string& message, const Element* element = NULL) AI_WONT_RETURN_SUFFIX;
63
64// does return
65void DOMWarning(const std::string& message, const Token& token);
66void DOMWarning(const std::string& message, const Element* element = NULL);
67
68
69// fetch a property table and the corresponding property template
70std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
71 const std::string& templateName,
72 const Element &element,
73 const Scope& sc,
74 bool no_warn = false);
75
76
77// ------------------------------------------------------------------------------------------------
78template <typename T>
79inline const T* ProcessSimpleConnection(const Connection& con,
80 bool is_object_property_conn,
81 const char* name,
82 const Element& element,
83 const char** propNameOut = NULL)
84{
85 if (is_object_property_conn && !con.PropertyName().length()) {
86 DOMWarning("expected incoming " + std::string(name) +
87 " link to be an object-object connection, ignoring",
88 &element
89 );
90 return NULL;
91 }
92 else if (!is_object_property_conn && con.PropertyName().length()) {
93 DOMWarning("expected incoming " + std::string(name) +
94 " link to be an object-property connection, ignoring",
95 &element
96 );
97 return NULL;
98 }
99
100 if(is_object_property_conn && propNameOut) {
101 // note: this is ok, the return value of PropertyValue() is guaranteed to
102 // remain valid and unchanged as long as the document exists.
103 *propNameOut = con.PropertyName().c_str();
104 }
105
106 const Object* const ob = con.SourceObject();
107 if(!ob) {
108 DOMWarning("failed to read source object for incoming" + std::string(name) +
109 " link, ignoring",
110 &element);
111 return NULL;
112 }
113
114 return dynamic_cast<const T*>(ob);
115}
116
117
118} //!Util
119} //!FBX
120} //!Assimp
121
122#endif
123