Fixed namespaces

This commit is contained in:
Benoit Blanchon
2014-10-18 23:05:54 +02:00
parent 1abb8ac6ae
commit 074c39ca5b
31 changed files with 638 additions and 554 deletions

View File

@ -2,6 +2,10 @@
#include "ArduinoJson/Internals/JsonWriter.h" #include "ArduinoJson/Internals/JsonWriter.h"
namespace ArduinoJson
{
namespace Internals
{
class CompactJsonWriter : public JsonWriter class CompactJsonWriter : public JsonWriter
{ {
public: public:
@ -40,4 +44,5 @@ public:
_length += _sink->write('}'); _length += _sink->write('}');
} }
}; };
}
}

View File

@ -9,7 +9,7 @@
namespace ArduinoJson namespace ArduinoJson
{ {
namespace Generator namespace Internals
{ {
// Decorator on top of Print to allow indented output. // Decorator on top of Print to allow indented output.
// This class is used by JsonPrintable::prettyPrintTo() but can also be used // This class is used by JsonPrintable::prettyPrintTo() but can also be used

View File

@ -1,6 +1,11 @@
#pragma once #pragma once
namespace ArduinoJson
{
class JsonBuffer; class JsonBuffer;
namespace Internals
{
class JsonWriter; class JsonWriter;
class JsonNodeIterator; class JsonNodeIterator;
@ -179,3 +184,5 @@ private:
content.asProxy.target = target; content.asProxy.target = target;
} }
}; };
}
}

View File

@ -2,6 +2,10 @@
#include "JsonNode.h" #include "JsonNode.h"
namespace ArduinoJson
{
namespace Internals
{
class JsonNodeIterator class JsonNodeIterator
{ {
public: public:
@ -34,4 +38,5 @@ public:
private: private:
JsonNode* node; JsonNode* node;
}; };
}
}

View File

@ -1,8 +1,13 @@
#pragma once #pragma once
#include "JsonNode.h" #include "JsonNode.h"
namespace ArduinoJson
{
class JsonValue ; class JsonValue ;
namespace Internals
{
class JsonNodeWrapper class JsonNodeWrapper
{ {
friend class JsonValue; friend class JsonValue;
@ -34,4 +39,5 @@ protected:
JsonNode* _node; JsonNode* _node;
}; };
}
}

View File

@ -1,10 +1,15 @@
#include "JsonNode.h"
#pragma once #pragma once
class JsonNode; #include "JsonNode.h"
namespace ArduinoJson
{
class JsonBuffer; class JsonBuffer;
namespace Internals
{
class JsonNode;
class JsonParser class JsonParser
{ {
public: public:
@ -41,3 +46,5 @@ private:
JsonNode *parseDouble(); JsonNode *parseDouble();
}; };
}
}

View File

@ -2,6 +2,10 @@
#include "../Arduino/Print.h" #include "../Arduino/Print.h"
namespace ArduinoJson
{
namespace Internals
{
class JsonWriter class JsonWriter
{ {
public: public:
@ -46,4 +50,5 @@ protected:
Print* _sink; Print* _sink;
size_t _length; size_t _length;
}; };
}
}

View File

@ -3,8 +3,10 @@
#include "JsonWriter.h" #include "JsonWriter.h"
#include "IndentedPrint.h" #include "IndentedPrint.h"
using namespace ArduinoJson::Generator; namespace ArduinoJson
{
namespace Internals
{
class PrettyJsonWriter : public JsonWriter class PrettyJsonWriter : public JsonWriter
{ {
public: public:
@ -63,3 +65,5 @@ private:
_indenter->unindent(); _indenter->unindent();
} }
}; };
}
}

View File

@ -2,6 +2,8 @@
#include "JsonContainer.h" #include "JsonContainer.h"
namespace ArduinoJson
{
class JsonArray : public JsonContainer class JsonArray : public JsonContainer
{ {
public: public:
@ -9,7 +11,7 @@ public:
{ {
} }
explicit JsonArray(JsonNode* node) explicit JsonArray(Internals::JsonNode* node)
: JsonContainer(node) : JsonContainer(node)
{ {
} }
@ -31,4 +33,4 @@ public:
return _node && _node->isArray(); return _node && _node->isArray();
} }
}; };
}

