// Copyright Benoit Blanchon 2014-2015 // MIT License // // Arduino JSON library // https://github.com/bblanchon/ArduinoJson #pragma once #include "JsonVariant.hpp" namespace ArduinoJson { inline JsonVariant::JsonVariant(bool value) { _type = Internals::JSON_BOOLEAN; _content.asBoolean = value; } inline JsonVariant::JsonVariant(const char *value) { _type = Internals::JSON_STRING; _content.asString = value; } inline JsonVariant::JsonVariant(const String &value) { _type = Internals::JSON_STRING; _content.asString = value.c_str(); } inline JsonVariant::JsonVariant(double value, uint8_t decimals) { _type = static_cast( Internals::JSON_DOUBLE_0_DECIMALS + decimals); _content.asDouble = value; } inline JsonVariant::JsonVariant(float value, uint8_t decimals) { _type = static_cast( Internals::JSON_DOUBLE_0_DECIMALS + decimals); _content.asDouble = value; } inline JsonVariant::JsonVariant(JsonArray &array) { _type = Internals::JSON_ARRAY; _content.asArray = &array; } inline JsonVariant::JsonVariant(JsonObject &object) { _type = Internals::JSON_OBJECT; _content.asObject = &object; } inline JsonVariant::JsonVariant(signed char value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(signed int value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(signed long value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(signed short value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(unsigned char value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(unsigned int value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(unsigned long value) { _type = Internals::JSON_LONG; _content.asLong = value; } inline JsonVariant::JsonVariant(unsigned short value) { _type = Internals::JSON_LONG; _content.asLong = value; } template inline T JsonVariant::as() const { return is() ? _content.as() : invalid(); } template inline T JsonVariant::invalid() { return T(); } template inline bool JsonVariant::is() const { return false; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_BOOLEAN; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_STRING; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_STRING; } template <> inline bool JsonVariant::is() const { return _type >= Internals::JSON_DOUBLE_0_DECIMALS; } template <> inline bool JsonVariant::is() const { return _type >= Internals::JSON_DOUBLE_0_DECIMALS; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_ARRAY; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_ARRAY; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_OBJECT; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_OBJECT; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } template <> inline bool JsonVariant::is() const { return _type == Internals::JSON_LONG; } #ifdef ARDUINOJSON_ENABLE_STD_STREAM inline std::ostream& operator<<(std::ostream& os, const JsonVariant& source) { return source.printTo(os); } #endif } // namespace ArduinoJson