From 98e2c82ceaaeb887ba9ca0e7e8e3811a3a9d6415 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 11 Jan 2014 22:55:00 +0100 Subject: [PATCH] Removed class JsonParserBase --- JsonArray.h | 4 +++- JsonHashTable.h | 4 +++- JsonParser.cpp | 24 ------------------------ JsonParser.h | 30 ++++++++++-------------------- 4 files changed, 16 insertions(+), 46 deletions(-) delete mode 100644 JsonParser.cpp diff --git a/JsonArray.h b/JsonArray.h index 73bcd682..c848d362 100644 --- a/JsonArray.h +++ b/JsonArray.h @@ -12,7 +12,9 @@ class JsonHashTable; class JsonArray : public JsonObjectBase { - friend class JsonParserBase; + template + friend class JsonParser; + friend class JsonHashTable; public: diff --git a/JsonHashTable.h b/JsonHashTable.h index 96ad7400..f9ebd335 100644 --- a/JsonHashTable.h +++ b/JsonHashTable.h @@ -12,8 +12,10 @@ class JsonArray; class JsonHashTable : public JsonObjectBase { + template + friend class JsonParser; + friend class JsonArray; - friend class JsonParserBase; public: diff --git a/JsonParser.cpp b/JsonParser.cpp deleted file mode 100644 index bb5da5c5..00000000 --- a/JsonParser.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* malloc-free JSON parser for Arduino -* Benoit Blanchon 2014 - MIT License -*/ - -#include "JsonParser.h" - -JsonParserBase::JsonParserBase(jsmntok_t* tokens, int maxTokenCount) -{ - this->maxTokenCount = maxTokenCount; - this->tokens = tokens; -} - -jsmntok_t* JsonParserBase::parse(char* jsonString) -{ - jsmn_parser parser; - - jsmn_init(&parser); - - if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, maxTokenCount)) - return 0; - - return tokens; -} \ No newline at end of file diff --git a/JsonParser.h b/JsonParser.h index 041da2db..593d1262 100644 --- a/JsonParser.h +++ b/JsonParser.h @@ -9,7 +9,8 @@ #include "JsonHashTable.h" #include "JsonArray.h" -class JsonParserBase +template +class JsonParser { public: @@ -22,31 +23,20 @@ public: { return JsonHashTable(json, parse(json)); } - -protected: - JsonParserBase(jsmntok_t* tokens, int maxTokenCount); - private: - jsmntok_t* parse(char* json); - - int maxTokenCount; - jsmntok_t* tokens; -}; - -template -class JsonParser : public JsonParserBase -{ -public: - - JsonParser() - : JsonParserBase(tokens, N) + jsmntok_t* parse(char* jsonString) { + jsmn_parser parser; + jsmn_init(&parser); + + if (JSMN_SUCCESS != jsmn_parse(&parser, jsonString, tokens, N)) + return 0; + + return tokens; } -private: - jsmntok_t tokens[N]; };