Dynamic Alloc Remove array Call back function

Dependents:   WIZwiki-REST_mc

Fork of MbedJSONValue by Lawrence Lee

Revision:
6:f8bec9cada34
Parent:
5:e15fd7be9e74
--- a/MbedJSONValue.h	Wed Mar 02 03:27:22 2016 +0000
+++ b/MbedJSONValue.h	Tue Apr 05 11:37:53 2016 +0000
@@ -33,6 +33,7 @@
 
 #define NB_TOKEN 10
 
+
 //#define DEBUG
 
 /*!< Number maximum of MbedJSONValue in an array or an object */
@@ -41,6 +42,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <vector>
+
+
+typedef  bool (*json_call_back)(void* param);
+
+bool default_json_cb(void* param);
 
 /** MbedJSONValue class
  *
@@ -104,7 +111,6 @@
  
 class MbedJSONValue {
 public:
-
     /**
     * \enum Type
     * \brief All types which can be used
@@ -122,14 +128,14 @@
     /**
     * MbedJSONValue constructor of type TypeNull
     */
-    MbedJSONValue() : _type(TypeNull), index_array(0), index_token(0) {}
+    MbedJSONValue() : accessible(false), cb_action(default_json_cb), _type(TypeNull), index_array(0), index_token(0)  {}
     
     /**
     * MbedJSONValue constructor of type TypeBoolean
     *
     * @param value the object created will be initialized with this boolean
     */
-    MbedJSONValue(bool value) : _type(TypeBoolean), index_array(0), index_token(0) {
+    MbedJSONValue(bool value) : accessible(false), cb_action(default_json_cb), _type(TypeBoolean), index_array(0), index_token(0){
         _value.asBool = value;
     }
     
@@ -138,7 +144,7 @@
     *
     * @param value the object created will be initialized with this integer
     */
-    MbedJSONValue(int value)  : _type(TypeInt), index_array(0), index_token(0) {
+    MbedJSONValue(int value)  :accessible(false), cb_action(default_json_cb), _type(TypeInt), index_array(0), index_token(0) {
         _value.asInt = value;
     }
     
@@ -147,7 +153,7 @@
     *
     * @param value the object created will be initialized with this double
     */
-    MbedJSONValue(double value)  : _type(TypeDouble), index_array(0), index_token(0) {
+    MbedJSONValue(double value)  : accessible(false), cb_action(default_json_cb), _type(TypeDouble), index_array(0), index_token(0) {
         _value.asDouble = value;
     }
 
@@ -156,7 +162,9 @@
     *
     * @param value the object created will be initialized with this string
     */
-    MbedJSONValue(std::string const& value) : _type(TypeString), index_array(0), index_token(0) {
+    MbedJSONValue(std::string const& value) : accessible(false), cb_action(default_json_cb), _type(TypeString), index_array(0), index_token(0) {
+//        printf("constructor:%s\r\n",value.c_str());
+        token.resize(0);
         _value.asString = new std::string(value);
     }
 
@@ -165,7 +173,7 @@
     *
     * @param value the object created will be initialized with this string
     */
-    MbedJSONValue(const char* value)  : _type(TypeString), index_array(0), index_token(0) {
+    MbedJSONValue(const char* value)  : accessible(false), cb_action(default_json_cb), _type(TypeString), index_array(0), index_token(0) {
         _value.asString = new std::string(value);
     }
 
@@ -297,8 +305,12 @@
     */
     std::string serialize();
 
-protected:
 
+    
+//protected:
+
+    bool accessible;
+    json_call_back  cb_action;
     // object type
     Type _type;
     
@@ -307,11 +319,14 @@
     int index_token;
 
     //an object can contain NB_TOKEN tokens. Each token have a name
-    MbedJSONValue * token[NB_TOKEN];
-    std::string * token_name[NB_TOKEN];
+    //MbedJSONValue * token[NB_TOKEN];
+    std::vector<MbedJSONValue*> token;
+    //std::string * token_name[NB_TOKEN];
+    std::vector<std::string*> token_name;
 
     //an object can contain an array of NB_TOKEN elements
-    MbedJSONValue * array[NB_TOKEN];
+    //MbedJSONValue * array[NB_TOKEN];
+    //std::vector<MbedJSONValue*> array;
 
     // Clean up
     void clean();
@@ -324,7 +339,8 @@
     } _value;
 
 
-    MbedJSONValue& operator[](int i) const { return *(array[i]); }
+    //MbedJSONValue& operator[](int i) const { return *(array[i]); }
+    MbedJSONValue& operator[](int i) const { return *(token[i]); }
     MbedJSONValue& operator[](std::string k) const;
     
     std::string to_str();