1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2019, assimp team
6
7
8All rights reserved.
9
10Redistribution and use of this software in source and binary forms,
11with or without modification, are permitted provided that the
12following conditions are met:
13
14* Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
17
18* Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22
23* Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
27
28THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40----------------------------------------------------------------------
41*/
42
43/** @file FBXProperties.h
44 * @brief FBX dynamic properties
45 */
46#ifndef INCLUDED_AI_FBX_PROPERTIES_H
47#define INCLUDED_AI_FBX_PROPERTIES_H
48
49#include "FBXCompileConfig.h"
50#include <memory>
51#include <string>
52
53namespace Assimp {
54namespace FBX {
55
56// Forward declarations
57class Element;
58
59/** Represents a dynamic property. Type info added by deriving classes,
60 * see #TypedProperty.
61 Example:
62 @verbatim
63 P: "ShininessExponent", "double", "Number", "",0.5
64 @endvebatim
65*/
66class Property {
67protected:
68 Property();
69
70public:
71 virtual ~Property();
72
73public:
74 template <typename T>
75 const T* As() const {
76 return dynamic_cast<const T*>(this);
77 }
78};
79
80template<typename T>
81class TypedProperty : public Property {
82public:
83 explicit TypedProperty(const T& value)
84 : value(value) {
85 // empty
86 }
87
88 const T& Value() const {
89 return value;
90 }
91
92private:
93 T value;
94};
95
96
97typedef std::fbx_unordered_map<std::string,std::shared_ptr<Property> > DirectPropertyMap;
98typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap;
99typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap;
100
101/**
102 * Represents a property table as can be found in the newer FBX files (Properties60, Properties70)
103 */
104class PropertyTable {
105public:
106 // in-memory property table with no source element
107 PropertyTable();
108 PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps);
109 ~PropertyTable();
110
111 const Property* Get(const std::string& name) const;
112
113 // PropertyTable's need not be coupled with FBX elements so this can be NULL
114 const Element* GetElement() const {
115 return element;
116 }
117
118 const PropertyTable* TemplateProps() const {
119 return templateProps.get();
120 }
121
122 DirectPropertyMap GetUnparsedProperties() const;
123
124private:
125 LazyPropertyMap lazyProps;
126 mutable PropertyMap props;
127 const std::shared_ptr<const PropertyTable> templateProps;
128 const Element* const element;
129};
130
131// ------------------------------------------------------------------------------------------------
132template <typename T>
133inline
134T PropertyGet(const PropertyTable& in, const std::string& name, const T& defaultValue) {
135 const Property* const prop = in.Get(name);
136 if( nullptr == prop) {
137 return defaultValue;
138 }
139
140 // strong typing, no need to be lenient
141 const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
142 if( nullptr == tprop) {
143 return defaultValue;
144 }
145
146 return tprop->Value();
147}
148
149// ------------------------------------------------------------------------------------------------
150template <typename T>
151inline
152T PropertyGet(const PropertyTable& in, const std::string& name, bool& result, bool useTemplate=false ) {
153 const Property* prop = in.Get(name);
154 if( nullptr == prop) {
155 if ( ! useTemplate ) {
156 result = false;
157 return T();
158 }
159 const PropertyTable* templ = in.TemplateProps();
160 if ( nullptr == templ ) {
161 result = false;
162 return T();
163 }
164 prop = templ->Get(name);
165 if ( nullptr == prop ) {
166 result = false;
167 return T();
168 }
169 }
170
171 // strong typing, no need to be lenient
172 const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
173 if( nullptr == tprop) {
174 result = false;
175 return T();
176 }
177
178 result = true;
179 return tprop->Value();
180}
181
182} //! FBX
183} //! Assimp
184
185#endif // INCLUDED_AI_FBX_PROPERTIES_H
186

source code of qt3d/src/3rdparty/assimp/src/code/FBX/FBXProperties.h