Răsfoiți Sursa

Moved all JsonParser code in a sub-folder.

Benoit Blanchon 11 ani în urmă
părinte
comite
3d8b31b1ec

+ 11 - 0
JsonParser.cpp

@@ -0,0 +1,11 @@
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+// This file is here to help the Arduino IDE find the .cpp files
+
+#include "JsonParser/JsonArray.cpp"
+#include "JsonParser/JsonHashTable.cpp"
+#include "JsonParser/JsonObjectBase.cpp"
+#include "JsonParser/Jsmn.cpp"

+ 1 - 64
JsonParser.h

@@ -3,67 +3,4 @@
 * Benoit Blanchon 2014 - MIT License
 */
 
-#ifndef __JSONPARSER_H
-#define __JSONPARSER_H
-
-#include "JsonHashTable.h"
-#include "JsonArray.h"
-
-/*
-* The JSON parser.
-*
-* You need to specifiy the number of token to be allocated for that parser.
-* Values from 16 to 32 are recommended.
-* The parser size will be MAX_TOKEN*8 bytes.
-* Don't forget that the memory size of standard Arduino board is only 2KB
-*
-* CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the
-* JsonParser, so they need the JsonParser to be in memory to work.
-* As a result, you must not create JsonArray and JsonHashTable that have a 
-* longer life that the JsonParser.
-*/
-template <int MAX_TOKENS>
-class JsonParser
-{
-public:
-
-	/*
-	* Parse the JSON string and return a array.
-	*
-	* The content of the string may be altered to add '\0' at the
-	* end of string tokens
-	*/ 
-	JsonArray parseArray(char* json)
-	{
-		return JsonArray(json, parse(json));
-	}
-
-	/*
-	* Parse the JSON string and return a array.
-	*
-	* The content of the string may be altered to add '\0' at the
-	* end of string tokens
-	*/
-	JsonHashTable parseHashTable(char* json)
-	{
-		return JsonHashTable(json, parse(json));
-	}
-
-private:
-
-	jsmntok_t* parse(char* json)
-	{
-		jsmn_parser parser;
-		jsmn_init(&parser);
-
-		if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, MAX_TOKENS))
-			return 0;
-
-		return tokens;
-	}
-
-	jsmntok_t tokens[MAX_TOKENS];
-};
-
-#endif
-
+#include "JsonParser/JsonParser.h"

+ 0 - 0
JsonArray.cpp → JsonParser/JsonArray.cpp


+ 0 - 0
JsonArray.h → JsonParser/JsonArray.h


+ 0 - 0
JsonHashTable.cpp → JsonParser/JsonHashTable.cpp


+ 0 - 0
JsonHashTable.h → JsonParser/JsonHashTable.h


+ 0 - 0
JsonObjectBase.cpp → JsonParser/JsonObjectBase.cpp


+ 1 - 1
JsonObjectBase.h → JsonParser/JsonObjectBase.h

@@ -7,7 +7,7 @@
 #ifndef __JSONOBJECTBASE_H
 #define __JSONOBJECTBASE_H
 
-#include "utility/jsmn.h"
+#include "jsmn.h"
 
 class JsonObjectBase
 {

+ 69 - 0
JsonParser/JsonParser.h

@@ -0,0 +1,69 @@
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#ifndef __JSONPARSER_H
+#define __JSONPARSER_H
+
+#include "JsonHashTable.h"
+#include "JsonArray.h"
+
+/*
+* The JSON parser.
+*
+* You need to specifiy the number of token to be allocated for that parser.
+* Values from 16 to 32 are recommended.
+* The parser size will be MAX_TOKEN*8 bytes.
+* Don't forget that the memory size of standard Arduino board is only 2KB
+*
+* CAUTION: JsonArray and JsonHashTable contain pointers to tokens of the
+* JsonParser, so they need the JsonParser to be in memory to work.
+* As a result, you must not create JsonArray and JsonHashTable that have a 
+* longer life that the JsonParser.
+*/
+template <int MAX_TOKENS>
+class JsonParser
+{
+public:
+
+	/*
+	* Parse the JSON string and return a array.
+	*
+	* The content of the string may be altered to add '\0' at the
+	* end of string tokens
+	*/ 
+	JsonArray parseArray(char* json)
+	{
+		return JsonArray(json, parse(json));
+	}
+
+	/*
+	* Parse the JSON string and return a array.
+	*
+	* The content of the string may be altered to add '\0' at the
+	* end of string tokens
+	*/
+	JsonHashTable parseHashTable(char* json)
+	{
+		return JsonHashTable(json, parse(json));
+	}
+
+private:
+
+	jsmntok_t* parse(char* json)
+	{
+		jsmn_parser parser;
+		jsmn_init(&parser);
+
+		if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, MAX_TOKENS))
+			return 0;
+
+		return tokens;
+	}
+
+	jsmntok_t tokens[MAX_TOKENS];
+};
+
+#endif
+

