Browse Source

Minor code motion.

pull/549/head
Vladimír Vondruš 4 years ago
parent
commit
80a679ba93
  1. 20
      src/Magnum/Mesh.cpp
  2. 6
      src/Magnum/Mesh.h
  3. 82
      src/Magnum/Test/MeshTest.cpp

20
src/Magnum/Mesh.cpp

@ -32,16 +32,6 @@
namespace Magnum { namespace Magnum {
UnsignedInt meshIndexTypeSize(MeshIndexType type) {
switch(type) {
case MeshIndexType::UnsignedByte: return 1;
case MeshIndexType::UnsignedShort: return 2;
case MeshIndexType::UnsignedInt: return 4;
}
CORRADE_ASSERT_UNREACHABLE("meshIndexTypeSize(): invalid type" << type, {});
}
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace { namespace {
@ -88,6 +78,16 @@ Debug& operator<<(Debug& debug, const MeshIndexType value) {
} }
#endif #endif
UnsignedInt meshIndexTypeSize(MeshIndexType type) {
switch(type) {
case MeshIndexType::UnsignedByte: return 1;
case MeshIndexType::UnsignedShort: return 2;
case MeshIndexType::UnsignedInt: return 4;
}
CORRADE_ASSERT_UNREACHABLE("meshIndexTypeSize(): invalid type" << type, {});
}
} }
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {

6
src/Magnum/Mesh.h

@ -286,12 +286,12 @@ enum class MeshIndexType: UnsignedByte {
UnsignedInt UnsignedInt
}; };
/** @brief Size of given mesh index type */
MAGNUM_EXPORT UnsignedInt meshIndexTypeSize(MeshIndexType type);
/** @debugoperatorenum{MeshIndexType} */ /** @debugoperatorenum{MeshIndexType} */
MAGNUM_EXPORT Debug& operator<<(Debug& debug, MeshIndexType value); MAGNUM_EXPORT Debug& operator<<(Debug& debug, MeshIndexType value);
/** @brief Size of given mesh index type */
MAGNUM_EXPORT UnsignedInt meshIndexTypeSize(MeshIndexType type);
} }
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {

82
src/Magnum/Test/MeshTest.cpp

@ -37,14 +37,13 @@ struct MeshTest: TestSuite::Tester {
explicit MeshTest(); explicit MeshTest();
void primitiveMapping(); void primitiveMapping();
void indexTypeMapping();
void primitiveIsImplementationSpecific(); void primitiveIsImplementationSpecific();
void primitiveWrap(); void primitiveWrap();
void primitiveWrapInvalid(); void primitiveWrapInvalid();
void primitiveUnwrap(); void primitiveUnwrap();
void primitiveUnwrapInvalid(); void primitiveUnwrapInvalid();
void indexTypeMapping();
void indexTypeSize(); void indexTypeSize();
void indexTypeSizeInvalid(); void indexTypeSizeInvalid();
@ -58,14 +57,13 @@ struct MeshTest: TestSuite::Tester {
MeshTest::MeshTest() { MeshTest::MeshTest() {
addTests({&MeshTest::primitiveMapping, addTests({&MeshTest::primitiveMapping,
&MeshTest::indexTypeMapping,
&MeshTest::primitiveIsImplementationSpecific, &MeshTest::primitiveIsImplementationSpecific,
&MeshTest::primitiveWrap, &MeshTest::primitiveWrap,
&MeshTest::primitiveWrapInvalid, &MeshTest::primitiveWrapInvalid,
&MeshTest::primitiveUnwrap, &MeshTest::primitiveUnwrap,
&MeshTest::primitiveUnwrapInvalid, &MeshTest::primitiveUnwrapInvalid,
&MeshTest::indexTypeMapping,
&MeshTest::indexTypeSize, &MeshTest::indexTypeSize,
&MeshTest::indexTypeSizeInvalid, &MeshTest::indexTypeSizeInvalid,
@ -115,44 +113,6 @@ void MeshTest::primitiveMapping() {
CORRADE_COMPARE(firstUnhandled, 0xff); CORRADE_COMPARE(firstUnhandled, 0xff);
} }
void MeshTest::indexTypeMapping() {
/* This goes through the first 8 bits, which should be enough. */
UnsignedInt firstUnhandled = 0xff;
UnsignedInt nextHandled = 1; /* 0 is an invalid type */
for(UnsignedInt i = 1; i <= 0xff; ++i) {
const auto type = MeshIndexType(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range) */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(type) {
#define _c(type) \
case MeshIndexType::type: \
CORRADE_COMPARE(Utility::ConfigurationValue<MeshIndexType>::toString(MeshIndexType::type, {}), #type); \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xff); \
++nextHandled; \
continue;
#include "Magnum/Implementation/meshIndexTypeMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xff);
}
void MeshTest::primitiveIsImplementationSpecific() { void MeshTest::primitiveIsImplementationSpecific() {
constexpr bool a = isMeshPrimitiveImplementationSpecific(MeshPrimitive::Lines); constexpr bool a = isMeshPrimitiveImplementationSpecific(MeshPrimitive::Lines);
constexpr bool b = isMeshPrimitiveImplementationSpecific(MeshPrimitive(0x8000dead)); constexpr bool b = isMeshPrimitiveImplementationSpecific(MeshPrimitive(0x8000dead));
@ -196,6 +156,44 @@ void MeshTest::primitiveUnwrapInvalid() {
CORRADE_COMPARE(out.str(), "meshPrimitiveUnwrap(): MeshPrimitive::Triangles isn't a wrapped implementation-specific value\n"); CORRADE_COMPARE(out.str(), "meshPrimitiveUnwrap(): MeshPrimitive::Triangles isn't a wrapped implementation-specific value\n");
} }
void MeshTest::indexTypeMapping() {
/* This goes through the first 8 bits, which should be enough. */
UnsignedInt firstUnhandled = 0xff;
UnsignedInt nextHandled = 1; /* 0 is an invalid type */
for(UnsignedInt i = 1; i <= 0xff; ++i) {
const auto type = MeshIndexType(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range) */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(type) {
#define _c(type) \
case MeshIndexType::type: \
CORRADE_COMPARE(Utility::ConfigurationValue<MeshIndexType>::toString(MeshIndexType::type, {}), #type); \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xff); \
++nextHandled; \
continue;
#include "Magnum/Implementation/meshIndexTypeMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xff);
}
void MeshTest::indexTypeSize() { void MeshTest::indexTypeSize() {
CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedByte), 1); CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedByte), 1);
CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedShort), 2); CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedShort), 2);

Loading…
Cancel
Save