2013-03-28 19:54:12 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2016-01-01 20:08:28 +00:00
|
|
|
Copyright (c) 2006-2016, assimp team
|
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,
|
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.
|
|
|
|
*/
|
2015-05-19 04:18:29 +00:00
|
|
|
aiMetadata()
|
2016-11-22 20:06:14 +00:00
|
|
|
: mNumProperties(0)
|
|
|
|
, mKeys(NULL)
|
|
|
|
, mValues(NULL) {
|
|
|
|
// empty
|
|
|
|
}
|
2013-03-28 19:54:12 +00:00
|
|
|
|
|
|
|
|
2016-11-22 20:06:14 +00:00
|
|
|
/**
|
|
|
|
* @brief The destructor.
|
|
|
|
*/
|
|
|
|
~aiMetadata() {
|
|
|
|
delete [] mKeys;
|
2014-03-27 19:33:08 +00:00
|
|
|
mKeys = NULL;
|
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:
|
|
|
|
delete static_cast<bool*>(data);
|
|
|
|
break;
|
2016-10-04 20:58:51 +00:00
|
|
|
case AI_INT32:
|
|
|
|
delete static_cast<int32_t*>(data);
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_UINT64:
|
|
|
|
delete static_cast<uint64_t*>(data);
|
|
|
|
break;
|
|
|
|
case AI_FLOAT:
|
|
|
|
delete static_cast<float*>(data);
|
|
|
|
break;
|
2016-07-15 02:53:49 +00:00
|
|
|
case AI_DOUBLE:
|
|
|
|
delete static_cast<double*>(data);
|
|
|
|
break;
|
2015-05-19 04:18:29 +00:00
|
|
|
case AI_AISTRING:
|
|
|
|
delete static_cast<aiString*>(data);
|
|
|
|
break;
|
|
|
|
case AI_AIVECTOR3D:
|
|
|
|
delete static_cast<aiVector3D*>(data);
|
|
|
|
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;
|
2014-03-27 19:33:08 +00:00
|
|
|
mValues = NULL;
|
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 ) {
|
2016-12-20 16:27:36 +00:00
|
|
|
return NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
bool Get( unsigned index, 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-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
|
2016-11-22 20:06:14 +00:00
|
|
|
bool Get( const aiString& key, T& value ) {
|
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>
|
|
|
|
inline bool Get( const std::string& key, T& value ) {
|
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.
|
2016-11-22 20:06:14 +00:00
|
|
|
inline bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) {
|
|
|
|
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
|