From 5a368c4fbadbe03ba602650f97c0a5fbda332058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 24 Jun 2013 18:55:41 +0200 Subject: [PATCH] Math: ability to read and write Rectangle to configuration. --- src/CMakeLists.txt | 3 +- src/Math/Geometry/Rectangle.h | 30 +++++++++++++++++++ src/Math/Geometry/Test/RectangleTest.cpp | 16 +++++++++- src/Math/Geometry/instantiation.cpp | 38 ++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/Math/Geometry/instantiation.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a204f4733..029e0e754 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -149,7 +149,8 @@ endif() # Files shared between main library and math unit test library set(MagnumMath_SRCS Math/Functions.cpp - Math/instantiation.cpp) + Math/instantiation.cpp + Math/Geometry/instantiation.cpp) # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index ad8ef7b20..41c3a4efc 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -148,4 +148,34 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb }}} +namespace Corrade { namespace Utility { + +/** @configurationvalue{Magnum::Math::Geometry::Rectangle} */ +template struct ConfigurationValue> { + ConfigurationValue() = delete; + + /** @brief Writes elements separated with spaces */ + static std::string toString(const Magnum::Math::Geometry::Rectangle& value, const ConfigurationValueFlags flags) { + return ConfigurationValue>::toString( + reinterpret_cast&>(value), flags); + } + + /** @brief Reads elements separated with whitespace */ + static Magnum::Math::Geometry::Rectangle fromString(const std::string& stringValue, const ConfigurationValueFlags flags) { + const auto vec = ConfigurationValue>::fromString(stringValue, flags); + return reinterpret_cast&>(vec); + } +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +#ifndef MAGNUM_TARGET_GLES +extern template struct MAGNUM_EXPORT ConfigurationValue>; +#endif +#endif + +}} + #endif diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 051f97670..b7d10facb 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "Math/Geometry/Rectangle.h" @@ -44,6 +45,7 @@ class RectangleTest: public Corrade::TestSuite::Tester { void size(); void debug(); + void configuration(); }; typedef Geometry::Rectangle Rectangle; @@ -61,7 +63,8 @@ RectangleTest::RectangleTest() { &RectangleTest::compare, &RectangleTest::size, - &RectangleTest::debug}); + &RectangleTest::debug, + &RectangleTest::configuration}); } void RectangleTest::construct() { @@ -148,6 +151,17 @@ void RectangleTest::debug() { CORRADE_COMPARE(o.str(), "Rectangle({34, 23}, {47, 30})\n"); } +void RectangleTest::configuration() { + Corrade::Utility::Configuration c; + + Rectangle rect({3.0f, 3.125f}, {9.0f, 9.55f}); + std::string value("3 3.125 9 9.55"); + + c.setValue("rectangle", rect); + CORRADE_COMPARE(c.value("rectangle"), value); + CORRADE_COMPARE(c.value("rectangle"), rect); +} + }}}} CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) diff --git a/src/Math/Geometry/instantiation.cpp b/src/Math/Geometry/instantiation.cpp new file mode 100644 index 000000000..c483599aa --- /dev/null +++ b/src/Math/Geometry/instantiation.cpp @@ -0,0 +1,38 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Math/Geometry/Rectangle.h" + +namespace Corrade { namespace Utility { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +#ifndef MAGNUM_TARGET_GLES +template struct ConfigurationValue>; +#endif +#endif + +}}