Browse Source

Math: adapt to changes to Tweakable internals.

pull/481/head
Vladimír Vondruš 6 years ago
parent
commit
83d6509595
  1. 62
      src/Magnum/Math/Angle.cpp
  2. 8
      src/Magnum/Math/Angle.h
  3. 75
      src/Magnum/Math/Color.cpp
  4. 8
      src/Magnum/Math/Color.h
  5. 18
      src/Magnum/Math/Half.cpp
  6. 2
      src/Magnum/Math/Half.h
  7. 5
      src/Magnum/Math/Test/AngleTest.cpp
  8. 33
      src/Magnum/Math/Test/ColorTest.cpp
  9. 4
      src/Magnum/Math/Test/HalfTest.cpp

62
src/Magnum/Math/Angle.cpp

@ -26,96 +26,102 @@
#include "Angle.h"
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
#include <algorithm>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/String.h>
#include <algorithm> /** @todo get rid of this once StringView::find() exists */
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/TweakableParser.h>
namespace Corrade { namespace Utility {
std::pair<TweakableState, Magnum::Math::Deg<Magnum::Float>> TweakableParser<Magnum::Math::Deg<Magnum::Float>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Deg<Magnum::Float>> TweakableParser<Magnum::Math::Deg<Magnum::Float>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
char* end;
const Magnum::Float result = std::strtof(value, &end);
const Magnum::Float result = std::strtof(value.data(), &end);
if(end == value.begin() || std::find(value.begin(), value.end(), '.') == value.end()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not an angle literal";
Warning{} << "Utility::TweakableParser:" << value << "is not an angle literal";
return {TweakableState::Recompile, {}};
}
if(!String::viewEndsWith(value, "_degf")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _degf";
if(!value.hasSuffix("_degf"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _degf";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 5) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after an angle literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after an angle literal";
return {TweakableState::Recompile, {}};
}
return {TweakableState::Success, Magnum::Math::Deg<Magnum::Float>{result}};
}
std::pair<TweakableState, Magnum::Math::Deg<Magnum::Double>> TweakableParser<Magnum::Math::Deg<Magnum::Double>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Deg<Magnum::Double>> TweakableParser<Magnum::Math::Deg<Magnum::Double>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
char* end;
const Magnum::Double result = std::strtod(value, &end);
const Magnum::Double result = std::strtod(value.data(), &end);
if(end == value.begin() || std::find(value.begin(), value.end(), '.') == value.end()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not an angle literal";
Warning{} << "Utility::TweakableParser:" << value << "is not an angle literal";
return {TweakableState::Recompile, {}};
}
if(!String::viewEndsWith(value, "_deg")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _deg";
if(!value.hasSuffix("_deg"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _deg";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 4) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after an angle literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after an angle literal";
return {TweakableState::Recompile, {}};
}
return {TweakableState::Success, Magnum::Math::Deg<Magnum::Double>{result}};
}
std::pair<TweakableState, Magnum::Math::Rad<Magnum::Float>> TweakableParser<Magnum::Math::Rad<Magnum::Float>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Rad<Magnum::Float>> TweakableParser<Magnum::Math::Rad<Magnum::Float>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
char* end;
const Magnum::Float result = std::strtof(value, &end);
const Magnum::Float result = std::strtof(value.data(), &end);
if(end == value.begin() || std::find(value.begin(), value.end(), '.') == value.end()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not an angle literal";
Warning{} << "Utility::TweakableParser:" << value << "is not an angle literal";
return {TweakableState::Recompile, {}};
}
if(!String::viewEndsWith(value, "_radf")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _radf";
if(!value.hasSuffix("_radf"_s)) {
Warning{} << "Utility::TweakableParser:" << value.data() << "has an unexpected suffix, expected _radf";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 5) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after an angle literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after an angle literal";
return {TweakableState::Recompile, {}};
}
return {TweakableState::Success, Magnum::Math::Rad<Magnum::Float>{result}};
}
std::pair<TweakableState, Magnum::Math::Rad<Magnum::Double>> TweakableParser<Magnum::Math::Rad<Magnum::Double>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Rad<Magnum::Double>> TweakableParser<Magnum::Math::Rad<Magnum::Double>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
char* end;
const Magnum::Double result = std::strtod(value, &end);
const Magnum::Double result = std::strtod(value.data(), &end);
if(end == value.begin() || std::find(value.begin(), value.end(), '.') == value.end()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not an angle literal";
Warning{} << "Utility::TweakableParser:" << value << "is not an angle literal";
return {TweakableState::Recompile, {}};
}
if(!String::viewEndsWith(value, "_rad")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _rad";
if(!value.hasSuffix("_rad"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _rad";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 4) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after an angle literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after an angle literal";
return {TweakableState::Recompile, {}};
}

8
src/Magnum/Math/Angle.h

@ -263,7 +263,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Deg<Magnum::Float>
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Float>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Float>> parse(Containers::StringView value);
};
/**
@ -276,7 +276,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Deg<Magnum::Double
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Double>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Double>> parse(Containers::StringView value);
};
/**
@ -289,7 +289,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Rad<Magnum::Float>
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Float>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Float>> parse(Containers::StringView value);
};
/**
@ -302,7 +302,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Rad<Magnum::Double
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Double>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Double>> parse(Containers::StringView value);
};
#endif

75
src/Magnum/Math/Color.cpp

@ -27,8 +27,7 @@
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
#include <cstring>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/String.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/Tweakable.h>
#endif
@ -146,28 +145,30 @@ Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, const Color4
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
namespace Corrade { namespace Utility {
std::pair<TweakableState, Magnum::Math::Color3<Magnum::UnsignedByte>> TweakableParser<Magnum::Math::Color3<Magnum::UnsignedByte>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Color3<Magnum::UnsignedByte>> TweakableParser<Magnum::Math::Color3<Magnum::UnsignedByte>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
if(value.size() < 2 || value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a hexadecimal color literal";
Warning{} << "Utility::TweakableParser:" << value << "is not a hexadecimal color literal";
return {TweakableState::Recompile, {}};
}
const bool isSrgb = String::viewEndsWith(value, "_srgb");
if(!isSrgb && !String::viewEndsWith(value, "_rgb")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _rgb or _srgb";
const bool isSrgb = value.hasSuffix("_srgb"_s);
if(!isSrgb && !value.hasSuffix("_rgb"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _rgb or _srgb";
return {TweakableState::Recompile, {}};
}
char* end;
const Magnum::UnsignedInt result = std::strtoul(value, &end, 16);
const Magnum::UnsignedInt result = std::strtoul(value.data(), &end, 16);
if(end != value.end() - (isSrgb ? 5 : 4)) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after a color literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after a color literal";
return {TweakableState::Recompile, {}};
}
if(value.size() != std::size_t(isSrgb ? 13 : 12)) {
Error{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "doesn't have expected number of digits";
Error{} << "Utility::TweakableParser:" << value << "doesn't have expected number of digits";
return {TweakableState::Error, {}};
}
@ -176,28 +177,30 @@ std::pair<TweakableState, Magnum::Math::Color3<Magnum::UnsignedByte>> TweakableP
Magnum::Math::Literals::operator "" _rgb(result)};
}
std::pair<TweakableState, Magnum::Math::Color4<Magnum::UnsignedByte>> TweakableParser<Magnum::Math::Color4<Magnum::UnsignedByte>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Color4<Magnum::UnsignedByte>> TweakableParser<Magnum::Math::Color4<Magnum::UnsignedByte>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
if(value.size() < 2 || value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a hexadecimal color literal";
Warning{} << "Utility::TweakableParser:" << value << "is not a hexadecimal color literal";
return {TweakableState::Recompile, {}};
}
const bool isSrgb = String::viewEndsWith(value, "_srgba");
if(!isSrgb && !String::viewEndsWith(value, "_rgba")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _rgba or _srgba";
const bool isSrgb = value.hasSuffix("_srgba"_s);
if(!isSrgb && !value.hasSuffix("_rgba"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _rgba or _srgba";
return {TweakableState::Recompile, {}};
}
char* end;
const Magnum::UnsignedInt result = std::strtoul(value, &end, 16);
const Magnum::UnsignedInt result = std::strtoul(value.data(), &end, 16);
if(end != value.end() - (isSrgb ? 6 : 5)) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after a color literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after a color literal";
return {TweakableState::Recompile, {}};
}
if(value.size() != std::size_t(isSrgb ? 16 : 15)) {
Error{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "doesn't have expected number of digits";
Error{} << "Utility::TweakableParser:" << value << "doesn't have expected number of digits";
return {TweakableState::Error, {}};
}
@ -206,28 +209,30 @@ std::pair<TweakableState, Magnum::Math::Color4<Magnum::UnsignedByte>> TweakableP
Magnum::Math::Literals::operator "" _rgba(result)};
}
std::pair<TweakableState, Magnum::Math::Color3<Magnum::Float>> TweakableParser<Magnum::Math::Color3<Magnum::Float>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Color3<Magnum::Float>> TweakableParser<Magnum::Math::Color3<Magnum::Float>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
if(value.size() < 2 || value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a hexadecimal color literal";
Warning{} << "Utility::TweakableParser:" << value << "is not a hexadecimal color literal";
return {TweakableState::Recompile, {}};
}
const bool isSrgb = String::viewEndsWith(value, "_srgbf");
if(!isSrgb && !String::viewEndsWith(value, "_rgbf")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _rgbf or _srgbf";
const bool isSrgb = value.hasSuffix("_srgbf"_s);
if(!isSrgb && !value.hasSuffix("_rgbf"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _rgbf or _srgbf";
return {TweakableState::Recompile, {}};
}
char* end;
const Magnum::UnsignedInt result = std::strtoul(value, &end, 16);
const Magnum::UnsignedInt result = std::strtoul(value.data(), &end, 16);
if(end != value.end() - (isSrgb ? 6 : 5)) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after a color literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after a color literal";
return {TweakableState::Recompile, {}};
}
if(value.size() != std::size_t(isSrgb ? 14 : 13)) {
Error{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "doesn't have expected number of digits";
Error{} << "Utility::TweakableParser:" << value << "doesn't have expected number of digits";
return {TweakableState::Error, {}};
}
@ -236,28 +241,30 @@ std::pair<TweakableState, Magnum::Math::Color3<Magnum::Float>> TweakableParser<M
Magnum::Math::Literals::operator "" _rgbf(result)};
}
std::pair<TweakableState, Magnum::Math::Color4<Magnum::Float>> TweakableParser<Magnum::Math::Color4<Magnum::Float>>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Color4<Magnum::Float>> TweakableParser<Magnum::Math::Color4<Magnum::Float>>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
if(value.size() < 2 || value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a hexadecimal color literal";
Warning{} << "Utility::TweakableParser:" << value << "is not a hexadecimal color literal";
return {TweakableState::Recompile, {}};
}
const bool isSrgb = String::viewEndsWith(value, "_srgbaf");
if(!isSrgb && !String::viewEndsWith(value, "_rgbaf")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _rgbaf or _srgbaf";
const bool isSrgb = value.hasSuffix("_srgbaf"_s);
if(!isSrgb && !value.hasSuffix("_rgbaf"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _rgbaf or _srgbaf";
return {TweakableState::Recompile, {}};
}
char* end;
const Magnum::UnsignedInt result = std::strtoul(value, &end, 16);
const Magnum::UnsignedInt result = std::strtoul(value.data(), &end, 16);
if(end != value.end() - (isSrgb ? 7 : 6)) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after a color literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after a color literal";
return {TweakableState::Recompile, {}};
}
if(value.size() != (isSrgb ? 17 : 16)) {
Error{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "doesn't have expected number of digits";
Error{} << "Utility::TweakableParser:" << value << "doesn't have expected number of digits";
return {TweakableState::Error, {}};
}

8
src/Magnum/Math/Color.h

@ -1429,7 +1429,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Color3<Magnum::Uns
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Color3<Magnum::UnsignedByte>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Color3<Magnum::UnsignedByte>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -1447,7 +1447,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Color4<Magnum::Uns
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Color4<Magnum::UnsignedByte>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Color4<Magnum::UnsignedByte>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -1465,7 +1465,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Color3<Magnum::Flo
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Color3<Magnum::Float>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Color3<Magnum::Float>> parse(Containers::StringView value);
};
/**
@ -1479,7 +1479,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Color4<Magnum::Flo
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Color4<Magnum::Float>> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Color4<Magnum::Float>> parse(Containers::StringView value);
};
#endif

18
src/Magnum/Math/Half.cpp

@ -30,8 +30,8 @@
#include <Corrade/Utility/DebugStl.h>
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
#include <algorithm>
#include <Corrade/Utility/String.h>
#include <algorithm> /** @todo get rid of this once StringView::find() exists */
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/TweakableParser.h>
#endif
@ -50,22 +50,24 @@ Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value)
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
namespace Corrade { namespace Utility {
std::pair<TweakableState, Magnum::Math::Half> TweakableParser<Magnum::Math::Half>::parse(const Containers::ArrayView<const char> value) {
std::pair<TweakableState, Magnum::Math::Half> TweakableParser<Magnum::Math::Half>::parse(const Containers::StringView value) {
using namespace Containers::Literals;
char* end;
const Magnum::Float result = std::strtof(value, &end);
const Magnum::Float result = std::strtof(value.data(), &end);
if(end == value.begin() || std::find(value.begin(), value.end(), '.') == value.end()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a half literal";
Warning{} << "Utility::TweakableParser:" << value << "is not a half literal";
return {TweakableState::Recompile, {}};
}
if(!String::viewEndsWith(value, "_h")) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected _h";
if(!value.hasSuffix("_h"_s)) {
Warning{} << "Utility::TweakableParser:" << value << "has an unexpected suffix, expected _h";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 2) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after a half literal";
Warning{} << "Utility::TweakableParser: unexpected characters" << value.suffix(end) << "after a half literal";
return {TweakableState::Recompile, {}};
}

2
src/Magnum/Math/Half.h

@ -213,7 +213,7 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Half> {
TweakableParser() = delete;
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Half> parse(Containers::ArrayView<const char> value);
static std::pair<TweakableState, Magnum::Math::Half> parse(Containers::StringView value);
};
}}

5
src/Magnum/Math/Test/AngleTest.cpp

@ -29,6 +29,7 @@
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/TweakableParser.h>
#endif
@ -294,7 +295,7 @@ template<class T> void AngleTest::tweakable() {
std::string input = Corrade::Utility::formatString(data.data, TweakableTraits<T>::literal());
Corrade::Utility::TweakableState state;
T result;
std::tie(state, result) = Corrade::Utility::TweakableParser<T>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<T>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, T(typename T::Type(data.result)));
}
@ -308,7 +309,7 @@ template<class T> void AngleTest::tweakableError() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<T>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<T>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, TweakableTraits<T>::literal()));
CORRADE_COMPARE(state, data.state);
}

