forked from bblanchon/ArduinoJson
Renamed union members
This commit is contained in:
@ -9,29 +9,29 @@
|
||||
|
||||
size_t JsonValue::printBooleanTo(Print& p) const
|
||||
{
|
||||
return p.write(content.boolean ? "true" : "false");
|
||||
return p.write(content.asBool ? "true" : "false");
|
||||
}
|
||||
|
||||
size_t JsonValue::printNumberTo(Print& p) const
|
||||
{
|
||||
char tmp[16];
|
||||
|
||||
sprintf(tmp, "%lg", content.number);
|
||||
sprintf(tmp, "%lg", content.asDouble);
|
||||
|
||||
return p.write(tmp);
|
||||
}
|
||||
|
||||
size_t JsonValue::printObjectTo(Print& p) const
|
||||
{
|
||||
if (content.object)
|
||||
return ((Printable*) content.object)->printTo(p);
|
||||
if (content.asPrintable)
|
||||
return ((Printable*) content.asPrintable)->printTo(p);
|
||||
else
|
||||
return p.write("null");
|
||||
}
|
||||
|
||||
size_t JsonValue::printStringTo(Print& p) const
|
||||
{
|
||||
const char* s = content.string;
|
||||
const char* s = content.asString;
|
||||
|
||||
if (!s)
|
||||
{
|
||||
|
@ -19,25 +19,25 @@ public:
|
||||
JsonValue(const char* value)
|
||||
: implementation(&JsonValue::printStringTo)
|
||||
{
|
||||
content.string = value;
|
||||
content.asString = value;
|
||||
}
|
||||
|
||||
JsonValue(double value)
|
||||
: implementation(&JsonValue::printNumberTo)
|
||||
{
|
||||
content.number = value;
|
||||
content.asDouble = value;
|
||||
}
|
||||
|
||||
JsonValue(bool value)
|
||||
: implementation(&JsonValue::printBooleanTo)
|
||||
{
|
||||
content.boolean = value;
|
||||
content.asBool = value;
|
||||
}
|
||||
|
||||
JsonValue(Printable& value)
|
||||
: implementation(&JsonValue::printObjectTo)
|
||||
{
|
||||
content.object = &value;
|
||||
content.asPrintable = &value;
|
||||
}
|
||||
|
||||
virtual size_t printTo(Print& p) const
|
||||
@ -50,10 +50,10 @@ private:
|
||||
|
||||
union Content
|
||||
{
|
||||
bool boolean;
|
||||
double number;
|
||||
Printable* object;
|
||||
const char* string;
|
||||
bool asBool;
|
||||
double asDouble;
|
||||
Printable* asPrintable;
|
||||
const char* asString;
|
||||
};
|
||||
|
||||
Content content;
|
||||
|
Reference in New Issue
Block a user