Browse Source

Math: ability to read and write Rectangle to configuration.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
5a368c4fba
  1. 3
      src/CMakeLists.txt
  2. 30
      src/Math/Geometry/Rectangle.h
  3. 16
      src/Math/Geometry/Test/RectangleTest.cpp
  4. 38
      src/Math/Geometry/instantiation.cpp

3
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

30
src/Math/Geometry/Rectangle.h

@ -148,4 +148,34 @@ template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb
}}}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Geometry::Rectangle} */
template<class T> struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<T>> {
ConfigurationValue() = delete;
/** @brief Writes elements separated with spaces */
static std::string toString(const Magnum::Math::Geometry::Rectangle<T>& value, const ConfigurationValueFlags flags) {
return ConfigurationValue<Magnum::Math::Vector<4, T>>::toString(
reinterpret_cast<const Magnum::Math::Vector<4, T>&>(value), flags);
}
/** @brief Reads elements separated with whitespace */
static Magnum::Math::Geometry::Rectangle<T> fromString(const std::string& stringValue, const ConfigurationValueFlags flags) {
const auto vec = ConfigurationValue<Magnum::Math::Vector<4, T>>::fromString(stringValue, flags);
return reinterpret_cast<const Magnum::Math::Geometry::Rectangle<T>&>(vec);
}
};
#ifndef DOXYGEN_GENERATING_OUTPUT
extern template struct MAGNUM_EXPORT ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Float>>;
extern template struct MAGNUM_EXPORT ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Int>>;
extern template struct MAGNUM_EXPORT ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::UnsignedInt>>;
#ifndef MAGNUM_TARGET_GLES
extern template struct MAGNUM_EXPORT ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Double>>;
#endif
#endif
}}
#endif

16
src/Math/Geometry/Test/RectangleTest.cpp

@ -24,6 +24,7 @@
#include <sstream>
#include <TestSuite/Tester.h>
#include <Utility/Configuration.h>
#include "Math/Geometry/Rectangle.h"
@ -44,6 +45,7 @@ class RectangleTest: public Corrade::TestSuite::Tester {
void size();
void debug();
void configuration();
};
typedef Geometry::Rectangle<Float> 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>("rectangle"), rect);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest)

38
src/Math/Geometry/instantiation.cpp

@ -0,0 +1,38 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
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<Magnum::Math::Geometry::Rectangle<Magnum::Float>>;
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Int>>;
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::UnsignedInt>>;
#ifndef MAGNUM_TARGET_GLES
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Double>>;
#endif
#endif
}}
Loading…
Cancel
Save