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