Merge pull request #1074 from assimp/testsuite_aiMetadata
Ue new alloc semantic when using aiMetadata + increase test coverage.pull/1077/head
commit
61e974f767
|
@ -336,25 +336,21 @@ auto texmap_is_equal = [](const CAMFImporter_NodeElement_TexMap* pTexMap1, const
|
||||||
} while(pInputList.size() > 0);
|
} while(pInputList.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeElement_Metadata*>& pMetadataList, aiNode& pSceneNode) const
|
void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeElement_Metadata*>& metadataList, aiNode& sceneNode) const
|
||||||
{
|
{
|
||||||
if(pMetadataList.size() > 0)
|
if ( !metadataList.empty() )
|
||||||
{
|
{
|
||||||
if(pSceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
if(sceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
||||||
|
|
||||||
// copy collected metadata to output node.
|
// copy collected metadata to output node.
|
||||||
pSceneNode.mMetaData = new aiMetadata();
|
sceneNode.mMetaData = aiMetadata::Alloc( metadataList.size() );
|
||||||
pSceneNode.mMetaData->mNumProperties = pMetadataList.size();
|
size_t meta_idx( 0 );
|
||||||
pSceneNode.mMetaData->mKeys = new aiString[pSceneNode.mMetaData->mNumProperties];
|
|
||||||
pSceneNode.mMetaData->mValues = new aiMetadataEntry[pSceneNode.mMetaData->mNumProperties];
|
|
||||||
|
|
||||||
size_t meta_idx = 0;
|
for(const CAMFImporter_NodeElement_Metadata& metadata: metadataList)
|
||||||
|
|
||||||
for(const CAMFImporter_NodeElement_Metadata& metadata: pMetadataList)
|
|
||||||
{
|
{
|
||||||
pSceneNode.mMetaData->Set(meta_idx++, metadata.Type, aiString(metadata.Value));
|
sceneNode.mMetaData->Set(meta_idx++, metadata.Type, aiString(metadata.Value));
|
||||||
}
|
}
|
||||||
}// if(pMetadataList.size() > 0)
|
}// if(!metadataList.empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode)
|
void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode)
|
||||||
|
|
|
@ -1075,10 +1075,7 @@ void Converter::SetupNodeMetadata( const Model& model, aiNode& nd )
|
||||||
|
|
||||||
// create metadata on node
|
// create metadata on node
|
||||||
std::size_t numStaticMetaData = 2;
|
std::size_t numStaticMetaData = 2;
|
||||||
aiMetadata* data = new aiMetadata();
|
aiMetadata* data = aiMetadata::Alloc( unparsedProperties.size() + numStaticMetaData );
|
||||||
data->mNumProperties = unparsedProperties.size() + numStaticMetaData;
|
|
||||||
data->mKeys = new aiString[ data->mNumProperties ]();
|
|
||||||
data->mValues = new aiMetadataEntry[ data->mNumProperties ]();
|
|
||||||
nd.mMetaData = data;
|
nd.mMetaData = data;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
|
@ -1089,22 +1086,22 @@ void Converter::SetupNodeMetadata( const Model& model, aiNode& nd )
|
||||||
|
|
||||||
// add unparsed properties to the node's metadata
|
// add unparsed properties to the node's metadata
|
||||||
for( const DirectPropertyMap::value_type& prop : unparsedProperties ) {
|
for( const DirectPropertyMap::value_type& prop : unparsedProperties ) {
|
||||||
|
|
||||||
// Interpret the property as a concrete type
|
// Interpret the property as a concrete type
|
||||||
if ( const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >() )
|
if ( const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >() ) {
|
||||||
data->Set( index++, prop.first, interpreted->Value() );
|
data->Set( index++, prop.first, interpreted->Value() );
|
||||||
else if ( const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >() )
|
} else if ( const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >() ) {
|
||||||
data->Set( index++, prop.first, interpreted->Value() );
|
data->Set( index++, prop.first, interpreted->Value() );
|
||||||
else if ( const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >() )
|
} else if ( const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >() ) {
|
||||||
data->Set( index++, prop.first, interpreted->Value() );
|
data->Set( index++, prop.first, interpreted->Value() );
|
||||||
else if ( const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >() )
|
} else if ( const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >() ) {
|
||||||
data->Set( index++, prop.first, interpreted->Value() );
|
data->Set( index++, prop.first, interpreted->Value() );
|
||||||
else if ( const TypedProperty<std::string>* interpreted = prop.second->As<TypedProperty<std::string> >() )
|
} else if ( const TypedProperty<std::string>* interpreted = prop.second->As<TypedProperty<std::string> >() ) {
|
||||||
data->Set( index++, prop.first, aiString( interpreted->Value() ) );
|
data->Set( index++, prop.first, aiString( interpreted->Value() ) );
|
||||||
else if ( const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >() )
|
} else if ( const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >() ) {
|
||||||
data->Set( index++, prop.first, interpreted->Value() );
|
data->Set( index++, prop.first, interpreted->Value() );
|
||||||
else
|
} else {
|
||||||
assert( false );
|
ai_assert( false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -707,15 +707,11 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!properties.empty()) {
|
if (!properties.empty()) {
|
||||||
aiMetadata* data = new aiMetadata();
|
aiMetadata* data = aiMetadata::Alloc( properties.size() );
|
||||||
data->mNumProperties = properties.size();
|
unsigned int index( 0 );
|
||||||
data->mKeys = new aiString[data->mNumProperties]();
|
for ( const Metadata::value_type& kv : properties ) {
|
||||||
data->mValues = new aiMetadataEntry[data->mNumProperties]();
|
data->Set( index++, kv.first, aiString( kv.second ) );
|
||||||
|
}
|
||||||
unsigned int index = 0;
|
|
||||||
for(const Metadata::value_type& kv : properties)
|
|
||||||
data->Set(index++, kv.first, aiString(kv.second));
|
|
||||||
|
|
||||||
nd->mMetaData = data;
|
nd->mMetaData = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -901,11 +901,8 @@ void SIBImporter::InternReadFile(const std::string& pFile,
|
||||||
// Mark instanced objects as being so.
|
// Mark instanced objects as being so.
|
||||||
if (n >= firstInst)
|
if (n >= firstInst)
|
||||||
{
|
{
|
||||||
node->mMetaData = new aiMetadata;
|
node->mMetaData = aiMetadata::Alloc( 1 );
|
||||||
node->mMetaData->mNumProperties = 1;
|
node->mMetaData->Set( 0, "IsInstance", true );
|
||||||
node->mMetaData->mKeys = new aiString[1];
|
|
||||||
node->mMetaData->mValues = new aiMetadataEntry[1];
|
|
||||||
node->mMetaData->Set(0, "IsInstance", true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
// possible as new fields are added to assimp structures.
|
// possible as new fields are added to assimp structures.
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** @file Implements Assimp::SceneCombiner. This is a smart utility
|
/**
|
||||||
* class that combines multiple scenes, meshes, ... into one. Currently
|
* @file Implements Assimp::SceneCombiner. This is a smart utility
|
||||||
* these utilities are used by the IRR and LWS loaders and the
|
* class that combines multiple scenes, meshes, ... into one. Currently
|
||||||
* OptimizeGraph step.
|
* these utilities are used by the IRR and LWS loaders and the
|
||||||
*/
|
* OptimizeGraph step.
|
||||||
|
*/
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
#include "SceneCombiner.h"
|
#include "SceneCombiner.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
@ -59,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "ScenePrivate.h"
|
#include "ScenePrivate.h"
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Add a prefix to a string
|
// Add a prefix to a string
|
||||||
|
@ -198,8 +199,9 @@ void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src,
|
||||||
void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInfo>& srcList)
|
void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInfo>& srcList)
|
||||||
{
|
{
|
||||||
unsigned int cnt;
|
unsigned int cnt;
|
||||||
for (cnt = 0; cnt < attach->mNumChildren;++cnt)
|
for ( cnt = 0; cnt < attach->mNumChildren; ++cnt ) {
|
||||||
AttachToGraph(attach->mChildren[cnt],srcList);
|
AttachToGraph( attach->mChildren[ cnt ], srcList );
|
||||||
|
}
|
||||||
|
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
for (std::vector<NodeAttachmentInfo>::iterator it = srcList.begin();
|
for (std::vector<NodeAttachmentInfo>::iterator it = srcList.begin();
|
||||||
|
@ -1219,13 +1221,12 @@ void SceneCombiner::Copy (aiNode** _dest, const aiNode* src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
|
void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src)
|
||||||
{
|
{
|
||||||
ai_assert(NULL != _dest && NULL != src);
|
ai_assert( NULL != _dest );
|
||||||
|
ai_assert( NULL != src);
|
||||||
|
|
||||||
aiMetadata* dest = *_dest = new aiMetadata();
|
aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
|
||||||
dest->mNumProperties = src->mNumProperties;
|
|
||||||
dest->mKeys = new aiString[src->mNumProperties];
|
|
||||||
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
|
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
|
||||||
|
|
||||||
dest->mValues = new aiMetadataEntry[src->mNumProperties];
|
dest->mValues = new aiMetadataEntry[src->mNumProperties];
|
||||||
|
|
|
@ -758,15 +758,14 @@ void X3DImporter::Postprocess_CollectMetadata(const CX3DImporter_NodeElement& pN
|
||||||
size_t meta_idx;
|
size_t meta_idx;
|
||||||
|
|
||||||
PostprocessHelper_CollectMetadata(pNodeElement, meta_list);// find metadata in current node element.
|
PostprocessHelper_CollectMetadata(pNodeElement, meta_list);// find metadata in current node element.
|
||||||
if(meta_list.size() > 0)
|
if ( !meta_list.empty() )
|
||||||
{
|
{
|
||||||
if(pSceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
if ( pSceneNode.mMetaData != nullptr ) {
|
||||||
|
throw DeadlyImportError( "Postprocess. MetaData member in node are not nullptr. Something went wrong." );
|
||||||
|
}
|
||||||
|
|
||||||
// copy collected metadata to output node.
|
// copy collected metadata to output node.
|
||||||
pSceneNode.mMetaData = new aiMetadata();
|
pSceneNode.mMetaData = aiMetadata::Alloc( meta_list.size() );
|
||||||
pSceneNode.mMetaData->mNumProperties = meta_list.size();
|
|
||||||
pSceneNode.mMetaData->mKeys = new aiString[pSceneNode.mMetaData->mNumProperties];
|
|
||||||
pSceneNode.mMetaData->mValues = new aiMetadataEntry[pSceneNode.mMetaData->mNumProperties];
|
|
||||||
meta_idx = 0;
|
meta_idx = 0;
|
||||||
for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++, meta_idx++)
|
for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++, meta_idx++)
|
||||||
{
|
{
|
||||||
|
@ -808,7 +807,7 @@ void X3DImporter::Postprocess_CollectMetadata(const CX3DImporter_NodeElement& pN
|
||||||
throw DeadlyImportError("Postprocess. Unknown metadata type.");
|
throw DeadlyImportError("Postprocess. Unknown metadata type.");
|
||||||
}// if((*it)->Type == CX3DImporter_NodeElement::ENET_Meta*) else
|
}// if((*it)->Type == CX3DImporter_NodeElement::ENET_Meta*) else
|
||||||
}// for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++)
|
}// for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++)
|
||||||
}// if(meta_list.size() > 0)
|
}// if( !meta_list.empty() )
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace Assimp
|
}// namespace Assimp
|
||||||
|
|
|
@ -47,10 +47,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define AI_METADATA_H_INC
|
#define AI_METADATA_H_INC
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
|
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
|
||||||
#include "Compiler/pstdint.h"
|
# include "Compiler/pstdint.h"
|
||||||
#else
|
#else
|
||||||
#include <limits.h>
|
# include <stdint.h>
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
@ -58,8 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* Enum used to distinguish data types
|
* Enum used to distinguish data types
|
||||||
*/
|
*/
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
typedef enum aiMetadataType
|
typedef enum aiMetadataType {
|
||||||
{
|
|
||||||
AI_BOOL = 0,
|
AI_BOOL = 0,
|
||||||
AI_INT32 = 1,
|
AI_INT32 = 1,
|
||||||
AI_UINT64 = 2,
|
AI_UINT64 = 2,
|
||||||
|
@ -80,8 +78,7 @@ typedef enum aiMetadataType
|
||||||
* The type field uniquely identifies the underlying type of the data field
|
* The type field uniquely identifies the underlying type of the data field
|
||||||
*/
|
*/
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
struct aiMetadataEntry
|
struct aiMetadataEntry {
|
||||||
{
|
|
||||||
aiMetadataType mType;
|
aiMetadataType mType;
|
||||||
void* mData;
|
void* mData;
|
||||||
};
|
};
|
||||||
|
@ -96,12 +93,12 @@ struct aiMetadataEntry
|
||||||
*/
|
*/
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
|
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
|
||||||
inline aiMetadataType GetAiType( int32_t ) { return AI_INT32; }
|
inline aiMetadataType GetAiType( int32_t ) { return AI_INT32; }
|
||||||
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
|
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
|
||||||
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
|
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
|
||||||
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; }
|
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; }
|
||||||
inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; }
|
inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; }
|
||||||
inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; }
|
inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; }
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
@ -113,8 +110,7 @@ inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; }
|
||||||
* Metadata is a key-value store using string keys and values.
|
* Metadata is a key-value store using string keys and values.
|
||||||
*/
|
*/
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
struct aiMetadata
|
struct aiMetadata {
|
||||||
{
|
|
||||||
/** Length of the mKeys and mValues arrays, respectively */
|
/** Length of the mKeys and mValues arrays, respectively */
|
||||||
unsigned int mNumProperties;
|
unsigned int mNumProperties;
|
||||||
|
|
||||||
|
@ -127,28 +123,28 @@ struct aiMetadata
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
/** Constructor */
|
/**
|
||||||
|
* @brief The default constructor, set all members to zero by default.
|
||||||
|
*/
|
||||||
aiMetadata()
|
aiMetadata()
|
||||||
// set all members to zero by default
|
: mNumProperties(0)
|
||||||
: mNumProperties(0)
|
, mKeys(NULL)
|
||||||
, mKeys(NULL)
|
, mValues(NULL) {
|
||||||
, mValues(NULL)
|
// empty
|
||||||
{}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Destructor */
|
/**
|
||||||
~aiMetadata()
|
* @brief The destructor.
|
||||||
{
|
*/
|
||||||
delete[] mKeys;
|
~aiMetadata() {
|
||||||
|
delete [] mKeys;
|
||||||
mKeys = NULL;
|
mKeys = NULL;
|
||||||
if (mValues)
|
if (mValues) {
|
||||||
{
|
|
||||||
// Delete each metadata entry
|
// Delete each metadata entry
|
||||||
for (unsigned i=0; i<mNumProperties; ++i)
|
for (unsigned i=0; i<mNumProperties; ++i) {
|
||||||
{
|
|
||||||
void* data = mValues[i].mData;
|
void* data = mValues[i].mData;
|
||||||
switch (mValues[i].mType)
|
switch (mValues[i].mType) {
|
||||||
{
|
|
||||||
case AI_BOOL:
|
case AI_BOOL:
|
||||||
delete static_cast<bool*>(data);
|
delete static_cast<bool*>(data);
|
||||||
break;
|
break;
|
||||||
|
@ -184,14 +180,37 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool 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
|
// In range assertion
|
||||||
if ( index >= mNumProperties ) {
|
if ( index >= mNumProperties ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that we have a valid key.
|
||||||
|
if ( key.empty() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set metadata key
|
// Set metadata key
|
||||||
mKeys[index] = key;
|
mKeys[index] = key;
|
||||||
|
|
||||||
|
@ -204,8 +223,8 @@ struct aiMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool Get( unsigned index, T& value )
|
inline
|
||||||
{
|
bool Get( unsigned index, T& value ) {
|
||||||
// In range assertion
|
// In range assertion
|
||||||
if ( index >= mNumProperties ) {
|
if ( index >= mNumProperties ) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -220,17 +239,19 @@ struct aiMetadata
|
||||||
// Otherwise, output the found value and
|
// Otherwise, output the found value and
|
||||||
// return true
|
// return true
|
||||||
value = *static_cast<T*>(mValues[index].mData);
|
value = *static_cast<T*>(mValues[index].mData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline
|
inline
|
||||||
bool Get( const aiString& key, T& value )
|
bool Get( const aiString& key, T& value ) {
|
||||||
{
|
|
||||||
// Search for the given key
|
// Search for the given key
|
||||||
for (unsigned i=0; i<mNumProperties; ++i)
|
for ( unsigned int i = 0; i < mNumProperties; ++i ) {
|
||||||
if (mKeys[i]==key)
|
if ( mKeys[ i ] == key ) {
|
||||||
return Get(i, value);
|
return Get( i, value );
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,18 +260,18 @@ struct aiMetadata
|
||||||
return Get(aiString(key), value);
|
return Get(aiString(key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \fn inline bool Get(size_t pIndex, const aiString*& pKey, const aiMetadataEntry*& pEntry)
|
|
||||||
/// Return metadata entry for analyzing it by user.
|
/// Return metadata entry for analyzing it by user.
|
||||||
/// \param [in] pIndex - index of the entry.
|
/// \param [in] pIndex - index of the entry.
|
||||||
/// \param [out] pKey - pointer to the key value.
|
/// \param [out] pKey - pointer to the key value.
|
||||||
/// \param [out] pEntry - pointer to the entry: type and value.
|
/// \param [out] pEntry - pointer to the entry: type and value.
|
||||||
/// \return false - if pIndex is out of range, else - true.
|
/// \return false - if pIndex is out of range, else - true.
|
||||||
inline bool Get(size_t pIndex, const aiString*& pKey, const aiMetadataEntry*& pEntry)
|
inline bool Get(size_t index, const aiString*& key, const aiMetadataEntry*& entry) {
|
||||||
{
|
if ( index >= mNumProperties ) {
|
||||||
if(pIndex >= mNumProperties) return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pKey = &mKeys[pIndex];
|
key = &mKeys[index];
|
||||||
pEntry = &mValues[pIndex];
|
entry = &mValues[index];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ protected:
|
||||||
aiMetadata *m_data;
|
aiMetadata *m_data;
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
m_data = new aiMetadata();
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
|
@ -69,20 +69,111 @@ TEST_F( utMetadata, creationTest ) {
|
||||||
EXPECT_TRUE( ok );
|
EXPECT_TRUE( ok );
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F( utMetadata, get_set_Test ) {
|
TEST_F( utMetadata, allocTest ) {
|
||||||
m_data->mNumProperties = 1;
|
aiMetadata *data = aiMetadata::Alloc( 0 );
|
||||||
m_data->mKeys = new aiString[ m_data->mNumProperties ]();
|
EXPECT_EQ( nullptr, data );
|
||||||
m_data->mValues = new aiMetadataEntry[ m_data->mNumProperties ]();
|
|
||||||
|
data = aiMetadata::Alloc( 1 );
|
||||||
|
EXPECT_NE( nullptr, data );
|
||||||
|
EXPECT_EQ( 1, data->mNumProperties );
|
||||||
|
EXPECT_NE( nullptr, data->mKeys );
|
||||||
|
EXPECT_NE( nullptr, data->mValues );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F( utMetadata, get_set_pod_Test ) {
|
||||||
|
m_data = aiMetadata::Alloc( 5 );
|
||||||
|
|
||||||
|
// int, 32 bit
|
||||||
|
unsigned int index( 0 );
|
||||||
|
bool success( false );
|
||||||
|
const std::string key_int = "test_int";
|
||||||
|
success = m_data->Set( index, key_int, 1 );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
success = m_data->Set( index + 10, key_int, 1 );
|
||||||
|
EXPECT_FALSE( success );
|
||||||
|
|
||||||
|
// unsigned int, 64 bit
|
||||||
|
index++;
|
||||||
|
const std::string key_uint = "test_uint";
|
||||||
|
success = m_data->Set<uint64_t>( index, key_uint, 1UL );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
uint64_t result_uint( 0 );
|
||||||
|
success = m_data->Get( key_uint, result_uint );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
EXPECT_EQ( 1UL, result_uint );
|
||||||
|
|
||||||
|
// bool
|
||||||
|
index++;
|
||||||
|
const std::string key_bool = "test_bool";
|
||||||
|
success = m_data->Set( index, key_bool, true );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
bool result_bool( false );
|
||||||
|
success = m_data->Get( key_bool, result_bool );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
EXPECT_EQ( true, result_bool );
|
||||||
|
|
||||||
|
// float
|
||||||
|
index++;
|
||||||
|
const std::string key_float = "test_float";
|
||||||
|
float fVal = 2.0f;
|
||||||
|
success = m_data->Set( index, key_float, fVal );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
float result_float( 0.0f );
|
||||||
|
success = m_data->Get( key_float, result_float );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
EXPECT_FLOAT_EQ( 2.0f, result_float );
|
||||||
|
|
||||||
|
// double
|
||||||
|
index++;
|
||||||
|
const std::string key_double = "test_double";
|
||||||
|
double dVal = 3.0;
|
||||||
|
success = m_data->Set( index, key_double, dVal );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
double result_double( 0.0 );
|
||||||
|
success = m_data->Get( key_double, result_double );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
EXPECT_DOUBLE_EQ( 3.0, result_double );
|
||||||
|
|
||||||
|
// error
|
||||||
|
int result;
|
||||||
|
success = m_data->Get( "bla", result );
|
||||||
|
EXPECT_FALSE( success );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F( utMetadata, get_set_string_Test ) {
|
||||||
|
m_data = aiMetadata::Alloc( 1 );
|
||||||
|
|
||||||
unsigned int index( 0 );
|
unsigned int index( 0 );
|
||||||
bool success( false );
|
bool success( false );
|
||||||
const std::string key = "test";
|
const std::string key = "test";
|
||||||
success = m_data->Set( index, key, aiString( std::string( "test" ) ) );
|
success = m_data->Set( index, key, aiString( std::string( "test" ) ) );
|
||||||
EXPECT_TRUE( success );
|
EXPECT_TRUE( success );
|
||||||
|
|
||||||
|
success = m_data->Set( index+10, key, aiString( std::string( "test" ) ) );
|
||||||
|
EXPECT_FALSE( success );
|
||||||
|
|
||||||
aiString result;
|
aiString result;
|
||||||
success = m_data->Get( key, result );
|
success = m_data->Get( key, result );
|
||||||
|
EXPECT_EQ( aiString( std::string( "test" ) ), result );
|
||||||
EXPECT_TRUE( success );
|
EXPECT_TRUE( success );
|
||||||
|
|
||||||
success = m_data->Get( "bla", result );
|
success = m_data->Get( "bla", result );
|
||||||
EXPECT_FALSE( success );
|
EXPECT_FALSE( success );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F( utMetadata, get_set_aiVector3D_Test ) {
|
||||||
|
m_data = aiMetadata::Alloc( 1 );
|
||||||
|
|
||||||
|
unsigned int index( 0 );
|
||||||
|
bool success( false );
|
||||||
|
const std::string key = "test";
|
||||||
|
aiVector3D vec( 1, 2, 3 );
|
||||||
|
|
||||||
|
success = m_data->Set( index, key, vec );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
|
||||||
|
aiVector3D result( 0, 0, 0 );
|
||||||
|
success = m_data->Get( key, result );
|
||||||
|
EXPECT_EQ( vec, result );
|
||||||
|
EXPECT_TRUE( success );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue