From efa55eb5b3d3a4942789bdf397c3a6d6226475d4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 7 Sep 2020 12:57:22 +0200 Subject: Revert "remove external libraries from main branch" This reverts commit 0558244645611f314f47e0fa427f7323ce253eaf. --- include/lib/ArduinoJson/JsonVariantComparisons.hpp | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 include/lib/ArduinoJson/JsonVariantComparisons.hpp (limited to 'include/lib/ArduinoJson/JsonVariantComparisons.hpp') diff --git a/include/lib/ArduinoJson/JsonVariantComparisons.hpp b/include/lib/ArduinoJson/JsonVariantComparisons.hpp new file mode 100644 index 0000000..47f9d63 --- /dev/null +++ b/include/lib/ArduinoJson/JsonVariantComparisons.hpp @@ -0,0 +1,139 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "StringTraits/StringTraits.hpp" +#include "TypeTraits/EnableIf.hpp" +#include "TypeTraits/IsVariant.hpp" + +namespace ArduinoJson { +namespace Internals { + +template +class JsonVariantComparisons { + public: + template + friend bool operator==(const JsonVariantComparisons &variant, + TComparand comparand) { + return variant.equals(comparand); + } + + template + friend typename EnableIf::value, bool>::type + operator==(TComparand comparand, const JsonVariantComparisons &variant) { + return variant.equals(comparand); + } + + template + friend bool operator!=(const JsonVariantComparisons &variant, + TComparand comparand) { + return !variant.equals(comparand); + } + + template + friend typename EnableIf::value, bool>::type + operator!=(TComparand comparand, const JsonVariantComparisons &variant) { + return !variant.equals(comparand); + } + + template + friend bool operator<=(const JsonVariantComparisons &left, TComparand right) { + return left.as() <= right; + } + + template + friend bool operator<=(TComparand comparand, + const JsonVariantComparisons &variant) { + return comparand <= variant.as(); + } + + template + friend bool operator>=(const JsonVariantComparisons &variant, + TComparand comparand) { + return variant.as() >= comparand; + } + + template + friend bool operator>=(TComparand comparand, + const JsonVariantComparisons &variant) { + return comparand >= variant.as(); + } + + template + friend bool operator<(const JsonVariantComparisons &varian, + TComparand comparand) { + return varian.as() < comparand; + } + + template + friend bool operator<(TComparand comparand, + const JsonVariantComparisons &variant) { + return comparand < variant.as(); + } + + template + friend bool operator>(const JsonVariantComparisons &variant, + TComparand comparand) { + return variant.as() > comparand; + } + + template + friend bool operator>(TComparand comparand, + const JsonVariantComparisons &variant) { + return comparand > variant.as(); + } + + private: + const TImpl *impl() const { + return static_cast(this); + } + + template + const typename JsonVariantAs::type as() const { + return impl()->template as(); + } + + template + bool is() const { + return impl()->template is(); + } + + template + typename EnableIf::has_equals, bool>::type equals( + const TString &comparand) const { + const char *value = as(); + return StringTraits::equals(comparand, value); + } + + template + typename EnableIf::value && + !StringTraits::has_equals, + bool>::type + equals(const TComparand &comparand) const { + return as() == comparand; + } + + template + bool equals(const JsonVariantComparisons &right) const { + using namespace Internals; + if (is() && right.template is()) + return as() == right.template as(); + if (is() && right.template is()) + return as() == right.template as(); + if (is() && right.template is()) + return as() == right.template as(); + if (is() && right.template is()) + return as() == right.template as(); + if (is() && right.template is()) + return as() == right.template as(); + if (is() && right.template is()) + return StringTraits::equals(as(), + right.template as()); + + return false; + } +}; +} // namespace Internals +} // namespace ArduinoJson -- cgit v1.2.3