View File

@ -3,13 +3,18 @@
#include "JsonArray.h" #include "JsonArray.h"
#include "JsonObject.h" #include "JsonObject.h"
namespace ArduinoJson
{
namespace Internals
{
class JsonParser; class JsonParser;
}
class JsonBuffer class JsonBuffer
{ {
friend class JsonContainer; friend class JsonContainer;
friend class JsonNode; friend class Internals::JsonNode;
friend class JsonParser; friend class Internals::JsonParser;
public: public:
virtual ~JsonBuffer() {}; virtual ~JsonBuffer() {};
@ -34,12 +39,13 @@ protected:
virtual void* allocateNode() = 0; virtual void* allocateNode() = 0;
private: private:
JsonNode* createNode(); Internals::JsonNode* createNode();
JsonNode* createArrayNode(); Internals::JsonNode* createArrayNode();
JsonNode* createBoolNode(bool value); Internals::JsonNode* createBoolNode(bool value);
JsonNode* createDoubleNode(double value, int decimals); Internals::JsonNode* createDoubleNode(double value, int decimals);
JsonNode* createLongNode(long value); Internals::JsonNode* createLongNode(long value);
JsonNode* createObjectNode(); Internals::JsonNode* createObjectNode();
JsonNode* createStringNode(const char* value); Internals::JsonNode* createStringNode(const char* value);
}; };
}

View File

@ -1,26 +1,25 @@
#pragma once #pragma once
#include "ArduinoJson/Arduino/Printable.h" #include "Arduino/Printable.h"
#include "ArduinoJson/Internals/JsonNodeIterator.h" #include "Internals/JsonNodeIterator.h"
#include "ArduinoJson/Internals/JsonNode.h" #include "Internals/JsonNode.h"
#include "ArduinoJson/Internals/IndentedPrint.h" #include "Internals/IndentedPrint.h"
#include "ArduinoJson/Internals/JsonNodeWrapper.h" #include "Internals/JsonNodeWrapper.h"
namespace ArduinoJson
{
class JsonArray; class JsonArray;
class JsonObject; class JsonObject;
class JsonValue; class JsonValue;
class JsonContainer : public Printable, public JsonNodeWrapper class JsonContainer : public Printable, public Internals::JsonNodeWrapper
{ {
// friend JsonValue;
friend class JsonArray; friend class JsonArray;
public: public:
JsonContainer() {} JsonContainer() {}
explicit JsonContainer(JsonNode* node) explicit JsonContainer(Internals::JsonNode* node)
: JsonNodeWrapper(node) : JsonNodeWrapper(node)
{ {
} }
@ -33,23 +32,23 @@ public:
virtual size_t printTo(Print& print) const; virtual size_t printTo(Print& print) const;
size_t prettyPrintTo(char* buffer, size_t bufferSize) const; size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
size_t prettyPrintTo(ArduinoJson::Generator::IndentedPrint& print) const; size_t prettyPrintTo(ArduinoJson::Internals::IndentedPrint& print) const;
size_t prettyPrintTo(Print& print) const; size_t prettyPrintTo(Print& print) const;
protected: protected:
JsonNodeIterator beginChildren() const Internals::JsonNodeIterator beginChildren() const
{ {
return JsonNodeIterator(_node ? _node->getContainerChild() : 0); return Internals::JsonNodeIterator(_node ? _node->getContainerChild() : 0);
} }
JsonNodeIterator endChildren() const Internals::JsonNodeIterator endChildren() const
{ {
return JsonNodeIterator(0); return Internals::JsonNodeIterator(0);
} }
void addChild(JsonNode*); void addChild(Internals::JsonNode*);
void removeChild(JsonNode*); void removeChild(Internals::JsonNode*);
JsonNode* createNode(); Internals::JsonNode* createNode();
}; };
}

