diff --git a/JsonGenerator.cpp b/JsonGenerator.cpp index 8d6444be..e4a4148e 100644 --- a/JsonGenerator.cpp +++ b/JsonGenerator.cpp @@ -7,6 +7,6 @@ #include "JsonGenerator/EscapedString.cpp" #include "JsonGenerator/JsonArrayBase.cpp" +#include "JsonGenerator/JsonObjectBase.cpp" #include "JsonGenerator/JsonValue.cpp" -#include "JsonGenerator/JsonHashTableBase.cpp" #include "JsonGenerator/StringBuilder.cpp" \ No newline at end of file diff --git a/JsonGenerator.h b/JsonGenerator.h index bd0ed9d7..00bab65c 100644 --- a/JsonGenerator.h +++ b/JsonGenerator.h @@ -4,4 +4,4 @@ */ #include "JsonGenerator/JsonArray.h" -#include "JsonGenerator/JsonHashTable.h" \ No newline at end of file +#include "JsonGenerator/JsonObject.h" \ No newline at end of file diff --git a/JsonGenerator/JsonGenerator.vcxproj b/JsonGenerator/JsonGenerator.vcxproj index 41274378..34d5febc 100644 --- a/JsonGenerator/JsonGenerator.vcxproj +++ b/JsonGenerator/JsonGenerator.vcxproj @@ -14,8 +14,8 @@ - - + + @@ -25,7 +25,7 @@ - + diff --git a/JsonGenerator/JsonGenerator.vcxproj.filters b/JsonGenerator/JsonGenerator.vcxproj.filters index 431c9ad0..d8912d64 100644 --- a/JsonGenerator/JsonGenerator.vcxproj.filters +++ b/JsonGenerator/JsonGenerator.vcxproj.filters @@ -24,12 +24,6 @@ Header Files - - Header Files - - - Header Files - Header Files @@ -45,6 +39,12 @@ Header Files + + Header Files + + + Header Files + @@ -53,9 +53,6 @@ Source Files - - Source Files - Source Files @@ -65,5 +62,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/JsonGenerator/JsonHashTable.h b/JsonGenerator/JsonHashTable.h deleted file mode 100644 index b7bf9f45..00000000 --- a/JsonGenerator/JsonHashTable.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Arduino JSON library - * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "JsonHashTableBase.h" - -namespace ArduinoJson -{ - namespace Generator - { - template - class JsonHashTable : public JsonHashTableBase - { - public: - JsonHashTable() - : JsonHashTableBase(items, N) - { - } - - private: - KeyValuePair items[N]; - }; - } -} \ No newline at end of file diff --git a/JsonGenerator/JsonObject.h b/JsonGenerator/JsonObject.h new file mode 100644 index 00000000..76048c43 --- /dev/null +++ b/JsonGenerator/JsonObject.h @@ -0,0 +1,44 @@ +/* + * Arduino JSON library + * Benoit Blanchon 2014 - MIT License + */ + +#pragma once + +#include "JsonObjectBase.h" + +#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING +#ifdef __GNUC__ +#define DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#endif +#else +#define DEPRECATED +#endif + +namespace ArduinoJson +{ + namespace Generator + { + template + class JsonObject : public JsonObjectBase + { + public: + JsonObject() + : JsonObjectBase(items, N) + { + } + + private: + KeyValuePair items[N]; + }; + + + // Obsolete: use JsonObject instead + template + class DEPRECATED JsonHashTable : public JsonObject + { + }; + } +} \ No newline at end of file diff --git a/JsonGenerator/JsonHashTableBase.cpp b/JsonGenerator/JsonObjectBase.cpp similarity index 83% rename from JsonGenerator/JsonHashTableBase.cpp rename to JsonGenerator/JsonObjectBase.cpp index 27bb3977..9c99e4a6 100644 --- a/JsonGenerator/JsonHashTableBase.cpp +++ b/JsonGenerator/JsonObjectBase.cpp @@ -3,11 +3,11 @@ * Benoit Blanchon 2014 - MIT License */ -#include "JsonHashTable.h" +#include "JsonObjectBase.h" using namespace ArduinoJson::Generator; -size_t JsonHashTableBase::printTo(Print& p) const +size_t JsonObjectBase::printTo(Print& p) const { size_t n = 0; diff --git a/JsonGenerator/JsonHashTableBase.h b/JsonGenerator/JsonObjectBase.h similarity index 87% rename from JsonGenerator/JsonHashTableBase.h rename to JsonGenerator/JsonObjectBase.h index ffb5b6db..89f38da7 100644 --- a/JsonGenerator/JsonHashTableBase.h +++ b/JsonGenerator/JsonObjectBase.h @@ -12,7 +12,7 @@ namespace ArduinoJson { namespace Generator { - class JsonHashTableBase : public JsonPrintable + class JsonObjectBase : public JsonPrintable { public: @@ -48,7 +48,7 @@ namespace ArduinoJson Internals::JsonValue value; }; - JsonHashTableBase(KeyValuePair* items, int capacity) + JsonObjectBase(KeyValuePair* items, int capacity) : items(items), capacity(capacity), count(0) { } diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index df4dcb8b..51be76b4 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -16,14 +16,14 @@ namespace ArduinoJson class JsonValue { public: - + void set(bool value) { printToImpl = &printBoolTo; content.asBool = value; } - void set(long value) + void set(long value) { printToImpl = &printLongTo; content.asLong = value; @@ -52,7 +52,7 @@ namespace ArduinoJson set<2>(value); } - template + template void set(double value) { printToImpl = &printDoubleTo; @@ -68,23 +68,23 @@ namespace ArduinoJson private: union Content { - bool asBool; - long asLong; - Printable* asPrintable; + bool asBool; + long asLong; + Printable* asPrintable; EscapedString asString; - double asDouble; + double asDouble; }; Content content; - size_t(*printToImpl)(const Content&, Print&); + size_t(* printToImpl)(const Content&, Print&); static size_t printBoolTo(const Content&, Print&); static size_t printLongTo(const Content&, Print&); static size_t printPrintableTo(const Content&, Print&); static size_t printStringTo(const Content&, Print&); - template + template static size_t printDoubleTo(const Content& c, Print& p) { return p.print(c.asDouble, DIGITS); diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp index f4886cf4..f26135a2 100644 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ b/JsonGeneratorTests/JsonArrayTests.cpp @@ -5,7 +5,7 @@ #include "CppUnitTest.h" #include "JsonArray.h" -#include "JsonHashTable.h" +#include "JsonObject.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace ArduinoJson::Generator; diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj b/JsonGeneratorTests/JsonGeneratorTests.vcxproj index 0d0453df..6428431d 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj @@ -55,7 +55,7 @@ Level3 Disabled $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - _DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ARDUINO_JSON_NO_DEPRECATION_WARNING;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true diff --git a/JsonGeneratorTests/JsonHashTableTests.cpp b/JsonGeneratorTests/JsonHashTableTests.cpp index f546efdb..614d6725 100644 --- a/JsonGeneratorTests/JsonHashTableTests.cpp +++ b/JsonGeneratorTests/JsonHashTableTests.cpp @@ -5,7 +5,7 @@ #include "CppUnitTest.h" #include "JsonArray.h" -#include "JsonHashTable.h" +#include "JsonObject.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace ArduinoJson::Generator; diff --git a/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/examples/JsonGeneratorExample/JsonGeneratorExample.ino index 71158be8..94a4b9fd 100644 --- a/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ b/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -15,7 +15,7 @@ void setup() array.add<6>(48.756080); // 6 is the number of decimals to print array.add<6>(2.302038); // if not specified, 2 digits are printed - JsonHashTable<3> root; + JsonObject<3> root; root.add("sensor", "gps"); root.add("time", 1351824120); root.add("data", array); diff --git a/examples/JsonParserExample/JsonParserExample.ino b/examples/JsonParserExample/JsonParserExample.ino index 99dae4f7..5c391bac 100644 --- a/examples/JsonParserExample/JsonParserExample.ino +++ b/examples/JsonParserExample/JsonParserExample.ino @@ -15,7 +15,7 @@ void setup() JsonParser<16> parser; - JsonHashTable root = parser.parse(json); + JsonObject root = parser.parse(json); if (!root.success()) { diff --git a/keywords.txt b/keywords.txt index 2110db66..e2536590 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,10 +1,6 @@ JsonParser KEYWORD1 JsonArray KEYWORD1 -JsonHashTable KEYWORD1 -getArray KEYWORD2 -getBool KEYWORD2 -getDouble KEYWORD2 -getHashTableKEYWORD2 -getLong KEYWORD2 -parseArray KEYWORD2 -parseHashTable KEYWORD2 +JsonObject KEYWORD1 +add KEYWORD2 +parse KEYWORD2 +success KEYWORD2