diff --git a/WORKSPACE b/WORKSPACE index 1cdfa805..4f5684a8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,7 +18,7 @@ rules_proto_toolchains() git_repository( name = "workflow", - commit = "273134f0ffadbb40a59ce9155a1fde299cd9d68b", + commit = "ba98ed0945f8888f73350ddfe5d9681306103702", remote = "https://github.com/sogou/workflow.git") new_git_repository( diff --git a/tools/templates/config/Json.cc b/tools/templates/config/Json.cc index 2505a7a0..e9d88082 100644 --- a/tools/templates/config/Json.cc +++ b/tools/templates/config/Json.cc @@ -75,23 +75,22 @@ Json::Json(std::nullptr_t null) { } -Json::Json(double val) - : node_(json_value_create(JSON_VALUE_NUMBER, val)), parent_(nullptr), - allocated_(true) -{ -} - -Json::Json(int val) - : node_(json_value_create(JSON_VALUE_NUMBER, static_cast(val))), +Json::Json(bool val) + : node_(val ? json_value_create(JSON_VALUE_TRUE) + : json_value_create(JSON_VALUE_FALSE)), parent_(nullptr), allocated_(true) { } -Json::Json(bool val) - : node_(val ? json_value_create(JSON_VALUE_TRUE) - : json_value_create(JSON_VALUE_FALSE)), +Json::Json(const std::vector& val) + : node_(json_value_create(JSON_VALUE_ARRAY)), parent_(nullptr), allocated_(true) { + json_array_t* arr = json_value_array(node_); + for (const auto& str : val) + { + json_array_append(arr, JSON_VALUE_STRING, str.c_str()); + } } // for parse @@ -378,6 +377,11 @@ bool Json::can_obj_push_back() void Json::push_back(const std::string& key, bool val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -389,6 +393,11 @@ void Json::push_back(const std::string& key, bool val) void Json::push_back(const std::string& key, std::nullptr_t val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -404,6 +413,11 @@ void Json::push_back(const std::string& key, const std::string& val) void Json::push_back(const std::string& key, const char* val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -414,6 +428,11 @@ void Json::push_back(const std::string& key, const char* val) void Json::push_back(const std::string& key, const std::vector& val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -430,6 +449,11 @@ void Json::push_back(const std::string& key, const std::vector& val void Json::push_back(const std::string& key, const Json& val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -552,15 +576,18 @@ void Json::normal_push_back(const std::string& key, { json_object_t* obj = json_value_object(parent_); const json_value_t* find = json_object_find(key.c_str(), obj); + const json_value_t* v; if (find == nullptr) { - json_object_append(obj, key.c_str(), JSON_VALUE_NULL); - return; + v = json_object_append(obj, key.c_str(), JSON_VALUE_ARRAY); + } + else + { + v = json_object_insert_before(find, obj, key.c_str(), + JSON_VALUE_ARRAY); + json_value_t* remove_val = json_object_remove(find, obj); + json_value_destroy(remove_val); } - const json_value_t *v = json_object_insert_before(find, obj, key.c_str(), - JSON_VALUE_ARRAY); - json_value_t* remove_val = json_object_remove(find, obj); - json_value_destroy(remove_val); json_array_t* arr = json_value_array(v); for (const auto& str : val) json_array_append(arr, JSON_VALUE_STRING, str.c_str()); @@ -599,6 +626,11 @@ Json Json::copy() const void Json::push_back(bool val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; @@ -610,6 +642,11 @@ void Json::push_back(bool val) void Json::push_back(std::nullptr_t val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; @@ -632,6 +669,11 @@ void Json::push_back(const std::vector& val) void Json::push_back(const char* val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; @@ -642,6 +684,11 @@ void Json::push_back(const char* val) void Json::push_back(const Json& val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; diff --git a/tools/templates/config/Json.h b/tools/templates/config/Json.h index 60f2a2b2..f5acb2be 100644 --- a/tools/templates/config/Json.h +++ b/tools/templates/config/Json.h @@ -204,6 +204,11 @@ class Json bool>::type = true> void push_back(const std::string& key, const T& val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -219,6 +224,11 @@ class Json bool>::type = true> void push_back(const std::string& key, const T& val) { + if (is_placeholder()) + { + *this = Json::Object{{key, val}}; + return; + } if (!can_obj_push_back()) { return; @@ -345,6 +355,11 @@ class Json bool>::type = true> void push_back(T val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; @@ -359,6 +374,11 @@ class Json bool>::type = true> void push_back(const T& val) { + if (is_placeholder()) + { + *this = Json::Array{{val}}; + return; + } if (!can_arr_push_back()) { return; @@ -709,9 +729,15 @@ class Json Json(const std::string& str); Json(const char* str); Json(std::nullptr_t null); - Json(double val); - Json(int val); + template ::value, + bool>::type = true> + Json(T val) + : node_(json_value_create(JSON_VALUE_NUMBER, static_cast(val))), + parent_(nullptr), allocated_(true) + { + } Json(bool val); + Json(const std::vector& val); // For parse Json(const std::string& str, bool parse_flag); diff --git a/workflow b/workflow index 273134f0..ba98ed09 160000 --- a/workflow +++ b/workflow @@ -1 +1 @@ -Subproject commit 273134f0ffadbb40a59ce9155a1fde299cd9d68b +Subproject commit ba98ed0945f8888f73350ddfe5d9681306103702