From ae7149419c1cb287e3135ff733cb6b8d129e5326 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 13 Jul 2015 14:44:57 +0900 Subject: [PATCH] Remove unused 'double' value manipulation functions from json Change-Id: I30ad4d87354da7cd7f8ea25956917759d47d76cc Signed-off-by: Mu-Woong --- include/json.h | 168 +++++++++++++++++++++++++-------------------------------- src/json.cpp | 12 +++++ 2 files changed, 84 insertions(+), 96 deletions(-) diff --git a/include/json.h b/include/json.h index a63c429..61b9aa8 100644 --- a/include/json.h +++ b/include/json.h @@ -29,106 +29,82 @@ do { \ } while(0) #define EMPTY_JSON_OBJECT "{}" -#define DEFAULT_PRECISION 3 -#define COMMON_ATTR_CLIENT_APP_ID "_ClientAppId_" namespace ctx { class json { - private: - typedef struct _JsonNode json_node_t; - json_node_t * json_node; - - void parse(const char* s); - void release(); - - /* For json vs json comparison */ - bool get_member_list(json_node_t* node, std::list& list); - bool node_equals(json_node_t* lhs, json_node_t* rhs); - bool value_equals(json_node_t* lhs, json_node_t* rhs); - bool object_equals(json_node_t* lhs, json_node_t* rhs); - bool array_equals(json_node_t* lhs, json_node_t* rhs); - - public: - json(); - json(const char* s); - json(const std::string& s); - - /* This json(const json& j) only copies the reference to the underlying json node. - * Therefore, changes applied to a json object affect the other. - * If you need to create a 'real' copy of a json, which can be manipulated separately, - * utilize the str() function, e.g., ctx::json copy(original.str()); - */ - json(const json& j); - - //TODO: Constructor accepting a file descriptor? - - ~json(); - - json& operator=(const char* s); - json& operator=(const std::string& s); - - /* This operator=(const json& j) only copies the reference to the underlying json node. - * Therefore, changes applied to a json object affect the other. - * If you need to create a 'real' copy of a json, which can be manipulated separately, - * utilize the str() function, e.g., ctx::json copy = original.str(); - */ - json& operator=(const json& j); - - bool operator==(const json& rhs); - bool operator!=(const json& rhs); - - char* dup_cstr(); - std::string str(); - - bool get_keys(std::list* list); - - bool set(const char* path, const char* key, json& val); - bool set(const char* path, const char* key, int val); - bool set(const char* path, const char* key, int64_t val); - bool set(const char* path, const char* key, double val, int prec = DEFAULT_PRECISION); - bool set(const char* path, const char* key, std::string val); - - bool get(const char* path, const char* key, json* val); - bool get(const char* path, const char* key, int* val); - bool get(const char* path, const char* key, int64_t* val); - bool get(const char* path, const char* key, double* val); - bool get(const char* path, const char* key, std::string* val); - - int array_get_size(const char* path, const char* key); - - bool array_append(const char* path, const char* key, json& val); - bool array_append(const char* path, const char* key, int val); - bool array_append(const char* path, const char* key, int64_t val); - bool array_append(const char* path, const char* key, double val, int prec = DEFAULT_PRECISION); - bool array_append(const char* path, const char* key, std::string val); - - bool array_set_at(const char* path, const char* key, int index, json& val); - bool array_set_at(const char* path, const char* key, int index, int val); - bool array_set_at(const char* path, const char* key, int index, int64_t val); - bool array_set_at(const char* path, const char* key, int index, double val, int prec = DEFAULT_PRECISION); - bool array_set_at(const char* path, const char* key, int index, std::string val); - - bool get_array_elem(const char* path, const char* key, int index, json* val); - bool get_array_elem(const char* path, const char* key, int index, int* val); - bool get_array_elem(const char* path, const char* key, int index, int64_t* val); - bool get_array_elem(const char* path, const char* key, int index, double* val); - bool get_array_elem(const char* path, const char* key, int index, std::string* val); - -#if 0 -//TODO: Implement below helper functions if necessary - bool set_array(const char* path, const char* key, json val[], int size); - bool set_array(const char* path, const char* key, int val[], int size); - bool set_array(const char* path, const char* key, int64_t val[], int size); - bool set_array(const char* path, const char* key, double val[], int size); - bool set_array(const char* path, const char* key, std::string val[], int size); - - bool get_array(const char* path, const char* key, json** val, int* size); - bool get_array(const char* path, const char* key, int** val, int* size); - bool get_array(const char* path, const char* key, int64_t** val, int* size); - bool get_array(const char* path, const char* key, double** val, int* size); - bool get_array(const char* path, const char* key, std::string** val, int* size); -#endif + private: + typedef struct _JsonNode json_node_t; + json_node_t * json_node; + + void parse(const char* s); + void release(); + + /* For json vs json comparison */ + bool get_member_list(json_node_t* node, std::list& list); + bool node_equals(json_node_t* lhs, json_node_t* rhs); + bool value_equals(json_node_t* lhs, json_node_t* rhs); + bool object_equals(json_node_t* lhs, json_node_t* rhs); + bool array_equals(json_node_t* lhs, json_node_t* rhs); + + public: + json(); + json(const char* s); + json(const std::string& s); + + /* This json(const json& j) only copies the reference to the underlying json node. + * Therefore, changes applied to a json object affect the other. + * If you need to create a 'real' copy of a json, which can be manipulated separately, + * utilize the str() function, e.g., ctx::json copy(original.str()); + */ + json(const json& j); + + ~json(); + + json& operator=(const char* s); + json& operator=(const std::string& s); + + /* This operator=(const json& j) only copies the reference to the underlying json node. + * Therefore, changes applied to a json object affect the other. + * If you need to create a 'real' copy of a json, which can be manipulated separately, + * utilize the str() function, e.g., ctx::json copy = original.str(); + */ + json& operator=(const json& j); + + bool operator==(const json& rhs); + bool operator!=(const json& rhs); + + char* dup_cstr(); + std::string str(); + + bool get_keys(std::list* list); + + bool set(const char* path, const char* key, json& val); + bool set(const char* path, const char* key, int val); + bool set(const char* path, const char* key, int64_t val); + bool set(const char* path, const char* key, std::string val); + + bool get(const char* path, const char* key, json* val); + bool get(const char* path, const char* key, int* val); + bool get(const char* path, const char* key, int64_t* val); + bool get(const char* path, const char* key, std::string* val); + + int array_get_size(const char* path, const char* key); + + bool array_append(const char* path, const char* key, json& val); + bool array_append(const char* path, const char* key, int val); + bool array_append(const char* path, const char* key, int64_t val); + bool array_append(const char* path, const char* key, std::string val); + + bool array_set_at(const char* path, const char* key, int index, json& val); + bool array_set_at(const char* path, const char* key, int index, int val); + bool array_set_at(const char* path, const char* key, int index, int64_t val); + bool array_set_at(const char* path, const char* key, int index, std::string val); + + bool get_array_elem(const char* path, const char* key, int index, json* val); + bool get_array_elem(const char* path, const char* key, int index, int* val); + bool get_array_elem(const char* path, const char* key, int index, int64_t* val); + bool get_array_elem(const char* path, const char* key, int index, std::string* val); }; } /* namespace ctx */ diff --git a/src/json.cpp b/src/json.cpp index 10462d8..c3e0d2d 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -35,6 +35,7 @@ static double string_to_double(const char* in) return out; } +#if 0 static std::string double_to_string(double in, int prec) { // Locale-independent double-to-string conversion @@ -43,6 +44,7 @@ static std::string double_to_string(double in, int prec) ostr << std::setprecision(prec) << std::fixed << in; return ostr.str(); } +#endif ctx::json::json() { @@ -352,6 +354,7 @@ bool ctx::json::set(const char* path, const char* key, int64_t val) return true; } +#if 0 bool ctx::json::set(const char* path, const char* key, double val, int prec) { IF_FAIL_RETURN_TAG(this->json_node, false, _E, "Json object not initialized"); @@ -368,6 +371,7 @@ bool ctx::json::set(const char* path, const char* key, double val, int prec) json_object_set_string_member(jobj, key, double_to_string(val, prec).c_str()); return true; } +#endif bool ctx::json::set(const char* path, const char* key, std::string val) { @@ -459,6 +463,7 @@ bool ctx::json::get(const char* path, const char* key, int64_t* val) return true; } +#if 0 bool ctx::json::get(const char* path, const char* key, double* val) { IF_FAIL_RETURN_TAG(this->json_node, false, _E, "Json object not initialized"); @@ -481,6 +486,7 @@ bool ctx::json::get(const char* path, const char* key, double* val) return true; } +#endif bool ctx::json::get(const char* path, const char* key, std::string* val) { @@ -568,6 +574,7 @@ bool ctx::json::array_append(const char* path, const char* key, int64_t val) return true; } +#if 0 bool ctx::json::array_append(const char* path, const char* key, double val, int prec) { IF_FAIL_RETURN_TAG(this->json_node, false, _E, "Json object not initialized"); @@ -580,6 +587,7 @@ bool ctx::json::array_append(const char* path, const char* key, double val, int json_array_add_string_element(arr, double_to_string(val, prec).c_str()); return true; } +#endif bool ctx::json::array_append(const char* path, const char* key, std::string val) { @@ -646,6 +654,7 @@ bool ctx::json::array_set_at(const char* path, const char* key, int index, int64 return true; } +#if 0 bool ctx::json::array_set_at(const char* path, const char* key, int index, double val, int prec) { IF_FAIL_RETURN_TAG(this->json_node, false, _E, "Json object not initialized"); @@ -659,6 +668,7 @@ bool ctx::json::array_set_at(const char* path, const char* key, int index, doubl json_node_set_string(node, double_to_string(val, prec).c_str()); return true; } +#endif bool ctx::json::array_set_at(const char* path, const char* key, int index, std::string val) { @@ -731,6 +741,7 @@ bool ctx::json::get_array_elem(const char* path, const char* key, int index, int return true; } +#if 0 bool ctx::json::get_array_elem(const char* path, const char* key, int index, double* val) { IF_FAIL_RETURN_TAG(this->json_node, false, _E, "Json object not initialized"); @@ -757,6 +768,7 @@ bool ctx::json::get_array_elem(const char* path, const char* key, int index, dou return true; } +#endif bool ctx::json::get_array_elem(const char* path, const char* key, int index, std::string* val) { -- 2.7.4