mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Added namespace
This commit is contained in:
@ -8,10 +8,14 @@
|
|||||||
#include "JsonObjectBase.h"
|
#include "JsonObjectBase.h"
|
||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
template<int N>
|
namespace ArduinoJson
|
||||||
class JsonArray : public JsonObjectBase
|
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
{
|
||||||
|
template<int N>
|
||||||
|
class JsonArray : public JsonObjectBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
JsonArray()
|
JsonArray()
|
||||||
{
|
{
|
||||||
itemCount = 0;
|
itemCount = 0;
|
||||||
@ -23,7 +27,7 @@ public:
|
|||||||
add(JsonValue(value));
|
add(JsonValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(double value, int digits=2)
|
void add(double value, int digits = 2)
|
||||||
{
|
{
|
||||||
add(JsonValue(value, digits));
|
add(JsonValue(value, digits));
|
||||||
}
|
}
|
||||||
@ -38,7 +42,7 @@ public:
|
|||||||
|
|
||||||
using JsonObjectBase::printTo;
|
using JsonObjectBase::printTo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonValue items[N];
|
JsonValue items[N];
|
||||||
int itemCount;
|
int itemCount;
|
||||||
|
|
||||||
@ -62,5 +66,6 @@ private:
|
|||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -7,10 +7,14 @@
|
|||||||
|
|
||||||
#include "JsonObjectBase.h"
|
#include "JsonObjectBase.h"
|
||||||
|
|
||||||
template<int N>
|
namespace ArduinoJson
|
||||||
class JsonHashTable : public JsonObjectBase
|
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
{
|
||||||
|
template<int N>
|
||||||
|
class JsonHashTable : public JsonObjectBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
JsonHashTable()
|
JsonHashTable()
|
||||||
{
|
{
|
||||||
@ -23,7 +27,7 @@ public:
|
|||||||
add(key, JsonValue(value));
|
add(key, JsonValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(const char* key, double value, int digits=2)
|
void add(const char* key, double value, int digits = 2)
|
||||||
{
|
{
|
||||||
add(key, JsonValue(value, digits));
|
add(key, JsonValue(value, digits));
|
||||||
}
|
}
|
||||||
@ -39,7 +43,7 @@ public:
|
|||||||
|
|
||||||
using JsonObjectBase::printTo;
|
using JsonObjectBase::printTo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct KeyValuePair
|
struct KeyValuePair
|
||||||
{
|
{
|
||||||
@ -74,5 +78,6 @@ private:
|
|||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -9,9 +9,13 @@
|
|||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
#include "Printable.h"
|
#include "Printable.h"
|
||||||
|
|
||||||
class JsonObjectBase : public Printable
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
{
|
||||||
|
class JsonObjectBase : public Printable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
size_t printTo(char* buffer, size_t bufferSize)
|
size_t printTo(char* buffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
@ -20,5 +24,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t printTo(Print& p) const = 0;
|
virtual size_t printTo(Print& p) const = 0;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "JsonValue.h"
|
#include "JsonValue.h"
|
||||||
|
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
size_t JsonValue::printBoolTo(Print& p) const
|
size_t JsonValue::printBoolTo(Print& p) const
|
||||||
{
|
{
|
||||||
return p.print(content.asBool ? "true" : "false");
|
return p.print(content.asBool ? "true" : "false");
|
||||||
|
@ -8,9 +8,13 @@
|
|||||||
#include "Printable.h"
|
#include "Printable.h"
|
||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
class JsonValue : public Printable
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
{
|
||||||
|
class JsonValue : public Printable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
JsonValue()
|
JsonValue()
|
||||||
{
|
{
|
||||||
@ -22,7 +26,7 @@ public:
|
|||||||
content.asBool = value;
|
content.asBool = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue(double value, int digits=2)
|
JsonValue(double value, int digits = 2)
|
||||||
: implementation(&JsonValue::printDoubleTo)
|
: implementation(&JsonValue::printDoubleTo)
|
||||||
{
|
{
|
||||||
content.asDouble.value = value;
|
content.asDouble.value = value;
|
||||||
@ -65,7 +69,7 @@ public:
|
|||||||
return (this->*implementation)(p);
|
return (this->*implementation)(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
union Content
|
union Content
|
||||||
{
|
{
|
||||||
@ -91,4 +95,6 @@ private:
|
|||||||
size_t printLongTo(Print& p) const;
|
size_t printLongTo(Print& p) const;
|
||||||
size_t printPrintableTo(Print& p) const;
|
size_t printPrintableTo(Print& p) const;
|
||||||
size_t printStringTo(Print& p) const;
|
size_t printStringTo(Print& p) const;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
size_t StringBuilder::write(uint8_t c)
|
size_t StringBuilder::write(uint8_t c)
|
||||||
{
|
{
|
||||||
if (length >= capacity) return 0;
|
if (length >= capacity) return 0;
|
||||||
|
@ -7,20 +7,25 @@
|
|||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
class StringBuilder : public Print
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
public:
|
namespace Generator
|
||||||
|
{
|
||||||
|
class StringBuilder : public Print
|
||||||
|
{
|
||||||
|
public:
|
||||||
StringBuilder(char* buf, int size)
|
StringBuilder(char* buf, int size)
|
||||||
: buffer(buf), capacity(size-1), length(0)
|
: buffer(buf), capacity(size - 1), length(0)
|
||||||
{
|
{
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t c);
|
virtual size_t write(uint8_t c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* buffer;
|
char* buffer;
|
||||||
int capacity;
|
int capacity;
|
||||||
int length;
|
int length;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include "JsonHashTable.h"
|
#include "JsonHashTable.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "JsonHashTable.h"
|
#include "JsonHashTable.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "JsonValue.h"
|
#include "JsonValue.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
namespace JsonGeneratorTests
|
namespace JsonGeneratorTests
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <JsonGenerator.h>
|
#include <JsonGenerator.h>
|
||||||
|
|
||||||
|
using namespace ArduinoJson::Generator;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
Reference in New Issue
Block a user