Switched to Google coding style to match cpplint expectations

This commit is contained in:
Benoit Blanchon
2014-10-23 23:13:13 +02:00
parent 5c8283b3e4
commit b43da1e421
47 changed files with 262 additions and 308 deletions

View File

@ -12,7 +12,7 @@
// This class reproduces Arduino's Print
class Print {
public:
public:
virtual size_t write(uint8_t) = 0;
size_t print(const char[]);

View File

@ -12,7 +12,7 @@
class Print;
class Printable {
public:
public:
virtual size_t printTo(Print &p) const = 0;
};

View File

@ -5,7 +5,7 @@
namespace ArduinoJson {
namespace Internals {
class CompactJsonWriter : public JsonWriter {
public:
public:
explicit CompactJsonWriter(Print *sink) : JsonWriter(sink) {}
virtual void beginArray() { _length += _sink->write('['); }

View File

@ -13,7 +13,7 @@ namespace Internals {
// This class is used by JsonPrintable::prettyPrintTo() but can also be used
// for your own purpose, like logging.
class IndentedPrint : public Print {
public:
public:
IndentedPrint(Print &p) : sink(&p) {
level = 0;
tabSize = 2;
@ -31,7 +31,7 @@ public:
// Set the number of space printed for each level of indentation
void setTabSize(uint8_t n);
private:
private:
Print *sink;
uint8_t level : 4;
uint8_t tabSize : 3;
@ -39,8 +39,8 @@ private:
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

@ -44,12 +44,12 @@ class JsonNode {
} asProxy;
};
public:
public:
JsonNode() : next(0), type(JSON_UNDEFINED) {}
JsonNode *next;
void writeTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
void writeTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
void setAsArray(JsonBuffer *buffer) {
type = JSON_ARRAY;
@ -104,16 +104,14 @@ public:
}
JsonBuffer *getContainerBuffer() {
if (type == JSON_PROXY)
return content.asProxy.target->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();
if (type == JSON_PROXY) return content.asProxy.target->getContainerChild();
return type == JSON_ARRAY || type == JSON_OBJECT ? content.asContainer.child
: 0;
}
@ -140,13 +138,14 @@ public:
void duplicate(JsonNode *other);
private:
private:
JsonNodeType type;
JsonNodeContent content;
inline void writeArrayTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
inline void
writeObjectTo(JsonWriter &); // TODO: <- move in JsonNodeSerializer
inline void writeArrayTo(
JsonWriter &); // TODO: <- move in JsonNodeSerializer
inline void writeObjectTo(
JsonWriter &); // TODO: <- move in JsonNodeSerializer
void setAsProxyOfSelf();

View File

@ -6,7 +6,7 @@ namespace ArduinoJson {
namespace Internals {
// TODO: replace by JsonArrayIterator and JsonObjectIterator
class JsonNodeIterator {
public:
public:
explicit JsonNodeIterator(JsonNode *node) : _node(node) {}
bool operator!=(const JsonNodeIterator &other) const {
@ -19,7 +19,7 @@ public:
JsonNode *operator->() const { return _node; }
private:
private:
JsonNode *_node;
};
}

View File

@ -9,12 +9,12 @@ namespace Internals {
class JsonNodeWrapper {
friend class JsonValue;
public:
public:
JsonNodeWrapper() : _node(0) {}
explicit JsonNodeWrapper(JsonNode *node) : _node(node) {}
protected:
protected:
void duplicate(const JsonNodeWrapper &other) {
if (!_node) {
_node = other._node;

View File

@ -9,12 +9,12 @@ namespace Internals {
class JsonNode;
class JsonParser {
public:
public:
JsonParser(JsonBuffer *buffer, char *json) : _buffer(buffer), _ptr(json) {}
JsonNode *parseAnything();
private:
private:
JsonBuffer *_buffer;
char *_ptr;

View File

@ -5,7 +5,7 @@
namespace ArduinoJson {
namespace Internals {
class JsonWriter {
public:
public:
explicit JsonWriter(Print *sink) : _sink(sink), _length(0) {}
size_t bytesWritten() { return _length; }
@ -31,7 +31,7 @@ public:
void writeEmptyObject() { _length += _sink->print("{}"); }
protected:
protected:
Print *_sink;
size_t _length;
};

View File

@ -6,7 +6,7 @@
namespace ArduinoJson {
namespace Internals {
class PrettyJsonWriter : public JsonWriter {
public:
public:
explicit PrettyJsonWriter(IndentedPrint *sink)
: JsonWriter(sink), _indenter(sink) {}
@ -37,7 +37,7 @@ public:
_length += _sink->write('}');
}
private:
private:
IndentedPrint *_indenter;
void indent() {

View File

@ -10,7 +10,7 @@
namespace ArduinoJson {
namespace Internals {
class QuotedString {
public:
public:
static size_t printTo(const char *, Print *);
static char *extractFrom(char *input, char **end);

View File

@ -10,7 +10,7 @@
namespace ArduinoJson {
namespace Internals {
class StringBuilder : public Print {
public:
public:
StringBuilder(char *buf, int size)
: buffer(buf), capacity(size - 1), length(0) {
buffer[0] = 0;
@ -18,7 +18,7 @@ public:
virtual size_t write(uint8_t c);
private:
private:
char *buffer;
int capacity;
int length;

View File

@ -5,7 +5,7 @@
namespace ArduinoJson {
class JsonArray : public JsonContainer {
public:
public:
JsonArray() {}
explicit JsonArray(Internals::JsonNode *node) : JsonContainer(node) {}
@ -17,7 +17,7 @@ public:
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(JsonContainer nestedArray); // TODO: should allow JsonValue too
JsonArray createNestedArray();
JsonObject createNestedObject();

View File

@ -8,7 +8,7 @@ class JsonArray;
class JsonArrayIterator {
friend class JsonArray;
public:
public:
explicit JsonArrayIterator(Internals::JsonNode *node) : _node(node) {}
void operator++() { _node = _node->next; }
@ -23,7 +23,7 @@ public:
return _node != other._node;
}
private:
private:
Internals::JsonNode *_node;
};
}

View File

@ -13,7 +13,7 @@ class JsonBuffer {
friend class Internals::JsonNode;
friend class Internals::JsonParser;
public:
public:
virtual ~JsonBuffer(){};
JsonArray createArray() { return JsonArray(createArrayNode()); }
@ -24,12 +24,12 @@ public:
JsonArray parseArray(char *json);
JsonObject parseObject(char *json);
JsonValue parseValue(char *json); // TODO: remove
JsonValue parseValue(char *json); // TODO: remove
protected:
protected:
virtual void *allocateNode() = 0;
private:
private:
Internals::JsonNode *createNode();
Internals::JsonNode *createArrayNode();

View File

@ -14,7 +14,7 @@ class JsonValue;
class JsonContainer : public Printable, public Internals::JsonNodeWrapper {
friend class JsonArray;
public:
public:
JsonContainer() {}
explicit JsonContainer(Internals::JsonNode *node) : JsonNodeWrapper(node) {}
@ -30,7 +30,7 @@ public:
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);
}

View File

@ -5,7 +5,7 @@
namespace ArduinoJson {
class JsonObject : public JsonContainer {
public:
public:
JsonObject() {}
explicit JsonObject(Internals::JsonNode *node) : JsonContainer(node) {}
@ -22,7 +22,7 @@ public:
JsonObjectIterator end() { return JsonObjectIterator(0); }
private:
private:
Internals::JsonNode *getOrCreateNodeAt(const char *key);
};
}

View File

@ -8,7 +8,7 @@ class JsonObject;
class JsonObjectIterator {
friend class JsonObject;
public:
public:
explicit JsonObjectIterator(Internals::JsonNode *node)
: _objectKeyValue(node) {}
@ -29,7 +29,7 @@ public:
return _objectKeyValue != other._objectKeyValue;
}
private:
private:
JsonObjectKeyValue _objectKeyValue;
};
}

View File

@ -4,7 +4,7 @@
namespace ArduinoJson {
class JsonObjectKeyValue {
public:
public:
explicit JsonObjectKeyValue(Internals::JsonNode *node) : _node(node) {}
const char *key() const { return _node->getAsObjectKey(); }
@ -21,7 +21,7 @@ public:
Internals::JsonNode *next() { return _node->next; }
private:
private:
Internals::JsonNode *_node;
};
}

View File

@ -8,7 +8,7 @@ class JsonContainer;
class JsonObject;
class JsonValue : public Internals::JsonNodeWrapper {
public:
public:
JsonValue() {}
explicit JsonValue(Internals::JsonNode *node) : JsonNodeWrapper(node) {}
@ -32,6 +32,9 @@ public:
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

@ -4,10 +4,11 @@
#include "JsonObject.hpp"
namespace ArduinoJson {
template <int CAPACITY> class StaticJsonBuffer : public JsonBuffer {
template <int CAPACITY>
class StaticJsonBuffer : public JsonBuffer {
friend class JsonObject;
public:
public:
explicit StaticJsonBuffer() : _size(0) {}
virtual ~StaticJsonBuffer() {}
@ -16,15 +17,14 @@ public:
int size() { return _size; }
protected:
protected:
virtual void *allocateNode() {
if (_size >= CAPACITY)
return 0;
if (_size >= CAPACITY) return 0;
return &_buffer[_size++];
}
private:
private:
Internals::JsonNode _buffer[CAPACITY];
int _size;
};