mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 11:06:35 +02:00
Fixed namespaces
This commit is contained in:
@ -2,9 +2,13 @@
|
||||
|
||||
#include "ArduinoJson/Internals/JsonWriter.h"
|
||||
|
||||
class CompactJsonWriter : public JsonWriter
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
namespace Internals
|
||||
{
|
||||
class CompactJsonWriter : public JsonWriter
|
||||
{
|
||||
public:
|
||||
explicit CompactJsonWriter(Print* sink)
|
||||
: JsonWriter(sink)
|
||||
{
|
||||
@ -39,5 +43,6 @@ public:
|
||||
{
|
||||
_length += _sink->write('}');
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -1,11 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
class JsonBuffer;
|
||||
class JsonWriter;
|
||||
class JsonNodeIterator;
|
||||
|
||||
class JsonNode
|
||||
namespace ArduinoJson
|
||||
{
|
||||
class JsonBuffer;
|
||||
|
||||
namespace Internals
|
||||
{
|
||||
class JsonWriter;
|
||||
class JsonNodeIterator;
|
||||
|
||||
class JsonNode
|
||||
{
|
||||
friend class JsonNodeIterator;
|
||||
|
||||
enum JsonNodeType
|
||||
@ -51,7 +56,7 @@ class JsonNode
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
JsonNode()
|
||||
: type(JSON_UNDEFINED), next(0)
|
||||
{
|
||||
@ -163,7 +168,7 @@ public:
|
||||
|
||||
void duplicate(JsonNode* other);
|
||||
|
||||
private:
|
||||
private:
|
||||
JsonNodeType type;
|
||||
JsonNode* next;
|
||||
JsonNodeContent content;
|
||||
@ -178,4 +183,6 @@ private:
|
||||
type = JSON_PROXY;
|
||||
content.asProxy.target = target;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
@ -2,9 +2,13 @@
|
||||
|
||||
#include "JsonNode.h"
|
||||
|
||||
class JsonNodeIterator
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
namespace Internals
|
||||
{
|
||||
class JsonNodeIterator
|
||||
{
|
||||
public:
|
||||
|
||||
explicit JsonNodeIterator(JsonNode* node)
|
||||
: node(node)
|
||||
@ -31,7 +35,8 @@ public:
|
||||
return node;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
JsonNode* node;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "JsonNode.h"
|
||||
class JsonValue;
|
||||
|
||||
class JsonNodeWrapper
|
||||
namespace ArduinoJson
|
||||
{
|
||||
class JsonValue ;
|
||||
|
||||
namespace Internals
|
||||
{
|
||||
class JsonNodeWrapper
|
||||
{
|
||||
friend class JsonValue;
|
||||
|
||||
public:
|
||||
public:
|
||||
JsonNodeWrapper()
|
||||
: _node(0)
|
||||
{
|
||||
@ -18,7 +23,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
void duplicate(const JsonNodeWrapper& other)
|
||||
{
|
||||
@ -33,5 +38,6 @@ protected:
|
||||
}
|
||||
|
||||
JsonNode* _node;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
#include "JsonNode.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
class JsonNode;
|
||||
class JsonBuffer;
|
||||
#include "JsonNode.h"
|
||||
|
||||
class JsonParser
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
class JsonBuffer;
|
||||
|
||||
namespace Internals
|
||||
{
|
||||
class JsonNode;
|
||||
|
||||
class JsonParser
|
||||
{
|
||||
public:
|
||||
JsonParser(JsonBuffer* buffer, char* json)
|
||||
: _buffer(buffer), _ptr(json)
|
||||
{
|
||||
@ -16,7 +21,7 @@ public:
|
||||
|
||||
JsonNode* parseAnything();
|
||||
|
||||
private:
|
||||
private:
|
||||
JsonBuffer* _buffer;
|
||||
char* _ptr;
|
||||
|
||||
@ -40,4 +45,6 @@ private:
|
||||
inline JsonNode* parseString();
|
||||
|
||||
JsonNode *parseDouble();
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
@ -2,9 +2,13 @@
|
||||
|
||||
#include "../Arduino/Print.h"
|
||||
|
||||
class JsonWriter
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
namespace Internals
|
||||
{
|
||||
class JsonWriter
|
||||
{
|
||||
public:
|
||||
explicit JsonWriter(Print* sink)
|
||||
: _sink(sink), _length(0)
|
||||
{
|
||||
@ -42,8 +46,9 @@ public:
|
||||
_length += _sink->print("{}");
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Print* _sink;
|
||||
size_t _length;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,13 @@
|
||||
#include "JsonWriter.h"
|
||||
#include "IndentedPrint.h"
|
||||
|
||||
using namespace ArduinoJson::Generator;
|
||||
|
||||
class PrettyJsonWriter : public JsonWriter
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
namespace Internals
|
||||
{
|
||||
class PrettyJsonWriter : public JsonWriter
|
||||
{
|
||||
public:
|
||||
explicit PrettyJsonWriter(IndentedPrint* sink)
|
||||
: JsonWriter(sink), _indenter(sink)
|
||||
{
|
||||
@ -48,7 +50,7 @@ public:
|
||||
_length += _sink->write('}');
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
IndentedPrint* _indenter;
|
||||
|
||||
void indent()
|
||||
@ -62,4 +64,6 @@ private:
|
||||
_length += _indenter->println();
|
||||
_indenter->unindent();
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
@ -2,14 +2,16 @@
|
||||
|
||||
#include "JsonContainer.h"
|
||||
|
||||
class JsonArray : public JsonContainer
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
class JsonArray : public JsonContainer
|
||||
{
|
||||
public:
|
||||
JsonArray()
|
||||
{
|
||||
}
|
||||
|
||||
explicit JsonArray(JsonNode* node)
|
||||
explicit JsonArray(Internals::JsonNode* node)
|
||||
: JsonContainer(node)
|
||||
{
|
||||
}
|
||||
@ -30,5 +32,5 @@ public:
|
||||
{
|
||||
return _node && _node->isArray();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -3,15 +3,20 @@
|
||||
#include "JsonArray.h"
|
||||
#include "JsonObject.h"
|
||||
|
||||
class JsonParser;
|
||||
|
||||
class JsonBuffer
|
||||
namespace ArduinoJson
|
||||
{
|
||||
friend class JsonContainer;
|
||||
friend class JsonNode;
|
||||
friend class JsonParser;
|
||||
namespace Internals
|
||||
{
|
||||
class JsonParser;
|
||||
}
|
||||
|
||||
public:
|
||||
class JsonBuffer
|
||||
{
|
||||
friend class JsonContainer;
|
||||
friend class Internals::JsonNode;
|
||||
friend class Internals::JsonParser;
|
||||
|
||||
public:
|
||||
virtual ~JsonBuffer() {};
|
||||
|
||||
JsonArray createArray()
|
||||
@ -30,16 +35,17 @@ public:
|
||||
|
||||
JsonValue parseValue(char* json);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void* allocateNode() = 0;
|
||||
|
||||
private:
|
||||
JsonNode* createNode();
|
||||
private:
|
||||
Internals::JsonNode* createNode();
|
||||
|
||||
JsonNode* createArrayNode();
|
||||
JsonNode* createBoolNode(bool value);
|
||||
JsonNode* createDoubleNode(double value, int decimals);
|
||||
JsonNode* createLongNode(long value);
|
||||
JsonNode* createObjectNode();
|
||||
JsonNode* createStringNode(const char* value);
|
||||
};
|
||||
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);
|
||||
};
|
||||
}
|
@ -1,26 +1,25 @@
|
||||
#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;
|
||||
class JsonArray;
|
||||
class JsonObject;
|
||||
class JsonValue;
|
||||
|
||||
class JsonContainer : public Printable, public Internals::JsonNodeWrapper
|
||||
{
|
||||
friend class JsonArray;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
public:
|
||||
JsonContainer() {}
|
||||
|
||||
explicit JsonContainer(JsonNode* node)
|
||||
explicit JsonContainer(Internals::JsonNode* node)
|
||||
: JsonNodeWrapper(node)
|
||||
{
|
||||
}
|
||||
@ -33,23 +32,23 @@ public:
|
||||
virtual size_t printTo(Print& print) 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;
|
||||
|
||||
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 removeChild(JsonNode*);
|
||||
JsonNode* createNode();
|
||||
};
|
||||
|
||||
void addChild(Internals::JsonNode*);
|
||||
void removeChild(Internals::JsonNode*);
|
||||
Internals::JsonNode* createNode();
|
||||
};
|
||||
}
|
@ -2,15 +2,17 @@
|
||||
|
||||
#include "JsonContainer.h"
|
||||
|
||||
class JsonObject : public JsonContainer
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
class JsonObject : public JsonContainer
|
||||
{
|
||||
public:
|
||||
|
||||
JsonObject()
|
||||
{
|
||||
}
|
||||
|
||||
explicit JsonObject(JsonNode* node)
|
||||
explicit JsonObject(Internals::JsonNode* node)
|
||||
: JsonContainer(node)
|
||||
{
|
||||
}
|
||||
@ -21,6 +23,7 @@ public:
|
||||
JsonArray createNestedArray(const char* key);
|
||||
JsonObject createNestedObject(const char* key);
|
||||
|
||||
private:
|
||||
JsonNode* getOrCreateNodeAt(const char* key);
|
||||
};
|
||||
private:
|
||||
Internals::JsonNode* getOrCreateNodeAt(const char* key);
|
||||
};
|
||||
}
|
@ -2,17 +2,19 @@
|
||||
|
||||
#include "Internals/JsonNodeWrapper.h"
|
||||
|
||||
class JsonArray;
|
||||
class JsonContainer;
|
||||
class JsonObject;
|
||||
|
||||
class JsonValue : public JsonNodeWrapper
|
||||
namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
class JsonArray;
|
||||
class JsonContainer;
|
||||
class JsonObject;
|
||||
|
||||
class JsonValue : public Internals::JsonNodeWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
JsonValue() {}
|
||||
|
||||
explicit JsonValue(JsonNode* node)
|
||||
explicit JsonValue(Internals::JsonNode* node)
|
||||
: JsonNodeWrapper(node)
|
||||
{
|
||||
}
|
||||
@ -22,7 +24,7 @@ public:
|
||||
void operator=(double x) { set(x, 2); }
|
||||
void operator=(int);
|
||||
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 const char*() const;
|
||||
@ -33,4 +35,5 @@ public:
|
||||
operator JsonObject() const;
|
||||
|
||||
void set(double value, int decimals);
|
||||
};
|
||||
};
|
||||
}
|
@ -3,12 +3,14 @@
|
||||
#include "JsonBuffer.h"
|
||||
#include "JsonObject.h"
|
||||
|
||||
template<int CAPACITY>
|
||||
class StaticJsonBuffer : public JsonBuffer
|
||||
namespace ArduinoJson
|
||||
{
|
||||
template<int CAPACITY>
|
||||
class StaticJsonBuffer : public JsonBuffer
|
||||
{
|
||||
friend class JsonObject;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
explicit StaticJsonBuffer()
|
||||
: _size(0)
|
||||
@ -27,7 +29,7 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void* allocateNode()
|
||||
{
|
||||
if (_size >= CAPACITY) return 0;
|
||||
@ -35,8 +37,8 @@ protected:
|
||||
return &_buffer[_size++];
|
||||
}
|
||||
|
||||
private:
|
||||
JsonNode _buffer[CAPACITY];
|
||||
private:
|
||||
Internals::JsonNode _buffer[CAPACITY];
|
||||
int _size;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "ArduinoJson/Internals/IndentedPrint.h"
|
||||
|
||||
using namespace ArduinoJson::Generator;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
void IndentedPrint::indent()
|
||||
{
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "ArduinoJson/JsonObject.h"
|
||||
#include "ArduinoJson/JsonBuffer.h"
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
void JsonNode::writeTo(JsonWriter& writer)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -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)
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "ArduinoJson/JsonObject.h"
|
||||
#include "ArduinoJson/Internals/JsonNode.h"
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
void JsonValue::operator=(bool value)
|
||||
{
|
||||
if (_node)
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
|
||||
using namespace ArduinoJson::Generator;
|
||||
using namespace ArduinoJson;
|
||||
|
||||
struct Person
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_Container_Tests : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_PrettyPrintTo_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <ArduinoJson/JsonObject.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonArray_PrintTo_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_Container_Tests : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_PrettyPrintTo_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonObject_Serialization_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonParser_Array_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonValueTests : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||
#include <ArduinoJson/JsonValue.h>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
TEST(StaticJsonBuffer, CapacityMatchTemplateParameter)
|
||||
{
|
||||
StaticJsonBuffer<42> json;
|
||||
|
Reference in New Issue
Block a user