+ 0 - 0
README.md → JsonParser/README.md


+ 0 - 0
utility/jsmn.cpp → JsonParser/jsmn.cpp


+ 0 - 0
utility/jsmn.h → JsonParser/jsmn.h


+ 0 - 0
tests/.gitignore → JsonParserTests/.gitignore


+ 0 - 0
tests/ArduinoJsonParserTests.sln → JsonParserTests/ArduinoJsonParserTests.sln


+ 11 - 11
tests/ArduinoJsonParserTests.vcxproj → JsonParserTests/ArduinoJsonParserTests.vcxproj

@@ -84,22 +84,22 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="..\JsonArray.h" />
-    <ClInclude Include="..\JsonHashTable.h" />
-    <ClInclude Include="..\JsonObjectBase.h" />
-    <ClInclude Include="..\JsonParser.h" />
-    <ClInclude Include="..\utility\jsmn.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\JsonArray.cpp" />
-    <ClCompile Include="..\JsonHashTable.cpp" />
-    <ClCompile Include="..\JsonObjectBase.cpp" />
-    <ClCompile Include="..\utility\jsmn.cpp" />
+    <ClCompile Include="..\JsonParser\jsmn.cpp" />
+    <ClCompile Include="..\JsonParser\JsonArray.cpp" />
+    <ClCompile Include="..\JsonParser\JsonHashTable.cpp" />
+    <ClCompile Include="..\JsonParser\JsonObjectBase.cpp" />
     <ClCompile Include="TestArrayExample.cpp" />
     <ClCompile Include="TestArrays.cpp" />
     <ClCompile Include="TestHashTableExample.cpp" />
     <ClCompile Include="TestGbathreeStrings.cpp" />
   </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\JsonParser\jsmn.h" />
+    <ClInclude Include="..\JsonParser\JsonArray.h" />
+    <ClInclude Include="..\JsonParser\JsonHashTable.h" />
+    <ClInclude Include="..\JsonParser\JsonObjectBase.h" />
+    <ClInclude Include="..\JsonParser\JsonParser.h" />
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>

+ 25 - 25
tests/ArduinoJsonParserTests.vcxproj.filters → JsonParserTests/ArduinoJsonParserTests.vcxproj.filters

@@ -15,46 +15,46 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\JsonArray.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\JsonHashTable.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\JsonObjectBase.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\JsonParser.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\utility\jsmn.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\JsonArray.cpp">
+    <ClCompile Include="TestHashTableExample.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\JsonHashTable.cpp">
+    <ClCompile Include="TestArrayExample.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\JsonObjectBase.cpp">
+    <ClCompile Include="TestGbathreeStrings.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\utility\jsmn.cpp">
+    <ClCompile Include="TestArrays.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="TestHashTableExample.cpp">
+    <ClCompile Include="..\JsonParser\jsmn.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="TestArrayExample.cpp">
+    <ClCompile Include="..\JsonParser\JsonArray.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="TestGbathreeStrings.cpp">
+    <ClCompile Include="..\JsonParser\JsonHashTable.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="TestArrays.cpp">
+    <ClCompile Include="..\JsonParser\JsonObjectBase.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\JsonParser\jsmn.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\JsonParser\JsonArray.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\JsonParser\JsonHashTable.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\JsonParser\JsonObjectBase.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\JsonParser\JsonParser.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
 </Project>

+ 0 - 0
tests/TestArrayExample.cpp → JsonParserTests/TestArrayExample.cpp


+ 0 - 0
tests/TestArrays.cpp → JsonParserTests/TestArrays.cpp


+ 0 - 0
tests/TestGbathreeStrings.cpp → JsonParserTests/TestGbathreeStrings.cpp


+ 25 - 0
JsonParserTests/TestHashGenerator.cpp

@@ -0,0 +1,25 @@
+#include "stdafx.h"
+#include "CppUnitTest.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace ArduinoJsonParserTests
+{
+	TEST_CLASS(TestHashGenerator)
+	{
+	public:
+		
+		TEST_METHOD(TestMethod1)
+		{
+            JsonArray<5> arr;
+            arr.Add(1);
+            arr.Add("Hi!");
+
+            JsonHashTable<4> hash;
+            hash.Add("key1", 1);
+            hash.Add("key2", "Hello!");
+            hash.Add("key3", arr);
+		}
+
+	};
+}

+ 0 - 0
tests/TestHashTableExample.cpp → JsonParserTests/TestHashTableExample.cpp