vrshoot

view libs/assimp/FBXProperties.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
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.
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.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file FBXProperties.h
42 * @brief FBX dynamic properties
43 */
44 #ifndef INCLUDED_AI_FBX_PROPERTIES_H
45 #define INCLUDED_AI_FBX_PROPERTIES_H
47 #include <map>
48 #include <string>
50 namespace Assimp {
51 namespace FBX {
53 class Element;
56 /** Represents a dynamic property. Type info added by deriving classes,
57 * see #TypedProperty.
58 Example:
59 @verbatim
60 P: "ShininessExponent", "double", "Number", "",0.5
61 @endvebatim
63 */
64 class Property
65 {
66 protected:
68 Property();
70 public:
72 virtual ~Property();
74 public:
76 template <typename T>
77 const T* As() const {
78 return dynamic_cast<const T*>(this);
79 }
80 };
83 template<typename T>
84 class TypedProperty : public Property
85 {
86 public:
88 TypedProperty(const T& value)
89 : value(value)
90 {
91 }
93 public:
95 const T& Value() const {
96 return value;
97 }
99 private:
100 T value;
101 };
104 typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap;
105 typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap;
107 /** Represents a property table as can be found in the newer FBX files (Properties60, Properties70)*/
108 class PropertyTable
109 {
110 public:
112 // in-memory property table with no source element
113 PropertyTable();
115 PropertyTable(const Element& element, boost::shared_ptr<const PropertyTable> templateProps);
116 ~PropertyTable();
118 public:
120 const Property* Get(const std::string& name) const;
122 // PropertyTable's need not be coupled with FBX elements so this can be NULL
123 const Element* GetElement() const {
124 return element;
125 }
127 const PropertyTable* TemplateProps() const {
128 return templateProps.get();
129 }
131 private:
133 LazyPropertyMap lazyProps;
134 mutable PropertyMap props;
135 const boost::shared_ptr<const PropertyTable> templateProps;
136 const Element* const element;
137 };
140 // ------------------------------------------------------------------------------------------------
141 template <typename T>
142 inline T PropertyGet(const PropertyTable& in, const std::string& name,
143 const T& defaultValue,
144 bool ignoreTemplate = false)
145 {
146 const Property* const prop = in.Get(name);
147 if(!prop) {
148 return defaultValue;
149 }
151 // strong typing, no need to be lenient
152 const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
153 if(!tprop) {
154 return defaultValue;
155 }
157 return tprop->Value();
158 }
161 // ------------------------------------------------------------------------------------------------
162 template <typename T>
163 inline T PropertyGet(const PropertyTable& in, const std::string& name,
164 bool& result,
165 bool ignoreTemplate = false)
166 {
167 const Property* const prop = in.Get(name);
168 if(!prop) {
169 result = false;
170 return T();
171 }
173 // strong typing, no need to be lenient
174 const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
175 if(!tprop) {
176 result = false;
177 return T();
178 }
180 result = true;
181 return tprop->Value();
182 }
185 } //! FBX
186 } //! Assimp
188 #endif //