Browse Source

Debug output and configuration value handler for IndexedMesh::IndexType.

Mostly copy of what was already done for Type enum.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
3b5b7c71d4
  1. 2
      src/Context.h
  2. 40
      src/IndexedMesh.cpp
  3. 26
      src/IndexedMesh.h
  4. 1
      src/Test/CMakeLists.txt
  5. 55
      src/Test/IndexedMeshTest.cpp

2
src/Context.h

@ -16,7 +16,7 @@
*/
/** @file
* @brief Enum Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED()
* @brief Enum Magnum::Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED()
*/
#include <bitset>

40
src/IndexedMesh.cpp

@ -87,4 +87,44 @@ void IndexedMesh::bindIndexedImplementationDefault() {
void IndexedMesh::bindIndexedImplementationVAO() {}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, IndexedMesh::IndexType value) {
switch(value) {
#define _c(value) case IndexedMesh::IndexType::value: return debug << "IndexedMesh::IndexType::" #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return debug << "IndexedMesh::IndexType::(invalid)";
}
#endif
}
namespace Corrade { namespace Utility {
std::string ConfigurationValue<Magnum::IndexedMesh::IndexType>::toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags) {
switch(value) {
#define _c(value) case Magnum::IndexedMesh::IndexType::value: return #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return "";
}
Magnum::IndexedMesh::IndexType ConfigurationValue<Magnum::IndexedMesh::IndexType>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
#define _c(value) if(stringValue == #value) return Magnum::IndexedMesh::IndexType::value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
return Magnum::IndexedMesh::IndexType::UnsignedInt;
}
}}

26
src/IndexedMesh.h

@ -196,6 +196,32 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
IndexType _indexType;
};
/** @debugoperator{Magnum::IndexedMesh} */
Debug MAGNUM_EXPORT operator<<(Debug debug, IndexedMesh::IndexType value);
}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::IndexedMesh} */
template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::IndexedMesh::IndexType> {
ConfigurationValue() = delete;
/**
* @brief Write enum value as string
*
* If the value is invalid, returns empty string.
*/
static std::string toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags);
/**
* @brief Read enum value as string
*
* If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt".
*/
static Magnum::IndexedMesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags);
};
}}
#endif

1
src/Test/CMakeLists.txt

@ -1,6 +1,7 @@
corrade_add_test(ArrayTest ArrayTest.cpp)
corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum)
corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum)
corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum)

55
src/Test/IndexedMeshTest.cpp

@ -0,0 +1,55 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <sstream>
#include <TestSuite/Tester.h>
#include <Utility/Configuration.h>
#include "IndexedMesh.h"
using namespace Corrade::Utility;
namespace Magnum { namespace Test {
class IndexedMeshTest: public Corrade::TestSuite::Tester {
public:
IndexedMeshTest();
void debug();
void configuration();
};
IndexedMeshTest::IndexedMeshTest() {
addTests(&IndexedMeshTest::debug,
&IndexedMeshTest::configuration);
}
void IndexedMeshTest::debug() {
std::ostringstream o;
Debug(&o) << IndexedMesh::IndexType::UnsignedShort;
CORRADE_COMPARE(o.str(), "IndexedMesh::IndexType::UnsignedShort\n");
}
void IndexedMeshTest::configuration() {
Configuration c;
c.setValue("type", IndexedMesh::IndexType::UnsignedByte);
CORRADE_COMPARE(c.value<std::string>("type"), "UnsignedByte");
CORRADE_COMPARE(c.value<IndexedMesh::IndexType>("type"), IndexedMesh::IndexType::UnsignedByte);
}
}}
CORRADE_TEST_MAIN(Magnum::Test::IndexedMeshTest)
Loading…
Cancel
Save