assimp/code/FBXProperties.h

173 lines
4.8 KiB
C
Raw Normal View History

2012-07-02 13:57:51 +00:00
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
2017-05-09 17:57:36 +00:00
Copyright (c) 2006-2017, assimp team
2012-07-02 13:57:51 +00:00
All rights reserved.
2015-05-19 03:52:10 +00:00
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
2012-07-02 13:57:51 +00:00
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
2015-05-19 03:52:10 +00:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2012-07-02 13:57:51 +00:00
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2015-05-19 03:52:10 +00:00
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012-07-02 13:57:51 +00:00
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2015-05-19 03:52:10 +00:00
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2012-07-02 13:57:51 +00:00
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2015-05-19 03:52:10 +00:00
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2012-07-02 13:57:51 +00:00
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
/** @file FBXProperties.h
2015-05-19 03:52:10 +00:00
* @brief FBX dynamic properties
2012-07-02 13:57:51 +00:00
*/
#ifndef INCLUDED_AI_FBX_PROPERTIES_H
#define INCLUDED_AI_FBX_PROPERTIES_H
#include "FBXCompileConfig.h"
#include <memory>
2017-03-05 14:05:40 +00:00
#include <string>
2012-07-02 13:57:51 +00:00
namespace Assimp {
namespace FBX {
2017-03-05 14:05:40 +00:00
// Forward declarations
class Element;
2012-07-02 13:57:51 +00:00
/** Represents a dynamic property. Type info added by deriving classes,
* see #TypedProperty.
Example:
@verbatim
P: "ShininessExponent", "double", "Number", "",0.5
@endvebatim
*/
2017-09-30 08:47:23 +00:00
class Property {
2012-07-02 13:57:51 +00:00
protected:
2015-05-19 03:57:13 +00:00
Property();
2012-07-02 13:57:51 +00:00
public:
2015-05-19 03:57:13 +00:00
virtual ~Property();
2012-07-02 13:57:51 +00:00
public:
2015-05-19 03:57:13 +00:00
template <typename T>
const T* As() const {
return dynamic_cast<const T*>(this);
}
2012-07-02 13:57:51 +00:00
};
template<typename T>
2017-09-30 08:47:23 +00:00
class TypedProperty : public Property {
2012-07-02 13:57:51 +00:00
public:
explicit TypedProperty(const T& value)
2017-09-30 08:47:23 +00:00
: value(value) {
// empty
2015-05-19 03:57:13 +00:00
}
2012-07-02 13:57:51 +00:00
2015-05-19 03:57:13 +00:00
const T& Value() const {
return value;
}
2012-07-02 13:57:51 +00:00
private:
2015-05-19 03:57:13 +00:00
T value;
2012-07-02 13:57:51 +00:00
};
typedef std::fbx_unordered_map<std::string,std::shared_ptr<Property> > DirectPropertyMap;
2017-09-30 08:47:23 +00:00
typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap;
typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap;
2012-07-02 13:57:51 +00:00
/**
* Represents a property table as can be found in the newer FBX files (Properties60, Properties70)
*/
2017-09-30 08:47:23 +00:00
class PropertyTable {
2012-07-02 13:57:51 +00:00
public:
2015-05-19 03:57:13 +00:00
// in-memory property table with no source element
PropertyTable();
PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps);
2015-05-19 03:57:13 +00:00
~PropertyTable();
2012-07-02 13:57:51 +00:00
2015-05-19 03:57:13 +00:00
const Property* Get(const std::string& name) const;
2012-07-02 13:57:51 +00:00
2015-05-19 03:57:13 +00:00
// PropertyTable's need not be coupled with FBX elements so this can be NULL
const Element* GetElement() const {
return element;
}
2012-07-02 13:57:51 +00:00
2015-05-19 03:57:13 +00:00
const PropertyTable* TemplateProps() const {
return templateProps.get();
}
2012-07-02 13:57:51 +00:00
2015-05-19 03:57:13 +00:00
DirectPropertyMap GetUnparsedProperties() const;
2012-07-02 13:57:51 +00:00
private:
2015-05-19 03:57:13 +00:00
LazyPropertyMap lazyProps;
mutable PropertyMap props;
const std::shared_ptr<const PropertyTable> templateProps;
2015-05-19 03:57:13 +00:00
const Element* const element;
2012-07-02 13:57:51 +00:00
};
// ------------------------------------------------------------------------------------------------
template <typename T>
inline
T PropertyGet(const PropertyTable& in, const std::string& name, const T& defaultValue) {
2015-05-19 03:57:13 +00:00
const Property* const prop = in.Get(name);
if( nullptr == prop) {
2015-05-19 03:57:13 +00:00
return defaultValue;
}
// strong typing, no need to be lenient
const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
if( nullptr == tprop) {
2015-05-19 03:57:13 +00:00
return defaultValue;
}
return tprop->Value();
}
// ------------------------------------------------------------------------------------------------
template <typename T>
inline
T PropertyGet(const PropertyTable& in, const std::string& name, bool& result) {
2015-05-19 03:57:13 +00:00
const Property* const prop = in.Get(name);
if( nullptr == prop) {
2015-05-19 03:57:13 +00:00
result = false;
return T();
}
// strong typing, no need to be lenient
const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
if( nullptr == tprop) {
2015-05-19 03:57:13 +00:00
result = false;
return T();
}
result = true;
return tprop->Value();
2012-07-02 13:57:51 +00:00
}
} //! FBX
} //! Assimp
#endif // INCLUDED_AI_FBX_PROPERTIES_H