33
src/Magnum/Math/Test/ColorTest.cpp

@ -28,6 +28,7 @@
#include <Corrade/TestSuite/Compare/Numeric.h>
#include <Corrade/Utility/DebugStl.h>
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Tweakable.h>
#endif
@ -1099,7 +1100,7 @@ void ColorTest::tweakableRgb() {
std::string input = Corrade::Utility::formatString(data.dataRgb, "rgb");
Corrade::Utility::TweakableState state;
Color3ub result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3ub>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3ub>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultUb.rgb());
}
@ -1110,7 +1111,7 @@ void ColorTest::tweakableSrgb() {
std::string input = Corrade::Utility::formatString(data.dataRgb, "srgb");
Corrade::Utility::TweakableState state;
Math::Vector3<UnsignedByte> result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Math::Vector3<UnsignedByte>>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Math::Vector3<UnsignedByte>>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultUb.rgb());
}
@ -1121,7 +1122,7 @@ void ColorTest::tweakableRgba() {
std::string input = Corrade::Utility::formatString(data.dataRgba, "rgba");
Corrade::Utility::TweakableState state;
Color4ub result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4ub>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4ub>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultUb);
}
@ -1132,7 +1133,7 @@ void ColorTest::tweakableSrgba() {
std::string input = Corrade::Utility::formatString(data.dataRgba, "srgba");
Corrade::Utility::TweakableState state;
Math::Vector4<UnsignedByte> result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Math::Vector4<UnsignedByte>>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Math::Vector4<UnsignedByte>>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultUb);
}
@ -1143,7 +1144,7 @@ void ColorTest::tweakableRgbf() {
std::string input = Corrade::Utility::formatString(data.dataRgb, "rgbf");
Corrade::Utility::TweakableState state;
Color3 result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.result.rgb());
}
@ -1154,7 +1155,7 @@ void ColorTest::tweakableSrgbf() {
std::string input = Corrade::Utility::formatString(data.dataRgb, "srgbf");
Corrade::Utility::TweakableState state;
Color3 result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color3>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultSrgba.rgb());
}
@ -1165,7 +1166,7 @@ void ColorTest::tweakableRgbaf() {
std::string input = Corrade::Utility::formatString(data.dataRgba, "rgbaf");
Corrade::Utility::TweakableState state;
Color4 result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.result);
}
@ -1176,7 +1177,7 @@ void ColorTest::tweakableSrgbaf() {
std::string input = Corrade::Utility::formatString(data.dataRgba, "srgbaf");
Corrade::Utility::TweakableState state;
Color4 result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4>::parse({input.data(), input.size()});
std::tie(state, result) = Corrade::Utility::TweakableParser<Color4>::parse(input);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.resultSrgba);
}
@ -1189,7 +1190,7 @@ void ColorTest::tweakableErrorRgb() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3ub>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3ub>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366", "rgb", ""));
CORRADE_COMPARE(state, data.state);
}
@ -1202,7 +1203,7 @@ void ColorTest::tweakableErrorSrgb() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Math::Vector3<UnsignedByte>>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Math::Vector3<UnsignedByte>>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366", "rgb", "s"));
CORRADE_COMPARE(state, data.state);
}
@ -1215,7 +1216,7 @@ void ColorTest::tweakableErrorRgba() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4ub>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4ub>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366aa", "rgba", ""));
CORRADE_COMPARE(state, data.state);
}
@ -1228,7 +1229,7 @@ void ColorTest::tweakableErrorSrgba() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Math::Vector4<UnsignedByte>>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Math::Vector4<UnsignedByte>>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366aa", "rgba", "s"));
CORRADE_COMPARE(state, data.state);
}
@ -1241,7 +1242,7 @@ void ColorTest::tweakableErrorRgbf() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366", "rgbf", ""));
CORRADE_COMPARE(state, data.state);
}
@ -1254,7 +1255,7 @@ void ColorTest::tweakableErrorSrgbf() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color3>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366", "rgbf", "s"));
CORRADE_COMPARE(state, data.state);
}
@ -1267,7 +1268,7 @@ void ColorTest::tweakableErrorRgbaf() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366aa", "rgbaf", ""));
CORRADE_COMPARE(state, data.state);
}
@ -1280,7 +1281,7 @@ void ColorTest::tweakableErrorSrgbaf() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4>::parse({input.data(), input.size()}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Color4>::parse(input).first;
CORRADE_COMPARE(out.str(), Corrade::Utility::formatString(data.error, "ff3366aa", "rgbaf", "s"));
CORRADE_COMPARE(state, data.state);
}

4
src/Magnum/Math/Test/HalfTest.cpp

@ -634,7 +634,7 @@ void HalfTest::tweakable() {
setTestCaseDescription(data.name);
Corrade::Utility::TweakableState state;
Half result;
std::tie(state, result) = Corrade::Utility::TweakableParser<Half>::parse({data.data, std::strlen(data.data)});
std::tie(state, result) = Corrade::Utility::TweakableParser<Half>::parse(data.data);
CORRADE_COMPARE(state, Corrade::Utility::TweakableState::Success);
CORRADE_COMPARE(result, data.result);
}
@ -646,7 +646,7 @@ void HalfTest::tweakableError() {
std::ostringstream out;
Warning redirectWarning{&out};
Error redirectError{&out};
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Half>::parse({data.data, std::strlen(data.data)}).first;
Corrade::Utility::TweakableState state = Corrade::Utility::TweakableParser<Half>::parse(data.data).first;
CORRADE_COMPARE(out.str(), data.error);
CORRADE_COMPARE(state, data.state);
}

Loading…
Cancel
Save