2013-03-28 19:54:12 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2018-01-28 18:42:05 +00:00
|
|
|
Copyright (c) 2006-2018, assimp team
|
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2013-03-28 19:54:12 +00:00
|
|
|
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 04:17:45 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2013-03-28 19:54:12 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 04:17:45 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2013-03-28 19:54:12 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 04:17:45 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2013-03-28 19:54:12 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 04:17:45 +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
|
2013-03-28 19:54:12 +00:00
|
|
|
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.
|
|
|
|
*/
|
2016-07-11 18:56:38 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef AI_METADATA_H_INC
|
|
|
|
#define AI_METADATA_H_INC
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2014-04-30 02:58:19 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
|
2016-11-22 20:06:14 +00:00
|
|
|
# include "Compiler/pstdint.h"
|
2014-04-30 02:58:19 +00:00
|
|
|
#else
|
2016-11-22 20:06:14 +00:00
|
|
|
# include <stdint.h>
|
2014-04-30 02:58:19 +00:00
|
|
|
#endif
|
2014-03-14 13:17:34 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Enum used to distinguish data types
|
|
|
|
*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-11-22 20:06:14 +00:00
|
|
|
typedef enum aiMetadataType {
|
2016-10-04 20:58:51 +00:00
|
|
|
AI_BOOL = 0,
|
|
|
|
AI_INT32 = 1,
|
|
|
|
AI_UINT64 = 2,
|
|
|
|
AI_FLOAT = 3,
|
|
|
|
AI_DOUBLE = 4,
|
|
|
|
AI_AISTRING = 5,
|
2016-07-15 02:53:49 +00:00
|
|
|
AI_AIVECTOR3D = 6,
|
2018-03-20 13:10:08 +00:00
|
|
|
AI_META_MAX = 7,
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2014-03-24 10:24:27 +00:00
|
|
|
#ifndef SWIG
|
2015-05-19 04:18:29 +00:00
|
|
|
FORCE_32BIT = INT_MAX
|
2014-03-24 10:24:27 +00:00
|
|
|
#endif
|
2014-05-04 13:24:12 +00:00
|
|
|
} aiMetadataType;
|
2014-03-14 13:17:34 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Metadata entry
|
|
|
|
*
|
|
|
|
* The type field uniquely identifies the underlying type of the data field
|
|
|
|
*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-11-22 20:06:14 +00:00
|
|
|
struct aiMetadataEntry {
|
2015-05-19 04:18:29 +00:00
|
|
|
aiMetadataType mType;
|
|
|
|
void* mData;
|
2014-03-14 13:17:34 +00:00
|
|
|
};
|
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
#ifdef __cplusplus
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2014-03-14 16:12:22 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-03-14 13:17:34 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Helper functions to get the aiType enum entry for a type
|
|
|
|
*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
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; }
|
2016-12-26 12:43:45 +00:00
|
|
|
inline aiMetadataType GetAiType( const aiString & ) { return AI_AISTRING; }
|
|
|
|
inline aiMetadataType GetAiType( const aiVector3D & ) { return AI_AIVECTOR3D; }
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2016-11-06 18:36:37 +00:00
|
|
|
#endif // __cplusplus
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Container for holding metadata.
|
|
|
|
*
|
|
|
|
* Metadata is a key-value store using string keys and values.
|
|
|
|
*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-11-22 20:06:14 +00:00
|
|
|
struct aiMetadata {
|
2015-05-19 04:18:29 +00:00
|
|
|
/** Length of the mKeys and mValues arrays, respectively */
|
|
|
|
unsigned int mNumProperties;
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
/** Arrays of keys, may not be NULL. Entries in this array may not be NULL as well. */
|
|
|
|
C_STRUCT aiString* mKeys;
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
/** 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;
|
2013-03-28 19:54:12 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief The default constructor, set all members to zero by default.
|
|
|
|
*/
|
2018-09-21 14:25:27 +00:00
|
|
|
aiMetadata() AI_NO_EXCEPT
|
2016-11-22 20:06:14 +00:00
|
|
|
: mNumProperties(0)
|
2018-03-20 13:10:08 +00:00
|
|
|
, mKeys(nullptr)
|
|
|
|
, mValues(nullptr) {
|
2016-11-22 20:06:14 +00:00
|
|
|
// empty
|
|
|
|
}
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2018-03-20 13:10:08 +00:00
|
|
|
aiMetadata( const aiMetadata &rhs )
|
|
|
|
: mNumProperties( rhs.mNumProperties )
|
|
|
|
, mKeys( nullptr )
|
|
|
|
, mValues( nullptr ) {
|
|
|
|
mKeys = new aiString[ mNumProperties ];
|
2018-09-21 14:07:09 +00:00
|
|
|
for ( size_t i = 0; i < static_cast<size_t>( mNumProperties ); ++i ) {
|
2018-03-20 13:10:08 +00:00
|
|
|
mKeys[ i ] = rhs.mKeys[ i ];
|
|
|
|
}
|
|
|
|
mValues = new aiMetadataEntry[ mNumProperties ];
|
2018-09-21 14:07:09 +00:00
|
|
|
for ( size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i ) {
|
2018-03-20 13:10:08 +00:00
|
|
|
mValues[ i ].mType = rhs.mValues[ i ].mType;
|
|
|
|
switch ( rhs.mValues[ i ].mType ) {
|
|
|
|
case AI_BOOL:
|
2018-05-08 07:46:32 +00:00
|
|
|
mValues[ i ].mData = new bool;
|
|
|
|
::memcpy( mValues[ i ].mData, rhs.mValues[ i ].mData, sizeof(bool) );
|
2018-03-20 13:10:08 +00:00
|
|
|
break;
|
|
|
|
case AI_INT32: {
|
|
|
|
int32_t v;
|
|
|
|
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( int32_t ) );
|
|
|
|
mValues[ i ].mData = new int32_t( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AI_UINT64: {
|
|
|
|
uint64_t v;
|
|
|
|
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( uint64_t ) );
|
|
|
|
mValues[ i ].mData = new uint64_t( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AI_FLOAT: {
|
|
|
|
float v;
|
|
|
|
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( float ) );
|
|
|
|
mValues[ i ].mData = new float( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AI_DOUBLE: {
|
|
|
|
double v;
|
|
|
|
::memcpy( &v, rhs.mValues[ i ].mData, sizeof( double ) );
|
|
|
|
mValues[ i ].mData = new double( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AI_AISTRING: {
|
|
|
|
aiString v;
|
|
|
|
rhs.Get<aiString>( mKeys[ i ], v );
|
|
|
|
mValues[ i ].mData = new aiString( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AI_AIVECTOR3D: {
|
|
|
|
aiVector3D v;
|
|
|
|
rhs.Get<aiVector3D>( mKeys[ i ], v );
|
|
|
|
mValues[ i ].mData = new aiVector3D( v );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifndef SWIG
|
|
|
|
case FORCE_32BIT:
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief The destructor.
|
|
|
|
*/
|
|
|
|
~aiMetadata() {
|
|
|
|
delete [] mKeys;
|
2018-03-20 13:10:08 +00:00
|
|
|
mKeys = nullptr;
|
2016-11-22 20:06:14 +00:00
|
|
|
if (mValues) {
|
2015-05-19 04:18:29 +00:00
|
|
|
// Delete each metadata entry
|
2016-11-22 20:06:14 +00:00
|
|
|
for (unsigned i=0; i<mNumProperties; ++i) {
|
2015-05-19 04:18:29 +00:00
|
|
|
void* data = mValues[i].mData;
|
2016-11-22 20:06:14 +00:00
|
|
|
switch (mValues[i].mType) {
|
2015-05-19 04:18:29 +00:00
|
|
|
case AI_BOOL:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< bool* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
2016-10-04 20:58:51 +00:00
|
|
|
case AI_INT32:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< int32_t* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_UINT64:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< uint64_t* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_FLOAT:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< float* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
2016-07-15 02:53:49 +00:00
|
|
|
case AI_DOUBLE:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< double* >( data );
|
2016-07-15 02:53:49 +00:00
|
|
|
break;
|
2015-05-19 04:18:29 +00:00
|
|
|
case AI_AISTRING:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< aiString* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_AIVECTOR3D:
|
2018-03-20 13:10:08 +00:00
|
|
|
delete static_cast< aiVector3D* >( data );
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
2016-03-02 08:07:17 +00:00
|
|
|
#ifndef SWIG
|
|
|
|
case FORCE_32BIT:
|
|
|
|
#endif
|
2015-05-19 04:18:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the metadata array
|
|
|
|
delete [] mValues;
|
2018-03-20 13:10:08 +00:00
|
|
|
mValues = nullptr;
|
2015-05-19 04:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief Allocates property fields + keys.
|
|
|
|
* @param numProperties Number of requested properties.
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
aiMetadata *Alloc( unsigned int numProperties ) {
|
|
|
|
if ( 0 == numProperties ) {
|
2017-11-19 18:05:51 +00:00
|
|
|
return nullptr;
|
2016-11-22 20:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aiMetadata *data = new aiMetadata;
|
|
|
|
data->mNumProperties = numProperties;
|
|
|
|
data->mKeys = new aiString[ data->mNumProperties ]();
|
|
|
|
data->mValues = new aiMetadataEntry[ data->mNumProperties ]();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:35:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Deallocates property fields + keys.
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
void Dealloc( aiMetadata *metadata ) {
|
|
|
|
delete metadata;
|
|
|
|
}
|
|
|
|
|
2016-08-23 09:59:49 +00:00
|
|
|
template<typename T>
|
2018-03-20 13:10:08 +00:00
|
|
|
inline
|
|
|
|
void Add(const std::string& key, const T& value) {
|
2016-08-23 09:59:49 +00:00
|
|
|
aiString* new_keys = new aiString[mNumProperties + 1];
|
|
|
|
aiMetadataEntry* new_values = new aiMetadataEntry[mNumProperties + 1];
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2016-08-23 09:59:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
template<typename T>
|
2016-11-22 20:06:14 +00:00
|
|
|
inline
|
|
|
|
bool Set( unsigned index, const std::string& key, const T& value ) {
|
2015-05-19 04:18:29 +00:00
|
|
|
// In range assertion
|
2016-11-21 22:54:39 +00:00
|
|
|
if ( index >= mNumProperties ) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
// Ensure that we have a valid key.
|
|
|
|
if ( key.empty() ) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
// Set metadata key
|
|
|
|
mKeys[index] = key;
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
// Set metadata type
|
|
|
|
mValues[index].mType = GetAiType(value);
|
|
|
|
// Copy the given value to the dynamic storage
|
|
|
|
mValues[index].mData = new T(value);
|
2016-11-21 22:54:39 +00:00
|
|
|
|
|
|
|
return true;
|
2015-05-19 04:18:29 +00:00
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
template<typename T>
|
2016-11-22 20:06:14 +00:00
|
|
|
inline
|
2018-03-20 13:10:08 +00:00
|
|
|
bool Get( unsigned index, T& value ) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
// In range assertion
|
2016-11-21 22:54:39 +00:00
|
|
|
if ( index >= mNumProperties ) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-15 07:37:45 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
// Return false if the output data type does
|
|
|
|
// not match the found value's data type
|
2014-03-27 19:33:08 +00:00
|
|
|
if ( GetAiType( value ) != mValues[ index ].mType ) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
// Otherwise, output the found value and
|
|
|
|
// return true
|
|
|
|
value = *static_cast<T*>(mValues[index].mData);
|
2016-11-22 20:06:14 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2016-11-21 22:54:39 +00:00
|
|
|
inline
|
2018-03-20 13:10:08 +00:00
|
|
|
bool Get( const aiString& key, T& value ) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
// Search for the given key
|
2016-11-22 20:06:14 +00:00
|
|
|
for ( unsigned int i = 0; i < mNumProperties; ++i ) {
|
|
|
|
if ( mKeys[ i ] == key ) {
|
|
|
|
return Get( i, value );
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 04:18:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2018-03-20 13:10:08 +00:00
|
|
|
inline
|
|
|
|
bool Get( const std::string& key, T& value ) const {
|
2015-05-19 04:17:45 +00:00
|
|
|
return Get(aiString(key), value);
|
2014-03-27 19:33:08 +00:00
|
|
|
}
|
2014-03-14 16:12:22 +00:00
|
|
|
|
2016-10-04 20:58:51 +00:00
|
|
|
/// 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.
|
2018-03-20 13:10:08 +00:00
|
|
|
inline
|
|
|
|
bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) const {
|
2016-11-22 20:06:14 +00:00
|
|
|
if ( index >= mNumProperties ) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-04 20:58:51 +00:00
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
key = &mKeys[index];
|
|
|
|
entry = &mValues[index];
|
2016-10-04 20:58:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
#endif // __cplusplus
|
2014-03-27 19:33:08 +00:00
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
};
|
|
|
|
|
2016-07-11 18:56:38 +00:00
|
|
|
#endif // AI_METADATA_H_INC
|