Added operator== and operator!= to aiMetadata to allow for testing.

Updated utMetadata.copy_test to reflect that there's now 8 metadata types.
pull/3298/head
Evangel 2020-06-26 15:07:42 +10:00
parent f6b4370f6a
commit d75d59a4fd
2 changed files with 93 additions and 1 deletions

View File

@ -442,6 +442,89 @@ struct aiMetadata {
return false; return false;
} }
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);
}
#endif // __cplusplus #endif // __cplusplus
}; };

View File

@ -197,9 +197,11 @@ TEST_F( utMetadata, copy_test ) {
m_data->Set( 5, "aiString", strVal ); m_data->Set( 5, "aiString", strVal );
aiVector3D vecVal( 1, 2, 3 ); aiVector3D vecVal( 1, 2, 3 );
m_data->Set( 6, "aiVector3D", vecVal ); m_data->Set( 6, "aiVector3D", vecVal );
aiMetadata metaVal;
m_data->Set( 7, "aiMetadata", metaVal );
aiMetadata copy( *m_data ); aiMetadata copy( *m_data );
EXPECT_EQ( 7u, copy.mNumProperties ); EXPECT_EQ( 8u, copy.mNumProperties );
// bool test // bool test
{ {
@ -251,4 +253,11 @@ TEST_F( utMetadata, copy_test ) {
EXPECT_TRUE( copy.Get( "aiVector3D", v ) ); EXPECT_TRUE( copy.Get( "aiVector3D", v ) );
EXPECT_EQ( vecVal, v ); EXPECT_EQ( vecVal, v );
} }
// metadata test
{
aiMetadata v;
EXPECT_TRUE( copy.Get( "aiMetadata", v ) );
EXPECT_EQ( metaVal, v );
}
} }