From 074c39ca5b3ad6312501c846b5a9029e8cc4b4d0 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 18 Oct 2014 23:05:54 +0200 Subject: [PATCH] Fixed namespaces --- .../ArduinoJson/Internals/CompactJsonWriter.h | 65 ++-- include/ArduinoJson/Internals/IndentedPrint.h | 2 +- include/ArduinoJson/Internals/JsonNode.h | 357 +++++++++--------- .../ArduinoJson/Internals/JsonNodeIterator.h | 65 ++-- .../ArduinoJson/Internals/JsonNodeWrapper.h | 64 ++-- include/ArduinoJson/Internals/JsonParser.h | 79 ++-- include/ArduinoJson/Internals/JsonWriter.h | 89 ++--- .../ArduinoJson/Internals/PrettyJsonWriter.h | 100 ++--- include/ArduinoJson/JsonArray.h | 48 +-- include/ArduinoJson/JsonBuffer.h | 64 ++-- include/ArduinoJson/JsonContainer.h | 77 ++-- include/ArduinoJson/JsonObject.h | 35 +- include/ArduinoJson/JsonValue.h | 55 +-- include/ArduinoJson/StaticJsonBuffer.h | 58 +-- src/Internals/IndentedPrint.cpp | 2 +- src/Internals/JsonNode.cpp | 2 + src/JsonArray.cpp | 3 + src/JsonBuffer.cpp | 3 + src/JsonContainer.cpp | 1 + src/JsonObject.cpp | 1 + src/JsonValue.cpp | 2 + test/Issue10.cpp | 2 +- test/JsonArray_Container_Tests.cpp | 2 + test/JsonArray_PrettyPrintTo_Tests.cpp | 2 + test/JsonArray_PrintTo_Tests.cpp | 2 + test/JsonObject_Container_Tests.cpp | 2 + test/JsonObject_PrettyPrintTo_Tests.cpp | 2 + test/JsonObject_Serialization_Tests.cpp | 2 + test/JsonParser_Array_Tests.cpp | 2 + test/JsonValueTests.cpp | 2 + test/StaticJsonBufferTests.cpp | 2 + 31 files changed, 638 insertions(+), 554 deletions(-) diff --git a/include/ArduinoJson/Internals/CompactJsonWriter.h b/include/ArduinoJson/Internals/CompactJsonWriter.h index 53911cdb..326271b9 100644 --- a/include/ArduinoJson/Internals/CompactJsonWriter.h +++ b/include/ArduinoJson/Internals/CompactJsonWriter.h @@ -2,42 +2,47 @@ #include "ArduinoJson/Internals/JsonWriter.h" -class CompactJsonWriter : public JsonWriter +namespace ArduinoJson { -public: - explicit CompactJsonWriter(Print* sink) - : JsonWriter(sink) + namespace Internals { - } + class CompactJsonWriter : public JsonWriter + { + public: + explicit CompactJsonWriter(Print* sink) + : JsonWriter(sink) + { + } - virtual void beginArray() - { - _length += _sink->write('['); - } + virtual void beginArray() + { + _length += _sink->write('['); + } - virtual void endArray() - { - _length += _sink->write(']'); - } + virtual void endArray() + { + _length += _sink->write(']'); + } - virtual void writeColon() - { - _length += _sink->write(':'); - } + virtual void writeColon() + { + _length += _sink->write(':'); + } - virtual void writeComma() - { - _length += _sink->write(','); - } + virtual void writeComma() + { + _length += _sink->write(','); + } - virtual void beginObject() - { - _length += _sink->write('{'); - } + virtual void beginObject() + { + _length += _sink->write('{'); + } - virtual void endObject() - { - _length += _sink->write('}'); + virtual void endObject() + { + _length += _sink->write('}'); + } + }; } -}; - +} \ No newline at end of file diff --git a/include/ArduinoJson/Internals/IndentedPrint.h b/include/ArduinoJson/Internals/IndentedPrint.h index 899fb915..66b37f63 100644 --- a/include/ArduinoJson/Internals/IndentedPrint.h +++ b/include/ArduinoJson/Internals/IndentedPrint.h @@ -9,7 +9,7 @@ namespace ArduinoJson { - namespace Generator + namespace Internals { // Decorator on top of Print to allow indented output. // This class is used by JsonPrintable::prettyPrintTo() but can also be used diff --git a/include/ArduinoJson/Internals/JsonNode.h b/include/ArduinoJson/Internals/JsonNode.h index d9be3c3e..89d7bfd5 100644 --- a/include/ArduinoJson/Internals/JsonNode.h +++ b/include/ArduinoJson/Internals/JsonNode.h @@ -1,181 +1,188 @@ #pragma once -class JsonBuffer; -class JsonWriter; -class JsonNodeIterator; - -class JsonNode +namespace ArduinoJson { - friend class JsonNodeIterator; - - enum JsonNodeType - { - JSON_UNDEFINED, - JSON_NULL, - JSON_ARRAY, - JSON_OBJECT, - JSON_KEY_VALUE, - JSON_BOOLEAN, - JSON_STRING, - JSON_LONG, - JSON_PROXY, - JSON_DOUBLE_0_DECIMALS, - JSON_DOUBLE_1_DECIMAL, - JSON_DOUBLE_2_DECIMALS, - // etc. - }; - - union JsonNodeContent - { - bool asBoolean; - double asDouble; - long asInteger; - const char* asString; - - struct - { - const char* key; - JsonNode* value; - } asKey; - - struct - { - JsonNode* child; - JsonBuffer* buffer; - } asContainer; - - struct - { - JsonNode* target; - } asProxy; - - }; - -public: - JsonNode() - : type(JSON_UNDEFINED), next(0) - { - - } + class JsonBuffer; - void writeTo(JsonWriter&); // TODO: <- move in JsonNodeSerializer - - void setAsArray(JsonBuffer* buffer) + namespace Internals { - type = JSON_ARRAY; - content.asContainer.child = 0; - content.asContainer.buffer = buffer; + class JsonWriter; + class JsonNodeIterator; + + class JsonNode + { + friend class JsonNodeIterator; + + enum JsonNodeType + { + JSON_UNDEFINED, + JSON_NULL, + JSON_ARRAY, + JSON_OBJECT, + JSON_KEY_VALUE, + JSON_BOOLEAN, + JSON_STRING, + JSON_LONG, + JSON_PROXY, + JSON_DOUBLE_0_DECIMALS, + JSON_DOUBLE_1_DECIMAL, + JSON_DOUBLE_2_DECIMALS, + // etc. + }; + + union JsonNodeContent + { + bool asBoolean; + double asDouble; + long asInteger; + const char* asString; + + struct + { + const char* key; + JsonNode* value; + } asKey; + + struct + { + JsonNode* child; + JsonBuffer* buffer; + } asContainer; + + struct + { + JsonNode* target; + } asProxy; + + }; + + public: + JsonNode() + : type(JSON_UNDEFINED), next(0) + { + + } + + void writeTo(JsonWriter&); // TODO: <- move in JsonNodeSerializer + + void setAsArray(JsonBuffer* buffer) + { + type = JSON_ARRAY; + content.asContainer.child = 0; + content.asContainer.buffer = buffer; + } + + void setAsBoolean(bool value) + { + type = JSON_BOOLEAN; + content.asBoolean = value; + } + + void setAsLong(int value) + { + type = JSON_LONG; + content.asInteger = value; + } + + void setAsString(char const* value) + { + type = JSON_STRING; + content.asString = value; + } + + void setAsDouble(double value, int decimals) + { + type = static_cast(JSON_DOUBLE_0_DECIMALS + decimals); + content.asDouble = value; + } + + void setAsObject(JsonBuffer* buffer) + { + type = JSON_OBJECT; + content.asContainer.child = 0; + content.asContainer.buffer = buffer; + } + + void setAsObjectKeyValue(const char* key, JsonNode* value) + { + type = JSON_KEY_VALUE; + content.asKey.key = key; + content.asKey.value = value; + } + + bool getAsBoolean() + { + return type == JSON_BOOLEAN ? content.asBoolean : false; + } + + double getAsDouble() + { + return type >= JSON_DOUBLE_0_DECIMALS ? content.asDouble : 0; + } + + long getAsInteger() + { + return type == JSON_LONG ? content.asInteger : 0; + } + + const char* getAsString() + { + return type == JSON_STRING ? content.asString : 0; + } + + JsonBuffer* getContainerBuffer() + { + if (type == JSON_PROXY) return content.asProxy.target->getContainerBuffer(); + return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.buffer : 0; + } + + JsonNode* getContainerChild() + { + if (type == JSON_PROXY) return content.asProxy.target->getContainerChild(); + return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.child : 0; + } + + const char* getAsObjectKey() + { + return type == JSON_KEY_VALUE ? content.asKey.key : 0; + } + + JsonNode* getAsObjectValue() + { + return type == JSON_KEY_VALUE ? content.asKey.value : 0; + } + + JsonNode* getProxyTarget() + { + return type == JSON_PROXY ? content.asProxy.target : this; + } + + bool isArray() + { + return type == JSON_ARRAY; + } + + void addChild(JsonNode* childToAdd); + + void removeChild(JsonNode* childToRemove); + + void duplicate(JsonNode* other); + + private: + JsonNodeType type; + JsonNode* next; + JsonNodeContent content; + + inline void writeArrayTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer + inline void writeObjectTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer + + void setAsProxyOfSelf(); + + void setAsProxyOf(JsonNode* target) + { + type = JSON_PROXY; + content.asProxy.target = target; + } + }; } - - void setAsBoolean(bool value) - { - type = JSON_BOOLEAN; - content.asBoolean = value; - } - - void setAsLong(int value) - { - type = JSON_LONG; - content.asInteger = value; - } - - void setAsString(char const* value) - { - type = JSON_STRING; - content.asString = value; - } - - void setAsDouble(double value, int decimals) - { - type = static_cast(JSON_DOUBLE_0_DECIMALS + decimals); - content.asDouble = value; - } - - void setAsObject(JsonBuffer* buffer) - { - type = JSON_OBJECT; - content.asContainer.child = 0; - content.asContainer.buffer = buffer; - } - - void setAsObjectKeyValue(const char* key, JsonNode* value) - { - type = JSON_KEY_VALUE; - content.asKey.key = key; - content.asKey.value = value; - } - - bool getAsBoolean() - { - return type == JSON_BOOLEAN ? content.asBoolean : false; - } - - double getAsDouble() - { - return type >= JSON_DOUBLE_0_DECIMALS ? content.asDouble : 0; - } - - long getAsInteger() - { - return type == JSON_LONG ? content.asInteger : 0; - } - - const char* getAsString() - { - return type == JSON_STRING ? content.asString : 0; - } - - JsonBuffer* getContainerBuffer() - { - if (type == JSON_PROXY) return content.asProxy.target->getContainerBuffer(); - return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.buffer : 0; - } - - JsonNode* getContainerChild() - { - if (type == JSON_PROXY) return content.asProxy.target->getContainerChild(); - return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.child : 0; - } - - const char* getAsObjectKey() - { - return type == JSON_KEY_VALUE ? content.asKey.key : 0; - } - - JsonNode* getAsObjectValue() - { - return type == JSON_KEY_VALUE ? content.asKey.value : 0; - } - - JsonNode* getProxyTarget() - { - return type == JSON_PROXY ? content.asProxy.target : this; - } - - bool isArray() - { - return type == JSON_ARRAY; - } - - void addChild(JsonNode* childToAdd); - - void removeChild(JsonNode* childToRemove); - - void duplicate(JsonNode* other); - -private: - JsonNodeType type; - JsonNode* next; - JsonNodeContent content; - - inline void writeArrayTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer - inline void writeObjectTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer - - void setAsProxyOfSelf(); - - void setAsProxyOf(JsonNode* target) - { - type = JSON_PROXY; - content.asProxy.target = target; - } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/include/ArduinoJson/Internals/JsonNodeIterator.h b/include/ArduinoJson/Internals/JsonNodeIterator.h index f0676687..26e6a8df 100644 --- a/include/ArduinoJson/Internals/JsonNodeIterator.h +++ b/include/ArduinoJson/Internals/JsonNodeIterator.h @@ -2,36 +2,41 @@ #include "JsonNode.h" -class JsonNodeIterator +namespace ArduinoJson { -public: - - explicit JsonNodeIterator(JsonNode* node) - : node(node) + namespace Internals { + class JsonNodeIterator + { + public: + + explicit JsonNodeIterator(JsonNode* node) + : node(node) + { + } + + bool operator!= (const JsonNodeIterator& other) const + { + return node != other.node; + } + + void operator++() + { + node = node->next; + } + + JsonNode* operator*() const + { + return node; + } + + JsonNode* operator->() const + { + return node; + } + + private: + JsonNode* node; + }; } - - bool operator!= (const JsonNodeIterator& other) const - { - return node != other.node; - } - - void operator++() - { - node = node->next; - } - - JsonNode* operator*() const - { - return node; - } - - JsonNode* operator->() const - { - return node; - } - -private: - JsonNode* node; -}; - +} diff --git a/include/ArduinoJson/Internals/JsonNodeWrapper.h b/include/ArduinoJson/Internals/JsonNodeWrapper.h index 45fe0aff..477ba23a 100644 --- a/include/ArduinoJson/Internals/JsonNodeWrapper.h +++ b/include/ArduinoJson/Internals/JsonNodeWrapper.h @@ -1,37 +1,43 @@ #pragma once #include "JsonNode.h" -class JsonValue; -class JsonNodeWrapper +namespace ArduinoJson { - friend class JsonValue; - -public: - JsonNodeWrapper() - : _node(0) + class JsonValue ; + + namespace Internals { - } - - explicit JsonNodeWrapper(JsonNode* node) - : _node(node) - { - } - -protected: - - void duplicate(const JsonNodeWrapper& other) - { - if (!_node) + class JsonNodeWrapper { - _node = other._node; - } - else - { - _node->duplicate(other._node); - } + friend class JsonValue; + + public: + JsonNodeWrapper() + : _node(0) + { + } + + explicit JsonNodeWrapper(JsonNode* node) + : _node(node) + { + } + + protected: + + void duplicate(const JsonNodeWrapper& other) + { + if (!_node) + { + _node = other._node; + } + else + { + _node->duplicate(other._node); + } + } + + JsonNode* _node; + }; } - - JsonNode* _node; -}; - +} diff --git a/include/ArduinoJson/Internals/JsonParser.h b/include/ArduinoJson/Internals/JsonParser.h index 9302e7c1..5f2e9f80 100644 --- a/include/ArduinoJson/Internals/JsonParser.h +++ b/include/ArduinoJson/Internals/JsonParser.h @@ -1,43 +1,50 @@ -#include "JsonNode.h" - #pragma once -class JsonNode; -class JsonBuffer; +#include "JsonNode.h" -class JsonParser +namespace ArduinoJson { -public: - JsonParser(JsonBuffer* buffer, char* json) - : _buffer(buffer), _ptr(json) + class JsonBuffer; + + namespace Internals { + class JsonNode; + class JsonParser + { + public: + JsonParser(JsonBuffer* buffer, char* json) + : _buffer(buffer), _ptr(json) + { + + } + + JsonNode* parseAnything(); + + private: + JsonBuffer* _buffer; + char* _ptr; + + inline bool isArrayStart(); + inline bool isArrayStop(); + inline bool isBoolean(); + inline bool isComma(); + inline bool isDouble(); + inline bool isEnd(); + inline bool isLong(); + inline bool isNull(); + inline bool isSpace(); + + inline void skipOneChar(); + inline void skipSpaces(); + + inline JsonNode* parseArray(); + inline JsonNode* parseBoolean(); + inline JsonNode* parseLong(); + inline JsonNode* parseNull(); + inline JsonNode* parseString(); + + JsonNode *parseDouble(); + }; } - - JsonNode* parseAnything(); - -private: - JsonBuffer* _buffer; - char* _ptr; - - inline bool isArrayStart(); - inline bool isArrayStop(); - inline bool isBoolean(); - inline bool isComma(); - inline bool isDouble(); - inline bool isEnd(); - inline bool isLong(); - inline bool isNull(); - inline bool isSpace(); - - inline void skipOneChar(); - inline void skipSpaces(); - - inline JsonNode* parseArray(); - inline JsonNode* parseBoolean(); - inline JsonNode* parseLong(); - inline JsonNode* parseNull(); - inline JsonNode* parseString(); - - JsonNode *parseDouble(); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/include/ArduinoJson/Internals/JsonWriter.h b/include/ArduinoJson/Internals/JsonWriter.h index bea6540f..4aa261fc 100644 --- a/include/ArduinoJson/Internals/JsonWriter.h +++ b/include/ArduinoJson/Internals/JsonWriter.h @@ -2,48 +2,53 @@ #include "../Arduino/Print.h" -class JsonWriter +namespace ArduinoJson { -public: - explicit JsonWriter(Print* sink) - : _sink(sink), _length(0) + namespace Internals { + class JsonWriter + { + public: + explicit JsonWriter(Print* sink) + : _sink(sink), _length(0) + { + } + + size_t bytesWritten() + { + return _length; + } + + virtual void beginArray() = 0; + + virtual void endArray() = 0; + + virtual void beginObject() = 0; + + virtual void endObject() = 0; + + void writeString(const char* value); + void writeInteger(long value); + void writeBoolean(bool value); + void writeDouble(double value, int decimals); + + virtual void writeColon() = 0; + + virtual void writeComma() = 0; + + void writeEmptyArray() + { + _length += _sink->print("[]"); + } + + void writeEmptyObject() + { + _length += _sink->print("{}"); + } + + protected: + Print* _sink; + size_t _length; + }; } - - size_t bytesWritten() - { - return _length; - } - - virtual void beginArray() = 0; - - virtual void endArray() = 0; - - virtual void beginObject() = 0; - - virtual void endObject() = 0; - - void writeString(const char* value); - void writeInteger(long value); - void writeBoolean(bool value); - void writeDouble(double value, int decimals); - - virtual void writeColon() = 0; - - virtual void writeComma() = 0; - - void writeEmptyArray() - { - _length += _sink->print("[]"); - } - - void writeEmptyObject() - { - _length += _sink->print("{}"); - } - -protected: - Print* _sink; - size_t _length; -}; - +} diff --git a/include/ArduinoJson/Internals/PrettyJsonWriter.h b/include/ArduinoJson/Internals/PrettyJsonWriter.h index bdc97553..63d16c96 100644 --- a/include/ArduinoJson/Internals/PrettyJsonWriter.h +++ b/include/ArduinoJson/Internals/PrettyJsonWriter.h @@ -3,63 +3,67 @@ #include "JsonWriter.h" #include "IndentedPrint.h" -using namespace ArduinoJson::Generator; - -class PrettyJsonWriter : public JsonWriter +namespace ArduinoJson { -public: - explicit PrettyJsonWriter(IndentedPrint* sink) - : JsonWriter(sink), _indenter(sink) + namespace Internals { - } + class PrettyJsonWriter : public JsonWriter + { + public: + explicit PrettyJsonWriter(IndentedPrint* sink) + : JsonWriter(sink), _indenter(sink) + { + } - virtual void beginArray() - { - _length += _sink->write('['); - indent(); - } + virtual void beginArray() + { + _length += _sink->write('['); + indent(); + } - virtual void endArray() - { - unindent(); - _length += _sink->write(']'); - } + virtual void endArray() + { + unindent(); + _length += _sink->write(']'); + } - virtual void writeColon() - { - _length += _sink->print(": "); - } + virtual void writeColon() + { + _length += _sink->print(": "); + } - virtual void writeComma() - { - _length += _sink->write(','); - _length += _indenter->println(); - } + virtual void writeComma() + { + _length += _sink->write(','); + _length += _indenter->println(); + } - virtual void beginObject() - { - _length += _sink->write('{'); - indent(); - } + virtual void beginObject() + { + _length += _sink->write('{'); + indent(); + } - virtual void endObject() - { - unindent(); - _length += _sink->write('}'); - } + virtual void endObject() + { + unindent(); + _length += _sink->write('}'); + } -private: - IndentedPrint* _indenter; + private: + IndentedPrint* _indenter; - void indent() - { - _indenter->indent(); - _length += _indenter->println(); - } + void indent() + { + _indenter->indent(); + _length += _indenter->println(); + } - void unindent() - { - _length += _indenter->println(); - _indenter->unindent(); + void unindent() + { + _length += _indenter->println(); + _indenter->unindent(); + } + }; } -}; +} \ No newline at end of file diff --git a/include/ArduinoJson/JsonArray.h b/include/ArduinoJson/JsonArray.h index ffe770f0..cb0753ac 100644 --- a/include/ArduinoJson/JsonArray.h +++ b/include/ArduinoJson/JsonArray.h @@ -2,33 +2,35 @@ #include "JsonContainer.h" -class JsonArray : public JsonContainer +namespace ArduinoJson { -public: - JsonArray() + class JsonArray : public JsonContainer { - } + public: + JsonArray() + { + } - explicit JsonArray(JsonNode* node) - : JsonContainer(node) - { - } + explicit JsonArray(Internals::JsonNode* node) + : JsonContainer(node) + { + } - JsonValue operator[](int index) const; + JsonValue operator[](int index) const; - void add(bool value); - void add(const char* value); - void add(double value, int decimals=2); - void add(int value) { add((long) value); } - void add(long value); - void add(JsonContainer nestedArray); // TODO: should allow JsonValue too + void add(bool value); + void add(const char* value); + void add(double value, int decimals=2); + void add(int value) { add((long) value); } + void add(long value); + void add(JsonContainer nestedArray); // TODO: should allow JsonValue too - JsonArray createNestedArray(); - JsonObject createNestedObject(); - - bool success() - { - return _node && _node->isArray(); - } -}; + JsonArray createNestedArray(); + JsonObject createNestedObject(); + bool success() + { + return _node && _node->isArray(); + } + }; +} diff --git a/include/ArduinoJson/JsonBuffer.h b/include/ArduinoJson/JsonBuffer.h index 74ab72e5..868a9c2e 100644 --- a/include/ArduinoJson/JsonBuffer.h +++ b/include/ArduinoJson/JsonBuffer.h @@ -3,43 +3,49 @@ #include "JsonArray.h" #include "JsonObject.h" -class JsonParser; - -class JsonBuffer +namespace ArduinoJson { - friend class JsonContainer; - friend class JsonNode; - friend class JsonParser; - -public: - virtual ~JsonBuffer() {}; - - JsonArray createArray() + namespace Internals { - return JsonArray(createArrayNode()); + class JsonParser; } - JsonObject createObject() + class JsonBuffer { - return JsonObject(createObjectNode()); - } + friend class JsonContainer; + friend class Internals::JsonNode; + friend class Internals::JsonParser; - JsonValue createValue(); + public: + virtual ~JsonBuffer() {}; - JsonArray parseArray(char* json); + JsonArray createArray() + { + return JsonArray(createArrayNode()); + } - JsonValue parseValue(char* json); + JsonObject createObject() + { + return JsonObject(createObjectNode()); + } -protected: - virtual void* allocateNode() = 0; + JsonValue createValue(); -private: - JsonNode* createNode(); + JsonArray parseArray(char* json); - JsonNode* createArrayNode(); - JsonNode* createBoolNode(bool value); - JsonNode* createDoubleNode(double value, int decimals); - JsonNode* createLongNode(long value); - JsonNode* createObjectNode(); - JsonNode* createStringNode(const char* value); -}; + JsonValue parseValue(char* json); + + protected: + virtual void* allocateNode() = 0; + + private: + Internals::JsonNode* createNode(); + + Internals::JsonNode* createArrayNode(); + Internals::JsonNode* createBoolNode(bool value); + Internals::JsonNode* createDoubleNode(double value, int decimals); + Internals::JsonNode* createLongNode(long value); + Internals::JsonNode* createObjectNode(); + Internals::JsonNode* createStringNode(const char* value); + }; +} \ No newline at end of file diff --git a/include/ArduinoJson/JsonContainer.h b/include/ArduinoJson/JsonContainer.h index 31137c58..0f376d1d 100644 --- a/include/ArduinoJson/JsonContainer.h +++ b/include/ArduinoJson/JsonContainer.h @@ -1,55 +1,54 @@ #pragma once -#include "ArduinoJson/Arduino/Printable.h" -#include "ArduinoJson/Internals/JsonNodeIterator.h" -#include "ArduinoJson/Internals/JsonNode.h" -#include "ArduinoJson/Internals/IndentedPrint.h" -#include "ArduinoJson/Internals/JsonNodeWrapper.h" +#include "Arduino/Printable.h" +#include "Internals/JsonNodeIterator.h" +#include "Internals/JsonNode.h" +#include "Internals/IndentedPrint.h" +#include "Internals/JsonNodeWrapper.h" -class JsonArray; -class JsonObject; -class JsonValue; - -class JsonContainer : public Printable, public JsonNodeWrapper +namespace ArduinoJson { - // friend JsonValue; - friend class JsonArray; + class JsonArray; + class JsonObject; + class JsonValue; -public: + class JsonContainer : public Printable, public Internals::JsonNodeWrapper + { + friend class JsonArray; + public: + JsonContainer() {} - JsonContainer() {} - - explicit JsonContainer(JsonNode* node) + explicit JsonContainer(Internals::JsonNode* node) : JsonNodeWrapper(node) - { - } + { + } - size_t size() const; - - bool operator==(JsonContainer const& other) const; + size_t size() const; - size_t printTo(char* buffer, size_t bufferSize) const; - virtual size_t printTo(Print& print) const; + bool operator==(JsonContainer const& other) const; - size_t prettyPrintTo(char* buffer, size_t bufferSize) const; - size_t prettyPrintTo(ArduinoJson::Generator::IndentedPrint& print) const; - size_t prettyPrintTo(Print& print) const; + size_t printTo(char* buffer, size_t bufferSize) const; + virtual size_t printTo(Print& print) const; -protected: + size_t prettyPrintTo(char* buffer, size_t bufferSize) const; + size_t prettyPrintTo(ArduinoJson::Internals::IndentedPrint& print) const; + size_t prettyPrintTo(Print& print) const; - JsonNodeIterator beginChildren() const - { - return JsonNodeIterator(_node ? _node->getContainerChild() : 0); - } + protected: - JsonNodeIterator endChildren() const - { - return JsonNodeIterator(0); - } + Internals::JsonNodeIterator beginChildren() const + { + return Internals::JsonNodeIterator(_node ? _node->getContainerChild() : 0); + } - void addChild(JsonNode*); - void removeChild(JsonNode*); - JsonNode* createNode(); -}; + Internals::JsonNodeIterator endChildren() const + { + return Internals::JsonNodeIterator(0); + } + void addChild(Internals::JsonNode*); + void removeChild(Internals::JsonNode*); + Internals::JsonNode* createNode(); + }; +} \ No newline at end of file diff --git a/include/ArduinoJson/JsonObject.h b/include/ArduinoJson/JsonObject.h index 23f94001..a4a6c309 100644 --- a/include/ArduinoJson/JsonObject.h +++ b/include/ArduinoJson/JsonObject.h @@ -2,25 +2,28 @@ #include "JsonContainer.h" -class JsonObject : public JsonContainer +namespace ArduinoJson { -public: - - JsonObject() + class JsonObject : public JsonContainer { - } + public: - explicit JsonObject(JsonNode* node) - : JsonContainer(node) - { - } + JsonObject() + { + } - JsonValue operator[](const char* key); - void remove(const char* key); + explicit JsonObject(Internals::JsonNode* node) + : JsonContainer(node) + { + } - JsonArray createNestedArray(const char* key); - JsonObject createNestedObject(const char* key); + JsonValue operator[](const char* key); + void remove(const char* key); -private: - JsonNode* getOrCreateNodeAt(const char* key); -}; \ No newline at end of file + JsonArray createNestedArray(const char* key); + JsonObject createNestedObject(const char* key); + + private: + Internals::JsonNode* getOrCreateNodeAt(const char* key); + }; +} \ No newline at end of file diff --git a/include/ArduinoJson/JsonValue.h b/include/ArduinoJson/JsonValue.h index 2eb7c078..854579d4 100644 --- a/include/ArduinoJson/JsonValue.h +++ b/include/ArduinoJson/JsonValue.h @@ -2,35 +2,38 @@ #include "Internals/JsonNodeWrapper.h" -class JsonArray; -class JsonContainer; -class JsonObject; - -class JsonValue : public JsonNodeWrapper +namespace ArduinoJson { -public: + class JsonArray; + class JsonContainer; + class JsonObject; - JsonValue() {} - - explicit JsonValue(JsonNode* node) - : JsonNodeWrapper(node) + class JsonValue : public Internals::JsonNodeWrapper { - } + public: - void operator=(bool); - void operator=(const char*); - void operator=(double x) { set(x, 2); } - void operator=(int); - void operator=(const JsonValue& value) { duplicate(value); } - void operator=(const JsonNodeWrapper& object) { duplicate(object); } + JsonValue() {} + + explicit JsonValue(Internals::JsonNode* node) + : JsonNodeWrapper(node) + { + } + + void operator=(bool); + void operator=(const char*); + void operator=(double x) { set(x, 2); } + void operator=(int); + void operator=(const JsonValue& value) { duplicate(value); } + void operator=(const Internals::JsonNodeWrapper& object) { duplicate(object); } - operator bool() const; - operator const char*() const; - operator double() const; - operator long() const; - operator int() const { return operator long(); } - operator JsonArray() const; - operator JsonObject() const; + operator bool() const; + operator const char*() const; + operator double() const; + operator long() const; + operator int() const { return operator long(); } + operator JsonArray() const; + operator JsonObject() const; - void set(double value, int decimals); -}; \ No newline at end of file + void set(double value, int decimals); + }; +} \ No newline at end of file diff --git a/include/ArduinoJson/StaticJsonBuffer.h b/include/ArduinoJson/StaticJsonBuffer.h index 8b85491f..4d164f23 100644 --- a/include/ArduinoJson/StaticJsonBuffer.h +++ b/include/ArduinoJson/StaticJsonBuffer.h @@ -3,40 +3,42 @@ #include "JsonBuffer.h" #include "JsonObject.h" -template -class StaticJsonBuffer : public JsonBuffer +namespace ArduinoJson { - friend class JsonObject; + template + class StaticJsonBuffer : public JsonBuffer + { + friend class JsonObject; -public: - - explicit StaticJsonBuffer() + public: + + explicit StaticJsonBuffer() : _size(0) - { - } + { + } - virtual ~StaticJsonBuffer() {} + virtual ~StaticJsonBuffer() {} - int capacity() - { - return CAPACITY; - } + int capacity() + { + return CAPACITY; + } - int size() - { - return _size; - } + int size() + { + return _size; + } -protected: - virtual void* allocateNode() - { - if (_size >= CAPACITY) return 0; + protected: + virtual void* allocateNode() + { + if (_size >= CAPACITY) return 0; - return &_buffer[_size++]; - } - -private: - JsonNode _buffer[CAPACITY]; - int _size; -}; + return &_buffer[_size++]; + } + private: + Internals::JsonNode _buffer[CAPACITY]; + int _size; + }; +} diff --git a/src/Internals/IndentedPrint.cpp b/src/Internals/IndentedPrint.cpp index 74c4dc21..3e01b872 100644 --- a/src/Internals/IndentedPrint.cpp +++ b/src/Internals/IndentedPrint.cpp @@ -1,6 +1,6 @@ #include "ArduinoJson/Internals/IndentedPrint.h" -using namespace ArduinoJson::Generator; +using namespace ArduinoJson::Internals; void IndentedPrint::indent() { diff --git a/src/Internals/JsonNode.cpp b/src/Internals/JsonNode.cpp index 91ef2408..f0ac8ab7 100644 --- a/src/Internals/JsonNode.cpp +++ b/src/Internals/JsonNode.cpp @@ -5,6 +5,8 @@ #include "ArduinoJson/JsonObject.h" #include "ArduinoJson/JsonBuffer.h" +using namespace ArduinoJson::Internals; + void JsonNode::writeTo(JsonWriter& writer) { switch (type) diff --git a/src/JsonArray.cpp b/src/JsonArray.cpp index a388c2d2..2c622fb0 100644 --- a/src/JsonArray.cpp +++ b/src/JsonArray.cpp @@ -2,6 +2,9 @@ #include "ArduinoJson/JsonObject.h" #include "ArduinoJson/JsonValue.h" +using namespace ArduinoJson; +using namespace ArduinoJson::Internals; + JsonValue JsonArray::operator[](int index) const { for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) diff --git a/src/JsonBuffer.cpp b/src/JsonBuffer.cpp index ec2ea3ee..0df60e7f 100644 --- a/src/JsonBuffer.cpp +++ b/src/JsonBuffer.cpp @@ -6,6 +6,9 @@ #include "ArduinoJson/Internals/JsonParser.h" #include "ArduinoJson/Internals/JsonNode.h" +using namespace ArduinoJson; +using namespace ArduinoJson::Internals; + JsonValue JsonBuffer::createValue() { return JsonValue(createNode()); diff --git a/src/JsonContainer.cpp b/src/JsonContainer.cpp index 8ff51244..c7c6f79a 100644 --- a/src/JsonContainer.cpp +++ b/src/JsonContainer.cpp @@ -5,6 +5,7 @@ #include "ArduinoJson/Internals/CompactJsonWriter.h" #include "ArduinoJson/Internals/PrettyJsonWriter.h" +using namespace ArduinoJson; using namespace ArduinoJson::Internals; size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index 874e9045..f6ff2043 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -7,6 +7,7 @@ #include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/StringBuilder.h" +using namespace ArduinoJson; using namespace ArduinoJson::Internals; JsonValue JsonObject::operator[](char const* key) diff --git a/src/JsonValue.cpp b/src/JsonValue.cpp index e197e07e..a4834650 100644 --- a/src/JsonValue.cpp +++ b/src/JsonValue.cpp @@ -4,6 +4,8 @@ #include "ArduinoJson/JsonObject.h" #include "ArduinoJson/Internals/JsonNode.h" +using namespace ArduinoJson; + void JsonValue::operator=(bool value) { if (_node) diff --git a/test/Issue10.cpp b/test/Issue10.cpp index f3976f9e..1fe4f4e0 100644 --- a/test/Issue10.cpp +++ b/test/Issue10.cpp @@ -4,7 +4,7 @@ #include #include -using namespace ArduinoJson::Generator; +using namespace ArduinoJson; struct Person { diff --git a/test/JsonArray_Container_Tests.cpp b/test/JsonArray_Container_Tests.cpp index fef0536c..dfd54d4c 100644 --- a/test/JsonArray_Container_Tests.cpp +++ b/test/JsonArray_Container_Tests.cpp @@ -2,6 +2,8 @@ #include #include +using namespace ArduinoJson; + class JsonArray_Container_Tests : public ::testing::Test { protected: diff --git a/test/JsonArray_PrettyPrintTo_Tests.cpp b/test/JsonArray_PrettyPrintTo_Tests.cpp index eb6e0574..d1a7d150 100644 --- a/test/JsonArray_PrettyPrintTo_Tests.cpp +++ b/test/JsonArray_PrettyPrintTo_Tests.cpp @@ -9,6 +9,8 @@ #include #include +using namespace ArduinoJson; + class JsonArray_PrettyPrintTo_Tests : public testing::Test { protected: diff --git a/test/JsonArray_PrintTo_Tests.cpp b/test/JsonArray_PrintTo_Tests.cpp index afa18cbd..ad84a5b9 100644 --- a/test/JsonArray_PrintTo_Tests.cpp +++ b/test/JsonArray_PrintTo_Tests.cpp @@ -8,6 +8,8 @@ #include #include +using namespace ArduinoJson; + class JsonArray_PrintTo_Tests : public testing::Test { protected: diff --git a/test/JsonObject_Container_Tests.cpp b/test/JsonObject_Container_Tests.cpp index 7a37d447..fe799e55 100644 --- a/test/JsonObject_Container_Tests.cpp +++ b/test/JsonObject_Container_Tests.cpp @@ -2,6 +2,8 @@ #include #include +using namespace ArduinoJson; + class JsonObject_Container_Tests : public ::testing::Test { protected: diff --git a/test/JsonObject_PrettyPrintTo_Tests.cpp b/test/JsonObject_PrettyPrintTo_Tests.cpp index 772e614b..03ed970e 100644 --- a/test/JsonObject_PrettyPrintTo_Tests.cpp +++ b/test/JsonObject_PrettyPrintTo_Tests.cpp @@ -8,6 +8,8 @@ #include #include +using namespace ArduinoJson; + class JsonObject_PrettyPrintTo_Tests : public testing::Test { protected: diff --git a/test/JsonObject_Serialization_Tests.cpp b/test/JsonObject_Serialization_Tests.cpp index 33cdbe05..dd312206 100644 --- a/test/JsonObject_Serialization_Tests.cpp +++ b/test/JsonObject_Serialization_Tests.cpp @@ -4,6 +4,8 @@ #include #include +using namespace ArduinoJson; + class JsonObject_Serialization_Tests : public testing::Test { protected: diff --git a/test/JsonParser_Array_Tests.cpp b/test/JsonParser_Array_Tests.cpp index 4cc44fe7..d43d0a8e 100644 --- a/test/JsonParser_Array_Tests.cpp +++ b/test/JsonParser_Array_Tests.cpp @@ -2,6 +2,8 @@ #include #include +using namespace ArduinoJson; + class JsonParser_Array_Tests : public testing::Test { protected: diff --git a/test/JsonValueTests.cpp b/test/JsonValueTests.cpp index a398ce60..9a54044c 100644 --- a/test/JsonValueTests.cpp +++ b/test/JsonValueTests.cpp @@ -2,6 +2,8 @@ #include #include +using namespace ArduinoJson; + class JsonValueTests : public ::testing::Test { protected: diff --git a/test/StaticJsonBufferTests.cpp b/test/StaticJsonBufferTests.cpp index 37609886..e4c7fc8d 100644 --- a/test/StaticJsonBufferTests.cpp +++ b/test/StaticJsonBufferTests.cpp @@ -2,6 +2,8 @@ #include #include +using namespace ArduinoJson; + TEST(StaticJsonBuffer, CapacityMatchTemplateParameter) { StaticJsonBuffer<42> json;