Formated code with clang-format

This commit is contained in:
Benoit Blanchon
2014-10-23 19:54:00 +02:00
parent 888fdc1d54
commit 9175046f35
52 changed files with 2002 additions and 2638 deletions

View File

@ -11,16 +11,14 @@
#include <stdint.h>
// This class reproduces Arduino's Print
class Print
{
class Print {
public:
virtual size_t write(uint8_t) = 0;
virtual size_t write(uint8_t) = 0;
size_t print(const char[]);
size_t print(double, int = 2);
size_t print(long);
size_t println();
size_t print(const char[]);
size_t print(double, int = 2);
size_t print(long);
size_t println();
};
#else

View File

@ -11,11 +11,9 @@
class Print;
class Printable
{
class Printable {
public:
virtual size_t printTo(Print& p) const = 0;
virtual size_t printTo(Print &p) const = 0;
};
#else
@ -23,4 +21,3 @@ public:
#include <Printable.h>
#endif

View File

@ -2,47 +2,23 @@
#include "ArduinoJson/Internals/JsonWriter.hpp"
namespace ArduinoJson
{
namespace Internals
{
class CompactJsonWriter : public JsonWriter
{
public:
explicit CompactJsonWriter(Print* sink)
: JsonWriter(sink)
{
}
namespace ArduinoJson {
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('}'); }
};
}
}

View File

@ -7,47 +7,40 @@
#include "../Arduino/Print.hpp"
namespace ArduinoJson
{
namespace Internals
{
// Decorator on top of Print to allow indented output.
// This class is used by JsonPrintable::prettyPrintTo() but can also be used
// for your own purpose, like logging.
class IndentedPrint : public Print
{
public:
namespace ArduinoJson {
namespace Internals {
// Decorator on top of Print to allow indented output.
// This class is used by JsonPrintable::prettyPrintTo() but can also be used
// for your own purpose, like logging.
class IndentedPrint : public Print {
public:
IndentedPrint(Print &p) : sink(&p) {
level = 0;
tabSize = 2;
isNewLine = true;
}
IndentedPrint(Print& p)
: sink(&p)
{
level = 0;
tabSize = 2;
isNewLine = true;
}
virtual size_t write(uint8_t);
virtual size_t write(uint8_t);
// Adds one level of indentation
void indent();
// Adds one level of indentation
void indent();
// Removes one level of indentation
void unindent();
// Removes one level of indentation
void unindent();
// Set the number of space printed for each level of indentation
void setTabSize(uint8_t n);
// Set the number of space printed for each level of indentation
void setTabSize(uint8_t n);
private:
Print *sink;
uint8_t level : 4;
uint8_t tabSize : 3;
bool isNewLine : 1;
private:
Print* sink;
uint8_t level : 4;
uint8_t tabSize : 3;
bool isNewLine : 1;
size_t writeTabs();
size_t writeTabs();
static const int MAX_LEVEL = 15; // because it's only 4 bits
static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
};
}
static const int MAX_LEVEL = 15; // because it's only 4 bits
static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
};
}
}

View File

@ -1,191 +1,159 @@
#pragma once
namespace ArduinoJson
{
class JsonBuffer;
namespace ArduinoJson {
class JsonBuffer;
namespace Internals
{
class JsonWriter;
namespace Internals {
class JsonWriter;
class JsonNode
{
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.
};
class JsonNode {
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;
union JsonNodeContent {
bool asBoolean;
double asDouble;
long asInteger;
const char *asString;
struct
{
const char* key;
JsonNode* value;
} asKeyValue;
struct {
const char *key;
JsonNode *value;
} asKeyValue;
struct
{
JsonNode* child;
JsonBuffer* buffer;
} asContainer;
struct {
JsonNode *child;
JsonBuffer *buffer;
} asContainer;
struct
{
JsonNode* target;
} asProxy;
struct {
JsonNode *target;
} asProxy;
};
};
public:
JsonNode() : next(0), type(JSON_UNDEFINED) {}
public:
JsonNode()
: next(0), type(JSON_UNDEFINED)
{
JsonNode *next;
}
void writeTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
JsonNode* next;
void setAsArray(JsonBuffer *buffer) {
type = JSON_ARRAY;
content.asContainer.child = 0;
content.asContainer.buffer = buffer;
}
void writeTo(JsonWriter&); // TODO: <- move in JsonNodeSerializer
void setAsBoolean(bool value) {
type = JSON_BOOLEAN;
content.asBoolean = value;
}
void setAsArray(JsonBuffer* buffer)
{
type = JSON_ARRAY;
content.asContainer.child = 0;
content.asContainer.buffer = buffer;
}
void setAsLong(int value) {
type = JSON_LONG;
content.asInteger = value;
}
void setAsBoolean(bool value)
{
type = JSON_BOOLEAN;
content.asBoolean = value;
}
void setAsString(char const *value) {
type = JSON_STRING;
content.asString = value;
}
void setAsLong(int value)
{
type = JSON_LONG;
content.asInteger = value;
}
void setAsDouble(double value, int decimals) {
type = static_cast<JsonNodeType>(JSON_DOUBLE_0_DECIMALS + decimals);
content.asDouble = value;
}
void setAsString(char const* value)
{
type = JSON_STRING;
content.asString = value;
}
void setAsObject(JsonBuffer *buffer) {
type = JSON_OBJECT;
content.asContainer.child = 0;
content.asContainer.buffer = buffer;
}
void setAsDouble(double value, int decimals)
{
type = static_cast<JsonNodeType>(JSON_DOUBLE_0_DECIMALS + decimals);
content.asDouble = value;
}
void setAsObjectKeyValue(const char *key, JsonNode *value) {
type = JSON_KEY_VALUE;
content.asKeyValue.key = key;
content.asKeyValue.value = value;
}
void setAsObject(JsonBuffer* buffer)
{
type = JSON_OBJECT;
content.asContainer.child = 0;
content.asContainer.buffer = buffer;
}
bool getAsBoolean() {
return type == JSON_BOOLEAN ? content.asBoolean : false;
}
void setAsObjectKeyValue(const char* key, JsonNode* value)
{
type = JSON_KEY_VALUE;
content.asKeyValue.key = key;
content.asKeyValue.value = value;
}
double getAsDouble() {
return type >= JSON_DOUBLE_0_DECIMALS ? content.asDouble : 0;
}
bool getAsBoolean()
{
return type == JSON_BOOLEAN ? content.asBoolean : false;
}
long getAsInteger() { return type == JSON_LONG ? content.asInteger : 0; }
double getAsDouble()
{
return type >= JSON_DOUBLE_0_DECIMALS ? content.asDouble : 0;
}
const char *getAsString() {
return type == JSON_STRING ? content.asString : 0;
}
long getAsInteger()
{
return type == JSON_LONG ? content.asInteger : 0;
}
JsonBuffer *getContainerBuffer() {
if (type == JSON_PROXY)
return content.asProxy.target->getContainerBuffer();
return type == JSON_ARRAY || type == JSON_OBJECT
? content.asContainer.buffer
: 0;
}
const char* getAsString()
{
return type == JSON_STRING ? content.asString : 0;
}
JsonNode *getContainerChild() {
if (type == JSON_PROXY)
return content.asProxy.target->getContainerChild();
return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.child
: 0;
}
JsonBuffer* getContainerBuffer()
{
if (type == JSON_PROXY) return content.asProxy.target->getContainerBuffer();
return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.buffer : 0;
}
const char *getAsObjectKey() {
return type == JSON_KEY_VALUE ? content.asKeyValue.key : 0;
}
JsonNode* getContainerChild()
{
if (type == JSON_PROXY) return content.asProxy.target->getContainerChild();
return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.child : 0;
}
JsonNode *getAsObjectValue() {
return type == JSON_KEY_VALUE ? content.asKeyValue.value : 0;
}
const char* getAsObjectKey()
{
return type == JSON_KEY_VALUE ? content.asKeyValue.key : 0;
}
JsonNode *getProxyTarget() {
return type == JSON_PROXY ? content.asProxy.target : this;
}
JsonNode* getAsObjectValue()
{
return type == JSON_KEY_VALUE ? content.asKeyValue.value : 0;
}
bool isArray() { return type == JSON_ARRAY; }
JsonNode* getProxyTarget()
{
return type == JSON_PROXY ? content.asProxy.target : this;
}
bool isObject() { return type == JSON_OBJECT; }
bool isArray()
{
return type == JSON_ARRAY;
}
void addChild(JsonNode *childToAdd);
bool isObject()
{
return type == JSON_OBJECT;
}
void removeChild(JsonNode *childToRemove);
void addChild(JsonNode* childToAdd);
void duplicate(JsonNode *other);
void removeChild(JsonNode* childToRemove);
private:
JsonNodeType type;
JsonNodeContent content;
void duplicate(JsonNode* other);
inline void writeArrayTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
inline void
writeObjectTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
private:
JsonNodeType type;
JsonNodeContent content;
void setAsProxyOfSelf();
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 setAsProxyOf(JsonNode *target) {
type = JSON_PROXY;
content.asProxy.target = target;
}
};
}
}

View File

@ -2,42 +2,25 @@
#include "JsonNode.hpp"
namespace ArduinoJson
{
namespace Internals
{
// TODO: replace by JsonArrayIterator and JsonObjectIterator
class JsonNodeIterator
{
public:
namespace ArduinoJson {
namespace Internals {
// TODO: replace by JsonArrayIterator and JsonObjectIterator
class JsonNodeIterator {
public:
explicit JsonNodeIterator(JsonNode *node) : _node(node) {}
explicit JsonNodeIterator(JsonNode* node)
: _node(node)
{
}
bool operator!=(const JsonNodeIterator &other) const {
return _node != other._node;
}
bool operator!= (const JsonNodeIterator& other) const
{
return _node != other._node;
}
void operator++() { _node = _node->next; }
void operator++()
{
_node = _node->next;
}
JsonNode *operator*() const { return _node; }
JsonNode* operator*() const
{
return _node;
}
JsonNode *operator->() const { return _node; }
JsonNode* operator->() const
{
return _node;
}
private:
JsonNode* _node;
};
}
private:
JsonNode *_node;
};
}
}

View File

@ -2,42 +2,28 @@
#include "JsonNode.hpp"
namespace ArduinoJson
{
class JsonValue ;
namespace Internals
{
class JsonNodeWrapper
{
friend class JsonValue;
namespace ArduinoJson {
class JsonValue;
public:
JsonNodeWrapper()
: _node(0)
{
}
namespace Internals {
class JsonNodeWrapper {
friend class JsonValue;
explicit JsonNodeWrapper(JsonNode* node)
: _node(node)
{
}
public:
JsonNodeWrapper() : _node(0) {}
protected:
explicit JsonNodeWrapper(JsonNode *node) : _node(node) {}
void duplicate(const JsonNodeWrapper& other)
{
if (!_node)
{
_node = other._node;
}
else
{
_node->duplicate(other._node);
}
}
JsonNode* _node;
};
protected:
void duplicate(const JsonNodeWrapper &other) {
if (!_node) {
_node = other._node;
} else {
_node->duplicate(other._node);
}
}
JsonNode *_node;
};
}
}

View File

@ -2,44 +2,34 @@
#include "JsonNode.hpp"
namespace ArduinoJson
{
class JsonBuffer;
namespace ArduinoJson {
class JsonBuffer;
namespace Internals
{
class JsonNode;
namespace Internals {
class JsonNode;
class JsonParser
{
public:
JsonParser(JsonBuffer* buffer, char* json)
: _buffer(buffer), _ptr(json)
{
class JsonParser {
public:
JsonParser(JsonBuffer *buffer, char *json) : _buffer(buffer), _ptr(json) {}
}
JsonNode *parseAnything();
JsonNode* parseAnything();
private:
JsonBuffer *_buffer;
char *_ptr;
private:
JsonBuffer* _buffer;
char* _ptr;
bool isEnd() { return *_ptr == 0; }
bool isEnd()
{
return *_ptr == 0;
}
bool skip(char charToSkip);
void skipSpaces();
bool skip(char charToSkip);
void skipSpaces();
inline JsonNode* parseArray();
inline JsonNode* parseBoolean();
inline JsonNode* parseNull();
inline JsonNode* parseNumber();
inline JsonNode* parseObject();
inline JsonNode* parseObjectKeyValue();
inline JsonNode* parseString();
};
}
inline JsonNode *parseArray();
inline JsonNode *parseBoolean();
inline JsonNode *parseNull();
inline JsonNode *parseNumber();
inline JsonNode *parseObject();
inline JsonNode *parseObjectKeyValue();
inline JsonNode *parseString();
};
}
}

View File

@ -2,53 +2,38 @@
#include "../Arduino/Print.hpp"
namespace ArduinoJson
{
namespace Internals
{
class JsonWriter
{
public:
explicit JsonWriter(Print* sink)
: _sink(sink), _length(0)
{
}
namespace ArduinoJson {
namespace Internals {
class JsonWriter {
public:
explicit JsonWriter(Print *sink) : _sink(sink), _length(0) {}
size_t bytesWritten()
{
return _length;
}
size_t bytesWritten() { return _length; }
virtual void beginArray() = 0;
virtual void beginArray() = 0;
virtual void endArray() = 0;
virtual void endArray() = 0;
virtual void beginObject() = 0;
virtual void beginObject() = 0;
virtual void endObject() = 0;
virtual void endObject() = 0;
void writeString(const char* value);
void writeInteger(long value);
void writeBoolean(bool value);
void writeDouble(double value, int decimals);
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 writeColon() = 0;
virtual void writeComma() = 0;
virtual void writeComma() = 0;
void writeEmptyArray()
{
_length += _sink->print("[]");
}
void writeEmptyArray() { _length += _sink->print("[]"); }
void writeEmptyObject()
{
_length += _sink->print("{}");
}
void writeEmptyObject() { _length += _sink->print("{}"); }
protected:
Print* _sink;
size_t _length;
};
}
protected:
Print *_sink;
size_t _length;
};
}
}

View File

@ -3,67 +3,52 @@
#include "JsonWriter.hpp"
#include "IndentedPrint.hpp"
namespace ArduinoJson
{
namespace Internals
{
class PrettyJsonWriter : public JsonWriter
{
public:
explicit PrettyJsonWriter(IndentedPrint* sink)
: JsonWriter(sink), _indenter(sink)
{
}
namespace ArduinoJson {
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();
}
};
}
}

View File

@ -7,16 +7,13 @@
#include "../Arduino/Print.hpp"
namespace ArduinoJson
{
namespace Internals
{
class QuotedString
{
public:
static size_t printTo(const char*, Print*);
namespace ArduinoJson {
namespace Internals {
class QuotedString {
public:
static size_t printTo(const char *, Print *);
static char* extractFrom(char* input, char** end);
};
}
static char *extractFrom(char *input, char **end);
};
}
}

View File

@ -7,25 +7,21 @@
#include "../Arduino/Print.hpp"
namespace ArduinoJson
{
namespace Internals
{
class StringBuilder : public Print
{
public:
StringBuilder(char* buf, int size)
: buffer(buf), capacity(size - 1), length(0)
{
buffer[0] = 0;
}
namespace ArduinoJson {
namespace Internals {
class StringBuilder : public Print {
public:
StringBuilder(char *buf, int size)
: buffer(buf), capacity(size - 1), length(0) {
buffer[0] = 0;
}
virtual size_t write(uint8_t c);
virtual size_t write(uint8_t c);
private:
char* buffer;
int capacity;
int length;
};
}
private:
char *buffer;
int capacity;
int length;
};
}
}

View File

@ -3,42 +3,29 @@
#include "JsonContainer.hpp"
#include "JsonArrayIterator.hpp"
namespace ArduinoJson
{
class JsonArray : public JsonContainer
{
public:
JsonArray()
{
}
namespace ArduinoJson {
class JsonArray : public JsonContainer {
public:
JsonArray() {}
explicit JsonArray(Internals::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(static_cast<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(static_cast<long>(value)); }
void add(long value);
void add(JsonContainer nestedArray); // TODO: should allow JsonValue too
JsonArray createNestedArray();
JsonObject createNestedObject();
JsonArray createNestedArray();
JsonObject createNestedObject();
bool success()
{
return _node && _node->isArray();
}
bool success() { return _node && _node->isArray(); }
JsonArrayIterator begin();
JsonArrayIterator begin();
JsonArrayIterator end()
{
return JsonArrayIterator(0);
}
};
JsonArrayIterator end() { return JsonArrayIterator(0); }
};
}

View File

@ -2,41 +2,28 @@
#include "ArduinoJson/JsonValue.hpp"
namespace ArduinoJson
{
class JsonArray;
namespace ArduinoJson {
class JsonArray;
class JsonArrayIterator
{
friend class JsonArray;
class JsonArrayIterator {
friend class JsonArray;
public:
explicit JsonArrayIterator(Internals::JsonNode* node)
: _node(node)
{
}
public:
explicit JsonArrayIterator(Internals::JsonNode *node) : _node(node) {}
void operator++()
{
_node = _node->next;
}
void operator++() { _node = _node->next; }
JsonValue operator*() const
{
return JsonValue(_node);
}
JsonValue operator*() const { return JsonValue(_node); }
bool operator==(const JsonArrayIterator& other) const
{
return _node == other._node;
}
bool operator==(const JsonArrayIterator &other) const {
return _node == other._node;
}
bool operator!=(const JsonArrayIterator& other) const
{
return _node != other._node;
}
bool operator!=(const JsonArrayIterator &other) const {
return _node != other._node;
}
private:
Internals::JsonNode* _node;
};
private:
Internals::JsonNode *_node;
};
}

View File

@ -3,50 +3,42 @@
#include "JsonArray.hpp"
#include "JsonObject.hpp"
namespace ArduinoJson
{
namespace Internals
{
class JsonParser;
}
namespace ArduinoJson {
namespace Internals {
class JsonParser;
}
class JsonBuffer
{
friend class JsonContainer;
friend class Internals::JsonNode;
friend class Internals::JsonParser;
class JsonBuffer {
friend class JsonContainer;
friend class Internals::JsonNode;
friend class Internals::JsonParser;
public:
virtual ~JsonBuffer() {};
public:
virtual ~JsonBuffer(){};
JsonArray createArray()
{
return JsonArray(createArrayNode());
}
JsonArray createArray() { return JsonArray(createArrayNode()); }
JsonObject createObject()
{
return JsonObject(createObjectNode());
}
JsonObject createObject() { return JsonObject(createObjectNode()); }
JsonValue createValue();
JsonValue createValue();
JsonArray parseArray(char* json);
JsonObject parseObject(char* json);
JsonValue parseValue(char* json); // TODO: remove
JsonArray parseArray(char *json);
JsonObject parseObject(char *json);
JsonValue parseValue(char *json); // TODO: remove
protected:
virtual void* allocateNode() = 0;
protected:
virtual void *allocateNode() = 0;
private:
Internals::JsonNode* createNode();
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* createObjectKeyValueNode(const char* key, Internals::JsonNode* value);
Internals::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 *createObjectKeyValueNode(const char *key,
Internals::JsonNode *value);
Internals::JsonNode *createStringNode(const char *value);
};
}

View File

@ -6,49 +6,41 @@
#include "Internals/IndentedPrint.hpp"
#include "Internals/JsonNodeWrapper.hpp"
namespace ArduinoJson
{
class JsonArray;
class JsonObject;
class JsonValue;
namespace ArduinoJson {
class JsonArray;
class JsonObject;
class JsonValue;
class JsonContainer : public Printable, public Internals::JsonNodeWrapper
{
friend class JsonArray;
class JsonContainer : public Printable, public Internals::JsonNodeWrapper {
friend class JsonArray;
public:
JsonContainer() {}
public:
JsonContainer() {}
explicit JsonContainer(Internals::JsonNode* node)
: JsonNodeWrapper(node)
{
}
explicit JsonContainer(Internals::JsonNode *node) : JsonNodeWrapper(node) {}
size_t size() const;
size_t size() const;
bool operator==(JsonContainer const& other) const;
bool operator==(JsonContainer const &other) const;
size_t printTo(char* buffer, size_t bufferSize) const;
virtual size_t printTo(Print& print) const;
size_t printTo(char *buffer, size_t bufferSize) const;
virtual size_t printTo(Print &print) const;
size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
size_t prettyPrintTo(ArduinoJson::Internals::IndentedPrint& print) const;
size_t prettyPrintTo(Print& print) const;
size_t prettyPrintTo(char *buffer, size_t bufferSize) const;
size_t prettyPrintTo(ArduinoJson::Internals::IndentedPrint &print) const;
size_t prettyPrintTo(Print &print) const;
protected:
protected:
Internals::JsonNodeIterator beginChildren() const {
return Internals::JsonNodeIterator(_node ? _node->getContainerChild() : 0);
}
Internals::JsonNodeIterator beginChildren() const
{
return Internals::JsonNodeIterator(_node ? _node->getContainerChild() : 0);
}
Internals::JsonNodeIterator endChildren() const {
return Internals::JsonNodeIterator(0);
}
Internals::JsonNodeIterator endChildren() const
{
return Internals::JsonNodeIterator(0);
}
void addChild(Internals::JsonNode*);
void removeChild(Internals::JsonNode*);
Internals::JsonNode* createNode();
};
void addChild(Internals::JsonNode *);
void removeChild(Internals::JsonNode *);
Internals::JsonNode *createNode();
};
}

View File

@ -3,40 +3,26 @@
#include "ArduinoJson/JsonContainer.hpp"
#include "ArduinoJson/JsonObjectIterator.hpp"
namespace ArduinoJson
{
class JsonObject : public JsonContainer
{
public:
namespace ArduinoJson {
class JsonObject : public JsonContainer {
public:
JsonObject() {}
JsonObject()
{
}
explicit JsonObject(Internals::JsonNode *node) : JsonContainer(node) {}
explicit JsonObject(Internals::JsonNode* node)
: JsonContainer(node)
{
}
JsonValue operator[](const char *key);
void remove(const char *key);
JsonValue operator[](const char* key);
void remove(const char* key);
JsonArray createNestedArray(const char *key);
JsonObject createNestedObject(const char *key);
JsonArray createNestedArray(const char* key);
JsonObject createNestedObject(const char* key);
bool success() { return _node && _node->isObject(); }
bool success()
{
return _node && _node->isObject();
}
JsonObjectIterator begin();
JsonObjectIterator begin();
JsonObjectIterator end() { return JsonObjectIterator(0); }
JsonObjectIterator end()
{
return JsonObjectIterator(0);
}
private:
Internals::JsonNode* getOrCreateNodeAt(const char* key);
};
private:
Internals::JsonNode *getOrCreateNodeAt(const char *key);
};
}

View File

@ -2,47 +2,34 @@
#include "ArduinoJson/JsonObjectKeyValue.hpp"
namespace ArduinoJson
{
class JsonObject;
namespace ArduinoJson {
class JsonObject;
class JsonObjectIterator
{
friend class JsonObject;
class JsonObjectIterator {
friend class JsonObject;
public:
explicit JsonObjectIterator(Internals::JsonNode* node)
: _objectKeyValue(node)
{
}
public:
explicit JsonObjectIterator(Internals::JsonNode *node)
: _objectKeyValue(node) {}
JsonObjectIterator& operator++()
{
_objectKeyValue = JsonObjectKeyValue(_objectKeyValue.next());
return *this;
}
JsonObjectIterator &operator++() {
_objectKeyValue = JsonObjectKeyValue(_objectKeyValue.next());
return *this;
}
JsonObjectKeyValue operator*() const
{
return _objectKeyValue;
}
JsonObjectKeyValue operator*() const { return _objectKeyValue; }
JsonObjectKeyValue* operator->()
{
return &_objectKeyValue;
}
JsonObjectKeyValue *operator->() { return &_objectKeyValue; }
bool operator==(const JsonObjectIterator& other) const
{
return _objectKeyValue == other._objectKeyValue;
}
bool operator==(const JsonObjectIterator &other) const {
return _objectKeyValue == other._objectKeyValue;
}
bool operator!=(const JsonObjectIterator& other) const
{
return _objectKeyValue != other._objectKeyValue;
}
bool operator!=(const JsonObjectIterator &other) const {
return _objectKeyValue != other._objectKeyValue;
}
private:
JsonObjectKeyValue _objectKeyValue;
};
private:
JsonObjectKeyValue _objectKeyValue;
};
}

View File

@ -2,42 +2,26 @@
#include "ArduinoJson/JsonValue.hpp"
namespace ArduinoJson
{
class JsonObjectKeyValue
{
public:
explicit JsonObjectKeyValue(Internals::JsonNode* node)
: _node(node)
{
}
namespace ArduinoJson {
class JsonObjectKeyValue {
public:
explicit JsonObjectKeyValue(Internals::JsonNode *node) : _node(node) {}
const char* key() const
{
return _node->getAsObjectKey();
}
const char *key() const { return _node->getAsObjectKey(); }
JsonValue value()
{
return JsonValue(_node->getAsObjectValue());
}
JsonValue value() { return JsonValue(_node->getAsObjectValue()); }
bool operator==(const JsonObjectKeyValue& other) const
{
return _node == other._node;
}
bool operator==(const JsonObjectKeyValue &other) const {
return _node == other._node;
}
bool operator!=(const JsonObjectKeyValue& other) const
{
return _node != other._node;
}
bool operator!=(const JsonObjectKeyValue &other) const {
return _node != other._node;
}
Internals::JsonNode* next()
{
return _node->next;
}
Internals::JsonNode *next() { return _node->next; }
private:
Internals::JsonNode* _node;
};
private:
Internals::JsonNode *_node;
};
}

View File

@ -2,44 +2,36 @@
#include "Internals/JsonNodeWrapper.hpp"
namespace ArduinoJson
{
class JsonArray;
class JsonContainer;
class JsonObject;
namespace ArduinoJson {
class JsonArray;
class JsonContainer;
class JsonObject;
class JsonValue : public Internals::JsonNodeWrapper
{
public:
class JsonValue : public Internals::JsonNodeWrapper {
public:
JsonValue() {}
JsonValue() {}
explicit JsonValue(Internals::JsonNode *node) : JsonNodeWrapper(node) {}
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);
}
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);
void set(double value, int decimals);
template<typename T>
T as()
{
return static_cast<T>(*this);
}
};
template <typename T> T as() { return static_cast<T>(*this); }
};
}

View File

@ -3,42 +3,29 @@
#include "JsonBuffer.hpp"
#include "JsonObject.hpp"
namespace ArduinoJson
{
template<int CAPACITY>
class StaticJsonBuffer : public JsonBuffer
{
friend class JsonObject;
namespace ArduinoJson {
template <int CAPACITY> class StaticJsonBuffer : public JsonBuffer {
friend class JsonObject;
public:
public:
explicit StaticJsonBuffer() : _size(0) {}
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++];
}
return &_buffer[_size++];
}
private:
Internals::JsonNode _buffer[CAPACITY];
int _size;
};
private:
Internals::JsonNode _buffer[CAPACITY];
int _size;
};
}