View File

@ -2,6 +2,8 @@
#include "JsonContainer.h" #include "JsonContainer.h"
namespace ArduinoJson
{
class JsonObject : public JsonContainer class JsonObject : public JsonContainer
{ {
public: public:
@ -10,7 +12,7 @@ public:
{ {
} }
explicit JsonObject(JsonNode* node) explicit JsonObject(Internals::JsonNode* node)
: JsonContainer(node) : JsonContainer(node)
{ {
} }
@ -22,5 +24,6 @@ public:
JsonObject createNestedObject(const char* key); JsonObject createNestedObject(const char* key);
private: private:
JsonNode* getOrCreateNodeAt(const char* key); Internals::JsonNode* getOrCreateNodeAt(const char* key);
}; };
}

View File

@ -2,17 +2,19 @@
#include "Internals/JsonNodeWrapper.h" #include "Internals/JsonNodeWrapper.h"
namespace ArduinoJson
{
class JsonArray; class JsonArray;
class JsonContainer; class JsonContainer;
class JsonObject; class JsonObject;
class JsonValue : public JsonNodeWrapper class JsonValue : public Internals::JsonNodeWrapper
{ {
public: public:
JsonValue() {} JsonValue() {}
explicit JsonValue(JsonNode* node) explicit JsonValue(Internals::JsonNode* node)
: JsonNodeWrapper(node) : JsonNodeWrapper(node)
{ {
} }
@ -22,7 +24,7 @@ public:
void operator=(double x) { set(x, 2); } void operator=(double x) { set(x, 2); }
void operator=(int); void operator=(int);
void operator=(const JsonValue& value) { duplicate(value); } void operator=(const JsonValue& value) { duplicate(value); }
void operator=(const JsonNodeWrapper& object) { duplicate(object); } void operator=(const Internals::JsonNodeWrapper& object) { duplicate(object); }
operator bool() const; operator bool() const;
operator const char*() const; operator const char*() const;
@ -34,3 +36,4 @@ public:
void set(double value, int decimals); void set(double value, int decimals);
}; };
}

View File

@ -3,6 +3,8 @@
#include "JsonBuffer.h" #include "JsonBuffer.h"
#include "JsonObject.h" #include "JsonObject.h"
namespace ArduinoJson
{
template<int CAPACITY> template<int CAPACITY>
class StaticJsonBuffer : public JsonBuffer class StaticJsonBuffer : public JsonBuffer
{ {
@ -36,7 +38,7 @@ protected:
} }
private: private:
JsonNode _buffer[CAPACITY]; Internals::JsonNode _buffer[CAPACITY];
int _size; int _size;
}; };
}

View File

