From 595529ef8bc6fe20e7b708f2e09e4b81d1f6d31e Mon Sep 17 00:00:00 2001 From: Frederik Aalund Date: Sat, 15 Mar 2014 08:37:45 +0100 Subject: [PATCH] Refactored the metadata for inner consistency. --- code/FBXConverter.cpp | 2 +- code/IFCLoader.cpp | 2 +- include/assimp/metadata.h | 37 ++++++++++++++++++++----------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index b0f4bf823..d08dc3dce 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -760,7 +760,7 @@ private: aiMetadata* data = new aiMetadata(); data->mNumProperties = unparsedProperties.size() + numStaticMetaData; data->mKeys = new aiString[data->mNumProperties](); - data->mValues = new aiMetaDataEntry[data->mNumProperties](); + data->mValues = new aiMetadataEntry[data->mNumProperties](); nd.mMetaData = data; int index = 0; diff --git a/code/IFCLoader.cpp b/code/IFCLoader.cpp index a00f2c9e7..9a5f79a5a 100644 --- a/code/IFCLoader.cpp +++ b/code/IFCLoader.cpp @@ -726,7 +726,7 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion aiMetadata* data = new aiMetadata(); data->mNumProperties = properties.size(); data->mKeys = new aiString[data->mNumProperties](); - data->mValues = new aiMetaDataEntry[data->mNumProperties](); + data->mValues = new aiMetadataEntry[data->mNumProperties](); unsigned int index = 0; BOOST_FOREACH(const Metadata::value_type& kv, properties) diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index 5bbc38bd4..f69f73ae2 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Enum used to distinguish data types */ // ------------------------------------------------------------------------------- -enum aiType +enum aiMetadataType { AI_BOOL = 0, AI_INT = 1, @@ -76,10 +76,10 @@ enum aiType * The type field uniquely identifies the underlying type of the data field */ // ------------------------------------------------------------------------------- -struct aiMetaDataEntry +struct aiMetadataEntry { - aiType type; - void* data; + aiMetadataType mType; + void* mData; }; @@ -95,12 +95,12 @@ struct aiMetaDataEntry * Helper functions to get the aiType enum entry for a type */ // ------------------------------------------------------------------------------- -inline aiType GetAiType( bool ) { return AI_BOOL; } -inline aiType GetAiType( int ) { return AI_INT; } -inline aiType GetAiType( uint64_t ) { return AI_UINT64; } -inline aiType GetAiType( float ) { return AI_FLOAT; } -inline aiType GetAiType( aiString ) { return AI_AISTRING; } -inline aiType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } +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( aiString ) { return AI_AISTRING; } +inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } @@ -125,7 +125,7 @@ struct aiMetadata /** Arrays of values, may not be NULL. Entries in this array may be NULL if the * corresponding property key has no assigned value. */ - C_STRUCT aiMetaDataEntry* mValues; + C_STRUCT aiMetadataEntry* mValues; #ifdef __cplusplus @@ -148,8 +148,8 @@ struct aiMetadata // Delete each metadata entry for (unsigned i=0; i(data); @@ -193,22 +193,25 @@ struct aiMetadata mKeys[index] = key; // Set metadata type - mValues[index].type = GetAiType(value); + mValues[index].mType = GetAiType(value); // Copy the given value to the dynamic storage - mValues[index].data = new T(value); + mValues[index].mData = new T(value); } template inline bool Get( unsigned index, T& value ) { + // In range assertion + assert(index < mNumProperties); + // Return false if the output data type does // not match the found value's data type - if (GetAiType(value) != mValues[index].type) + if (GetAiType(value) != mValues[index].mType) return false; // Otherwise, output the found value and // return true - value = *static_cast(mValues[index].data); + value = *static_cast(mValues[index].mData); return true; }