2013-03-28 19:54:12 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +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
|
|
|
|
2019-10-11 11:27:36 +00:00
|
|
|
#ifdef __GNUC__
|
2020-04-06 09:16:16 +00:00
|
|
|
#pragma GCC system_header
|
2019-10-11 11:27:36 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-30 02:58:19 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
|
2020-04-06 09:16:16 +00:00
|
|
|
#include "Compiler/pstdint.h"
|
2014-04-30 02:58:19 +00:00
|
|
|
#else
|
2020-04-06 09:16:16 +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
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
2016-11-22 20:06:14 +00:00
|
|
|
typedef enum aiMetadataType {
|
2020-04-06 09:16:16 +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,
|
2020-06-26 04:26:45 +00:00
|
|
|
AI_AIMETADATA = 7,
|
|
|
|
AI_META_MAX = 8,
|
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
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
2016-11-22 20:06:14 +00:00
|
|
|
struct aiMetadataEntry {
|
2015-05-19 04:18:29 +00:00
|
|
|
aiMetadataType mType;
|
2020-04-06 09:16:16 +00:00
|
|
|
void *mData;
|
2020-05-04 18:40:08 +00:00
|
|
|
|
2020-05-04 18:50:44 +00:00
|
|
|
#ifdef __cplusplus
|
2020-05-04 18:40:08 +00:00
|
|
|
aiMetadataEntry() :
|
|
|
|
mType(AI_META_MAX),
|
|
|
|
mData( nullptr ) {
|
|
|
|
// empty
|
|
|
|
}
|
2020-05-04 18:50:44 +00:00
|
|
|
#endif
|
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>
|
|
|
|
|
2020-06-26 04:26:45 +00:00
|
|
|
struct aiMetadata;
|
|
|
|
|
2014-03-14 13:17:34 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* Helper functions to get the aiType enum entry for a type
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2020-04-06 09:16:16 +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;
|
|
|
|
}
|
|
|
|
inline aiMetadataType GetAiType(const aiString &) {
|
|
|
|
return AI_AISTRING;
|
|
|
|
}
|
|
|
|
inline aiMetadataType GetAiType(const aiVector3D &) {
|
|
|
|
return AI_AIVECTOR3D;
|
|
|
|
}
|
2020-06-26 04:26:45 +00:00
|
|
|
inline aiMetadataType GetAiType(const aiMetadata &) {
|
|
|
|
return AI_AIMETADATA;
|
|
|
|
}
|
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.
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
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. */
|
2020-04-06 09:16:16 +00:00
|
|
|
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. */
|
2020-04-06 09:16:16 +00:00
|
|
|
C_STRUCT aiMetadataEntry *mValues;
|
2013-03-28 19:54:12 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2021-05-26 09:11:19 +00:00
|
|
|
/**
|
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
|
2020-04-06 09:16:16 +00:00
|
|
|
: mNumProperties(0),
|
|
|
|
mKeys(nullptr),
|
|
|
|
mValues(nullptr) {
|
2016-11-22 20:06:14 +00:00
|
|
|
// empty
|
|
|
|
}
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
aiMetadata(const aiMetadata &rhs) :
|
|
|
|
mNumProperties(rhs.mNumProperties), mKeys(nullptr), mValues(nullptr) {
|
|
|
|
mKeys = new aiString[mNumProperties];
|
|
|
|
for (size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i) {
|
|
|
|
mKeys[i] = rhs.mKeys[i];
|
2018-03-20 13:10:08 +00:00
|
|
|
}
|
2020-04-06 09:16:16 +00:00
|
|
|
mValues = new aiMetadataEntry[mNumProperties];
|
|
|
|
for (size_t i = 0; i < static_cast<size_t>(mNumProperties); ++i) {
|
|
|
|
mValues[i].mType = rhs.mValues[i].mType;
|
|
|
|
switch (rhs.mValues[i].mType) {
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_BOOL:
|
2020-04-06 09:16:16 +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;
|
2020-04-06 09:16:16 +00:00
|
|
|
::memcpy(&v, rhs.mValues[i].mData, sizeof(int32_t));
|
|
|
|
mValues[i].mData = new int32_t(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_UINT64: {
|
2020-04-06 09:16:16 +00:00
|
|
|
uint64_t v;
|
|
|
|
::memcpy(&v, rhs.mValues[i].mData, sizeof(uint64_t));
|
|
|
|
mValues[i].mData = new uint64_t(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_FLOAT: {
|
2020-04-06 09:16:16 +00:00
|
|
|
float v;
|
|
|
|
::memcpy(&v, rhs.mValues[i].mData, sizeof(float));
|
|
|
|
mValues[i].mData = new float(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_DOUBLE: {
|
2020-04-06 09:16:16 +00:00
|
|
|
double v;
|
|
|
|
::memcpy(&v, rhs.mValues[i].mData, sizeof(double));
|
|
|
|
mValues[i].mData = new double(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_AISTRING: {
|
2020-04-06 09:16:16 +00:00
|
|
|
aiString v;
|
2021-05-26 09:11:19 +00:00
|
|
|
rhs.Get<aiString>(static_cast<unsigned int>(i), v);
|
2020-04-06 09:16:16 +00:00
|
|
|
mValues[i].mData = new aiString(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
case AI_AIVECTOR3D: {
|
2020-04-06 09:16:16 +00:00
|
|
|
aiVector3D v;
|
2021-05-26 09:11:19 +00:00
|
|
|
rhs.Get<aiVector3D>(static_cast<unsigned int>(i), v);
|
2020-04-06 09:16:16 +00:00
|
|
|
mValues[i].mData = new aiVector3D(v);
|
|
|
|
} break;
|
2020-06-26 04:26:45 +00:00
|
|
|
case AI_AIMETADATA: {
|
|
|
|
aiMetadata v;
|
2021-05-26 09:11:19 +00:00
|
|
|
rhs.Get<aiMetadata>(static_cast<unsigned int>(i), v);
|
2020-06-26 04:26:45 +00:00
|
|
|
mValues[i].mData = new aiMetadata(v);
|
|
|
|
} break;
|
2018-03-20 13:10:08 +00:00
|
|
|
#ifndef SWIG
|
|
|
|
case FORCE_32BIT:
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 04:26:45 +00:00
|
|
|
aiMetadata &operator=(aiMetadata rhs) {
|
|
|
|
using std::swap;
|
|
|
|
swap(mNumProperties, rhs.mNumProperties);
|
|
|
|
swap(mKeys, rhs.mKeys);
|
|
|
|
swap(mValues, rhs.mValues);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-22 20:06:14 +00:00
|
|
|
* @brief The destructor.
|
|
|
|
*/
|
|
|
|
~aiMetadata() {
|
2020-04-06 09:16:16 +00:00
|
|
|
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
|
2020-04-06 09:16:16 +00:00
|
|
|
for (unsigned i = 0; i < mNumProperties; ++i) {
|
|
|
|
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:
|
2020-04-06 09:16:16 +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:
|
2020-04-06 09:16:16 +00:00
|
|
|
delete static_cast<int32_t *>(data);
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_UINT64:
|
2020-04-06 09:16:16 +00:00
|
|
|
delete static_cast<uint64_t *>(data);
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_FLOAT:
|
2020-04-06 09:16:16 +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:
|
2020-04-06 09:16:16 +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:
|
2020-04-06 09:16:16 +00:00
|
|
|
delete static_cast<aiString *>(data);
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
|
|
|
case AI_AIVECTOR3D:
|
2020-04-06 09:16:16 +00:00
|
|
|
delete static_cast<aiVector3D *>(data);
|
2015-05-19 04:18:29 +00:00
|
|
|
break;
|
2020-06-26 04:26:45 +00:00
|
|
|
case AI_AIMETADATA:
|
|
|
|
delete static_cast<aiMetadata *>(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
|
2020-04-06 09:16:16 +00:00
|
|
|
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.
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
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;
|
2020-04-06 09:16:16 +00:00
|
|
|
data->mKeys = new aiString[data->mNumProperties]();
|
|
|
|
data->mValues = new aiMetadataEntry[data->mNumProperties]();
|
2016-11-22 20:06:14 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:35:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Deallocates property fields + keys.
|
|
|
|
*/
|
2020-04-06 09:16:16 +00:00
|
|
|
static inline void Dealloc(aiMetadata *metadata) {
|
2017-05-25 20:35:27 +00:00
|
|
|
delete metadata;
|
|
|
|
}
|
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
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];
|
2013-03-28 19:54:12 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
|
|
|
new_keys[i] = mKeys[i];
|
|
|
|
new_values[i] = mValues[i];
|
|
|
|
}
|
2016-08-23 09:59:49 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
delete[] mKeys;
|
|
|
|
delete[] mValues;
|
2016-08-23 09:59:49 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
mKeys = new_keys;
|
|
|
|
mValues = new_values;
|
2016-08-23 09:59:49 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
mNumProperties++;
|
2016-08-23 09:59:49 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
Set(mNumProperties - 1, key, value);
|
|
|
|
}
|
2014-03-14 13:17:34 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
template <typename T>
|
|
|
|
inline bool Set(unsigned index, const std::string &key, const T &value) {
|
2015-05-19 04:18:29 +00:00
|
|
|
// In range assertion
|
2020-04-06 09:16:16 +00:00
|
|
|
if (index >= mNumProperties) {
|
2016-11-21 22:54:39 +00:00
|
|
|
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.
|
2020-04-06 09:16:16 +00:00
|
|
|
if (key.empty()) {
|
2016-11-22 20:06:14 +00:00
|
|
|
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);
|
2020-05-04 13:36:54 +00:00
|
|
|
|
2015-05-19 04:18:29 +00:00
|
|
|
// Copy the given value to the dynamic storage
|
2020-06-26 04:26:45 +00:00
|
|
|
if (nullptr != mValues[index].mData && AI_AIMETADATA != mValues[index].mType) {
|
2020-05-04 13:36:54 +00:00
|
|
|
::memcpy(mValues[index].mData, &value, sizeof(T));
|
2020-06-26 04:26:45 +00:00
|
|
|
} else if (nullptr != mValues[index].mData && AI_AIMETADATA == mValues[index].mType) {
|
|
|
|
*static_cast<T *>(mValues[index].mData) = value;
|
2020-05-04 13:36:54 +00:00
|
|
|
} else {
|
2021-01-29 19:25:02 +00:00
|
|
|
if (nullptr != mValues[index].mData) {
|
2021-03-04 06:30:36 +00:00
|
|
|
delete static_cast<T *>(mValues[index].mData);
|
2021-01-29 19:25:02 +00:00
|
|
|
mValues[index].mData = nullptr;
|
|
|
|
}
|
2020-05-04 13:36:54 +00:00
|
|
|
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
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
template <typename T>
|
2020-04-29 19:13:46 +00:00
|
|
|
inline bool Set(const std::string &key, const T &value) {
|
2020-04-06 09:16:16 +00:00
|
|
|
if (key.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
|
|
|
if (key == mKeys[i].C_Str()) {
|
|
|
|
Set(i, key, value);
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool Get(unsigned index, T &value) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
// In range assertion
|
2020-04-06 09:16:16 +00:00
|
|
|
if (index >= mNumProperties) {
|
2016-11-21 22:54:39 +00:00
|
|
|
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
|
2020-04-06 09:16:16 +00:00
|
|
|
if (GetAiType(value) != mValues[index].mType) {
|
2014-03-27 19:33:08 +00:00
|
|
|
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
|
2020-04-06 09:16:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
template <typename T>
|
|
|
|
inline bool Get(const aiString &key, T &value) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
// Search for the given key
|
2020-04-06 09:16:16 +00:00
|
|
|
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
|
|
|
if (mKeys[i] == key) {
|
|
|
|
return Get(i, value);
|
2016-11-22 20:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 04:18:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
template <typename T>
|
|
|
|
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
|
|
|
|
2020-04-06 09:16:16 +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.
|
|
|
|
inline bool Get(size_t index, const aiString *&key, const aiMetadataEntry *&entry) const {
|
|
|
|
if (index >= mNumProperties) {
|
2016-11-22 20:06:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-04 20:58:51 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
key = &mKeys[index];
|
|
|
|
entry = &mValues[index];
|
2016-10-04 20:58:51 +00:00
|
|
|
|
2020-04-06 09:16:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-04 20:58:51 +00:00
|
|
|
|
2019-12-05 11:25:12 +00:00
|
|
|
/// Check whether there is a metadata entry for the given key.
|
|
|
|
/// \param [in] Key - the key value value to check for.
|
2021-06-14 02:21:29 +00:00
|
|
|
inline bool HasKey(const char *key) const {
|
2020-04-06 09:16:16 +00:00
|
|
|
if (nullptr == key) {
|
2019-12-06 20:24:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-04-06 09:16:16 +00:00
|
|
|
|
2019-12-05 11:25:12 +00:00
|
|
|
// Search for the given key
|
|
|
|
for (unsigned int i = 0; i < mNumProperties; ++i) {
|
2020-04-06 09:16:16 +00:00
|
|
|
if (0 == strncmp(mKeys[i].C_Str(), key, mKeys[i].length)) {
|
2019-12-05 11:25:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-26 05:07:42 +00:00
|
|
|
friend bool CompareKeys(const aiMetadata &lhs, const aiMetadata &rhs) {
|
|
|
|
if (lhs.mNumProperties != rhs.mNumProperties) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < lhs.mNumProperties; ++i) {
|
|
|
|
if (lhs.mKeys[i] != rhs.mKeys[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool CompareValues(const aiMetadata &lhs, const aiMetadata &rhs) {
|
|
|
|
if (lhs.mNumProperties != rhs.mNumProperties) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < lhs.mNumProperties; ++i) {
|
|
|
|
if (lhs.mValues[i].mType != rhs.mValues[i].mType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (lhs.mValues[i].mType) {
|
|
|
|
case AI_BOOL: {
|
|
|
|
if (*static_cast<bool *>(lhs.mValues[i].mData) != *static_cast<bool *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_INT32: {
|
|
|
|
if (*static_cast<int32_t *>(lhs.mValues[i].mData) != *static_cast<int32_t *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_UINT64: {
|
|
|
|
if (*static_cast<uint64_t *>(lhs.mValues[i].mData) != *static_cast<uint64_t *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_FLOAT: {
|
|
|
|
if (*static_cast<float *>(lhs.mValues[i].mData) != *static_cast<float *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_DOUBLE: {
|
|
|
|
if (*static_cast<double *>(lhs.mValues[i].mData) != *static_cast<double *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_AISTRING: {
|
|
|
|
if (*static_cast<aiString *>(lhs.mValues[i].mData) != *static_cast<aiString *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_AIVECTOR3D: {
|
|
|
|
if (*static_cast<aiVector3D *>(lhs.mValues[i].mData) != *static_cast<aiVector3D *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case AI_AIMETADATA: {
|
|
|
|
if (*static_cast<aiMetadata *>(lhs.mValues[i].mData) != *static_cast<aiMetadata *>(rhs.mValues[i].mData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
#ifndef SWIG
|
|
|
|
case FORCE_32BIT:
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const aiMetadata &lhs, const aiMetadata &rhs) {
|
|
|
|
return CompareKeys(lhs, rhs) && CompareValues(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const aiMetadata &lhs, const aiMetadata &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2013-03-28 19:54:12 +00:00
|
|
|
#endif // __cplusplus
|
|
|
|
};
|
|
|
|
|
2016-07-11 18:56:38 +00:00
|
|
|
#endif // AI_METADATA_H_INC
|