diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 93ff6917e..49956a899 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -265,4 +265,55 @@ void Mesh::unbindImplementationDefault() { void Mesh::unbindImplementationVAO() {} +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, Mesh::Primitive value) { + switch(value) { + #define _c(value) case Mesh::Primitive::value: return debug << "Mesh::Primitive::" #value; + _c(Points) + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + } + + return debug << "Mesh::Primitive::(invalid)"; +} +#endif + +} + +namespace Corrade { namespace Utility { + +std::string ConfigurationValue::toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags) { + switch(value) { + #define _c(value) case Magnum::Mesh::Primitive::value: return #value; + _c(Points) + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + } + + return ""; } + +Magnum::Mesh::Primitive ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { + #define _c(value) if(stringValue == #value) return Magnum::Mesh::Primitive::value; + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + + return Magnum::Mesh::Primitive::Points; +} + +}} diff --git a/src/Mesh.h b/src/Mesh.h index 8eee5324d..369d47a66 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -742,6 +742,30 @@ class MAGNUM_EXPORT Mesh { #endif }; +/** @debugoperator{Magnum::Mesh} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value); + } +namespace Corrade { namespace Utility { + +/** @configurationvalue{Magnum::Mesh} */ +template<> struct MAGNUM_EXPORT ConfigurationValue { + /** + * @brief Writes enum value as string + * + * If the value is invalid, returns empty string. + */ + static std::string toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags); + + /** + * @brief Reads enum value as string + * + * If the value is invalid, returns @ref Magnum::Mesh::Primitive "Mesh::Primitive::Points". + */ + static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags); +}; + +}} + #endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index d46a463fb..2e6f58e3e 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,4 +1,5 @@ corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test2(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test2(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp new file mode 100644 index 000000000..0e1a9d949 --- /dev/null +++ b/src/Test/MeshTest.cpp @@ -0,0 +1,47 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + 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 "MeshTest.h" + +#include + +#include "Mesh.h" + +CORRADE_TEST_MAIN(Magnum::Test::MeshTest) + +using namespace Corrade::Utility; + +namespace Magnum { namespace Test { + +MeshTest::MeshTest() { + addTests(&MeshTest::debug, + &MeshTest::configuration); +} + +void MeshTest::debug() { + std::ostringstream o; + Debug(&o) << Mesh::Primitive::TriangleFan; + CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n"); +} + +void MeshTest::configuration() { + Configuration c; + + c.setValue("primitive", Mesh::Primitive::LineStrip); + CORRADE_COMPARE(c.value("primitive"), "LineStrip"); + CORRADE_COMPARE(c.value("primitive"), Mesh::Primitive::LineStrip); +} + +}} diff --git a/src/Test/MeshTest.h b/src/Test/MeshTest.h new file mode 100644 index 000000000..051488fbf --- /dev/null +++ b/src/Test/MeshTest.h @@ -0,0 +1,32 @@ +#ifndef Magnum_Test_MeshTest_h +#define Magnum_Test_MeshTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + 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 + +namespace Magnum { namespace Test { + +class MeshTest: public Corrade::TestSuite::Tester { + public: + MeshTest(); + + void debug(); + void configuration(); +}; + +}} + +#endif