@ -1,6 +1,6 @@
#include "ArduinoJson/Internals/IndentedPrint.h" #include "ArduinoJson/Internals/IndentedPrint.h"
using namespace ArduinoJson::Generator; using namespace ArduinoJson::Internals;
void IndentedPrint::indent() void IndentedPrint::indent()
{ {

View File

@ -5,6 +5,8 @@
#include "ArduinoJson/JsonObject.h" #include "ArduinoJson/JsonObject.h"
#include "ArduinoJson/JsonBuffer.h" #include "ArduinoJson/JsonBuffer.h"
using namespace ArduinoJson::Internals;
void JsonNode::writeTo(JsonWriter& writer) void JsonNode::writeTo(JsonWriter& writer)
{ {
switch (type) switch (type)

View File

@ -2,6 +2,9 @@
#include "ArduinoJson/JsonObject.h" #include "ArduinoJson/JsonObject.h"
#include "ArduinoJson/JsonValue.h" #include "ArduinoJson/JsonValue.h"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
JsonValue JsonArray::operator[](int index) const JsonValue JsonArray::operator[](int index) const
{ {
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it) for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)

View File

@ -6,6 +6,9 @@
#include "ArduinoJson/Internals/JsonParser.h" #include "ArduinoJson/Internals/JsonParser.h"
#include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/JsonNode.h"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals;
JsonValue JsonBuffer::createValue() JsonValue JsonBuffer::createValue()
{ {
return JsonValue(createNode()); return JsonValue(createNode());

View File

@ -5,6 +5,7 @@
#include "ArduinoJson/Internals/CompactJsonWriter.h" #include "ArduinoJson/Internals/CompactJsonWriter.h"
#include "ArduinoJson/Internals/PrettyJsonWriter.h" #include "ArduinoJson/Internals/PrettyJsonWriter.h"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const

View File

@ -7,6 +7,7 @@
#include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/JsonNode.h"
#include "ArduinoJson/Internals/StringBuilder.h" #include "ArduinoJson/Internals/StringBuilder.h"
using namespace ArduinoJson;
using namespace ArduinoJson::Internals; using namespace ArduinoJson::Internals;
JsonValue JsonObject::operator[](char const* key) JsonValue JsonObject::operator[](char const* key)

View File

@ -4,6 +4,8 @@
#include "ArduinoJson/JsonObject.h" #include "ArduinoJson/JsonObject.h"
#include "ArduinoJson/Internals/JsonNode.h" #include "ArduinoJson/Internals/JsonNode.h"
using namespace ArduinoJson;
void JsonValue::operator=(bool value) void JsonValue::operator=(bool value)
{ {
if (_node) if (_node)

View File

@ -4,7 +4,7 @@
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
using namespace ArduinoJson::Generator; using namespace ArduinoJson;
struct Person struct Person
{ {

View File

@ -2,6 +2,8 @@
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
using namespace ArduinoJson;
class JsonArray_Container_Tests : public ::testing::Test class JsonArray_Container_Tests : public ::testing::Test
{ {
protected: protected:

View File

@ -9,6 +9,8 @@
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
using namespace ArduinoJson;
class JsonArray_PrettyPrintTo_Tests : public testing::Test class JsonArray_PrettyPrintTo_Tests : public testing::Test
{ {
protected: protected:

View File

@ -8,6 +8,8 @@
#include <ArduinoJson/JsonObject.h> #include <ArduinoJson/JsonObject.h>
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
using namespace ArduinoJson;
class JsonArray_PrintTo_Tests : public testing::Test class JsonArray_PrintTo_Tests : public testing::Test
{ {
protected: protected:

View File

@ -2,6 +2,8 @@
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
using namespace ArduinoJson;
class JsonObject_Container_Tests : public ::testing::Test class JsonObject_Container_Tests : public ::testing::Test
{ {
protected: protected:

View File

@ -8,6 +8,8 @@
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
using namespace ArduinoJson;
class JsonObject_PrettyPrintTo_Tests : public testing::Test class JsonObject_PrettyPrintTo_Tests : public testing::Test
{ {
protected: protected:

View File

@ -4,6 +4,8 @@
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
using namespace ArduinoJson;
class JsonObject_Serialization_Tests : public testing::Test class JsonObject_Serialization_Tests : public testing::Test
{ {
protected: protected:

View File

@ -2,6 +2,8 @@
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
using namespace ArduinoJson;
class JsonParser_Array_Tests : public testing::Test class JsonParser_Array_Tests : public testing::Test
{ {
protected: protected:

View File

@ -2,6 +2,8 @@
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
using namespace ArduinoJson;
class JsonValueTests : public ::testing::Test class JsonValueTests : public ::testing::Test
{ {
protected: protected:

View File

@ -2,6 +2,8 @@
#include <ArduinoJson/StaticJsonBuffer.h> #include <ArduinoJson/StaticJsonBuffer.h>
#include <ArduinoJson/JsonValue.h> #include <ArduinoJson/JsonValue.h>
using namespace ArduinoJson;
TEST(StaticJsonBuffer, CapacityMatchTemplateParameter) TEST(StaticJsonBuffer, CapacityMatchTemplateParameter)
{ {
StaticJsonBuffer<42> json; StaticJsonBuffer<42> json;