diff options
Diffstat (limited to 'src/3rdparty/assimp/include/assimp/metadata.h')
-rw-r--r-- | src/3rdparty/assimp/include/assimp/metadata.h | 207 |
1 files changed, 135 insertions, 72 deletions
diff --git a/src/3rdparty/assimp/include/assimp/metadata.h b/src/3rdparty/assimp/include/assimp/metadata.h index 579ccd446..92db9b59a 100644 --- a/src/3rdparty/assimp/include/assimp/metadata.h +++ b/src/3rdparty/assimp/include/assimp/metadata.h @@ -3,7 +3,8 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2016, assimp team +Copyright (c) 2006-2017, assimp team + All rights reserved. @@ -42,41 +43,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file metadata.h * @brief Defines the data structures for holding node meta information. */ -#ifndef __AI_METADATA_H_INC__ -#define __AI_METADATA_H_INC__ - -#include <assert.h> +#pragma once +#ifndef AI_METADATA_H_INC +#define AI_METADATA_H_INC #if defined(_MSC_VER) && (_MSC_VER <= 1500) -#include "Compiler/pstdint.h" +# include "Compiler/pstdint.h" #else -#include <limits.h> -#include <stdint.h> +# include <stdint.h> #endif - - // ------------------------------------------------------------------------------- /** * Enum used to distinguish data types */ // ------------------------------------------------------------------------------- -typedef enum aiMetadataType -{ - AI_BOOL = 0, - AI_INT = 1, - AI_UINT64 = 2, - AI_FLOAT = 3, - AI_AISTRING = 4, - AI_AIVECTOR3D = 5, +typedef enum aiMetadataType { + AI_BOOL = 0, + AI_INT32 = 1, + AI_UINT64 = 2, + AI_FLOAT = 3, + AI_DOUBLE = 4, + AI_AISTRING = 5, + AI_AIVECTOR3D = 6, #ifndef SWIG FORCE_32BIT = INT_MAX #endif } aiMetadataType; - - // ------------------------------------------------------------------------------- /** * Metadata entry @@ -84,37 +79,30 @@ typedef enum aiMetadataType * The type field uniquely identifies the underlying type of the data field */ // ------------------------------------------------------------------------------- -struct aiMetadataEntry -{ +struct aiMetadataEntry { aiMetadataType mType; void* mData; }; - - #ifdef __cplusplus #include <string> - - // ------------------------------------------------------------------------------- /** * Helper functions to get the aiType enum entry for a type */ // ------------------------------------------------------------------------------- -inline aiMetadataType GetAiType( bool ) { return AI_BOOL; } -inline aiMetadataType GetAiType( int ) { return AI_INT; } -inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; } -inline aiMetadataType GetAiType( float ) { return AI_FLOAT; } -inline aiMetadataType GetAiType( const aiString & ) { return AI_AISTRING; } -inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; } - - - -#endif +inline aiMetadataType GetAiType( bool ) { return AI_BOOL; } +inline aiMetadataType GetAiType( int32_t ) { return AI_INT32; } +inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; } +inline aiMetadataType GetAiType( float ) { return AI_FLOAT; } +inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; } +inline aiMetadataType GetAiType( const aiString & ) { return AI_AISTRING; } +inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; } +#endif // __cplusplus // ------------------------------------------------------------------------------- /** @@ -123,8 +111,7 @@ inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; } * Metadata is a key-value store using string keys and values. */ // ------------------------------------------------------------------------------- -struct aiMetadata -{ +struct aiMetadata { /** Length of the mKeys and mValues arrays, respectively */ unsigned int mNumProperties; @@ -137,33 +124,32 @@ struct aiMetadata #ifdef __cplusplus - /** Constructor */ + /** + * @brief The default constructor, set all members to zero by default. + */ aiMetadata() - // set all members to zero by default - : mNumProperties(0) - , mKeys(NULL) - , mValues(NULL) - {} - + : mNumProperties(0) + , mKeys(NULL) + , mValues(NULL) { + // empty + } - /** Destructor */ - ~aiMetadata() - { - delete[] mKeys; + /** + * @brief The destructor. + */ + ~aiMetadata() { + delete [] mKeys; mKeys = NULL; - if (mValues) - { + if (mValues) { // Delete each metadata entry - for (unsigned i=0; i<mNumProperties; ++i) - { + for (unsigned i=0; i<mNumProperties; ++i) { void* data = mValues[i].mData; - switch (mValues[i].mType) - { + switch (mValues[i].mType) { case AI_BOOL: delete static_cast<bool*>(data); break; - case AI_INT: - delete static_cast<int*>(data); + case AI_INT32: + delete static_cast<int32_t*>(data); break; case AI_UINT64: delete static_cast<uint64_t*>(data); @@ -171,6 +157,9 @@ struct aiMetadata case AI_FLOAT: delete static_cast<float*>(data); break; + case AI_DOUBLE: + delete static_cast<double*>(data); + break; case AI_AISTRING: delete static_cast<aiString*>(data); break; @@ -181,7 +170,6 @@ struct aiMetadata case FORCE_32BIT: #endif default: - assert(false); break; } } @@ -192,13 +180,67 @@ struct aiMetadata } } + /** + * @brief Allocates property fields + keys. + * @param numProperties Number of requested properties. + */ + static inline + aiMetadata *Alloc( unsigned int numProperties ) { + if ( 0 == numProperties ) { + return nullptr; + } + + aiMetadata *data = new aiMetadata; + data->mNumProperties = numProperties; + data->mKeys = new aiString[ data->mNumProperties ](); + data->mValues = new aiMetadataEntry[ data->mNumProperties ](); + + return data; + } + + /** + * @brief Deallocates property fields + keys. + */ + static inline + void Dealloc( aiMetadata *metadata ) { + delete metadata; + } + + template<typename T> + inline void Add(const std::string& key, const T& value) + { + aiString* new_keys = new aiString[mNumProperties + 1]; + aiMetadataEntry* new_values = new aiMetadataEntry[mNumProperties + 1]; + + for(unsigned int i = 0; i < mNumProperties; ++i) + { + new_keys[i] = mKeys[i]; + new_values[i] = mValues[i]; + } + + delete mKeys; + delete mValues; + mKeys = new_keys; + mValues = new_values; + + mNumProperties++; + + Set(mNumProperties - 1, key, value); + } template<typename T> - inline void Set( unsigned index, const std::string& key, const T& value ) - { + inline + bool Set( unsigned index, const std::string& key, const T& value ) { // In range assertion - assert(index < mNumProperties); + if ( index >= mNumProperties ) { + return false; + } + + // Ensure that we have a valid key. + if ( key.empty() ) { + return false; + } // Set metadata key mKeys[index] = key; @@ -207,13 +249,17 @@ struct aiMetadata mValues[index].mType = GetAiType(value); // Copy the given value to the dynamic storage mValues[index].mData = new T(value); + + return true; } template<typename T> - inline bool Get( unsigned index, T& value ) - { + inline + bool Get( unsigned index, T& value ) { // In range assertion - assert(index < mNumProperties); + if ( index >= mNumProperties ) { + return false; + } // Return false if the output data type does // not match the found value's data type @@ -224,16 +270,19 @@ struct aiMetadata // Otherwise, output the found value and // return true value = *static_cast<T*>(mValues[index].mData); + return true; } template<typename T> - inline bool Get( const aiString& key, T& value ) - { + inline + bool Get( const aiString& key, T& value ) { // Search for the given key - for (unsigned i=0; i<mNumProperties; ++i) - if (mKeys[i]==key) - return Get(i, value); + for ( unsigned int i = 0; i < mNumProperties; ++i ) { + if ( mKeys[ i ] == key ) { + return Get( i, value ); + } + } return false; } @@ -242,10 +291,24 @@ struct aiMetadata return Get(aiString(key), value); } -#endif // __cplusplus + /// Return metadata entry for analyzing it by user. + /// \param [in] pIndex - index of the entry. + /// \param [out] pKey - pointer to the key value. + /// \param [out] pEntry - pointer to the entry: type and value. + /// \return false - if pIndex is out of range, else - true. + inline bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) { + if ( index >= mNumProperties ) { + return false; + } -}; + key = &mKeys[index]; + entry = &mValues[index]; -#endif // __AI_METADATA_H_INC__ + return true; + } +#endif // __cplusplus + +}; +#endif // AI_METADATA_H_INC |