mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Remove safe bool idiom (#1820)
This commit is contained in:
		| @@ -4,7 +4,6 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <ArduinoJson/Misc/SafeBoolIdiom.hpp> |  | ||||||
| #include <ArduinoJson/Namespace.hpp> | #include <ArduinoJson/Namespace.hpp> | ||||||
| #include <ArduinoJson/Polyfills/pgmspace_generic.hpp> | #include <ArduinoJson/Polyfills/pgmspace_generic.hpp> | ||||||
| #include <ArduinoJson/Polyfills/preprocessor.hpp> | #include <ArduinoJson/Polyfills/preprocessor.hpp> | ||||||
| @@ -15,7 +14,7 @@ | |||||||
|  |  | ||||||
| namespace ARDUINOJSON_NAMESPACE { | namespace ARDUINOJSON_NAMESPACE { | ||||||
|  |  | ||||||
| class DeserializationError : public SafeBoolIdom<DeserializationError> { | class DeserializationError { | ||||||
|  public: |  public: | ||||||
|   enum Code { |   enum Code { | ||||||
|     Ok, |     Ok, | ||||||
| @@ -53,9 +52,9 @@ class DeserializationError : public SafeBoolIdom<DeserializationError> { | |||||||
|     return lhs != rhs._code; |     return lhs != rhs._code; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Behaves like a bool |   // Returns true if there is an error | ||||||
|   operator bool_type() const { |   explicit operator bool() const { | ||||||
|     return _code != Ok ? safe_true() : safe_false(); |     return _code != Ok; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Returns internal enum, useful for switch statement |   // Returns internal enum, useful for switch statement | ||||||
|   | |||||||
| @@ -1,26 +0,0 @@ | |||||||
| // ArduinoJson - https://arduinojson.org |  | ||||||
| // Copyright © 2014-2022, Benoit BLANCHON |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #pragma once |  | ||||||
|  |  | ||||||
| #include <ArduinoJson/Polyfills/type_traits.hpp> |  | ||||||
|  |  | ||||||
| namespace ARDUINOJSON_NAMESPACE { |  | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| class SafeBoolIdom { |  | ||||||
|  protected: |  | ||||||
|   typedef void (T::*bool_type)() const; |  | ||||||
|   void safeBoolHelper() const {} |  | ||||||
|  |  | ||||||
|   static bool_type safe_true() { |  | ||||||
|     return &SafeBoolIdom::safeBoolHelper; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   static bool_type safe_false() { |  | ||||||
|     return 0; |  | ||||||
|   } |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| }  // namespace ARDUINOJSON_NAMESPACE |  | ||||||
| @@ -4,8 +4,6 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <ArduinoJson/Misc/SafeBoolIdiom.hpp> |  | ||||||
|  |  | ||||||
| #if ARDUINOJSON_ENABLE_STD_STREAM | #if ARDUINOJSON_ENABLE_STD_STREAM | ||||||
| #  include <ostream> | #  include <ostream> | ||||||
| #endif | #endif | ||||||
| @@ -14,7 +12,7 @@ namespace ARDUINOJSON_NAMESPACE { | |||||||
|  |  | ||||||
| // A string. | // A string. | ||||||
| // https://arduinojson.org/v6/api/jsonstring/ | // https://arduinojson.org/v6/api/jsonstring/ | ||||||
| class JsonString : public SafeBoolIdom<JsonString> { | class JsonString { | ||||||
|  public: |  public: | ||||||
|   enum Ownership { Copied, Linked }; |   enum Ownership { Copied, Linked }; | ||||||
|  |  | ||||||
| @@ -47,9 +45,9 @@ class JsonString : public SafeBoolIdom<JsonString> { | |||||||
|     return _size; |     return _size; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // safe bool idiom |   // Returns true if the string is non-null | ||||||
|   operator bool_type() const { |   explicit operator bool() const { | ||||||
|     return _data ? safe_true() : safe_false(); |     return _data != 0; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Returns true if strings are equal. |   // Returns true if strings are equal. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user