param-validation: add static creation methods to bt_param_validation_value_descr
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 4 Feb 2022 20:43:23 +0000 (15:43 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 16 Feb 2022 19:16:46 +0000 (14:16 -0500)
Replace the various constructors of bt_param_validation_value_descr with
equivalent static methods.

Change-Id: Ia53e05369df9f5f357f1e9eed72d7cfc8c6cb11b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7209
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/common/param-validation/param-validation.h
src/plugins/ctf/fs-sink/fs-sink.cpp
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/lttng-live/lttng-live.cpp

index 0daee1ff9040e0c3498126e153a59d47b7d77df4..e1110faa284931c582b291b77d0afca918520e2e 100644 (file)
@@ -19,7 +19,7 @@ struct bt_param_validation_value_descr;
 
 #if defined(__cplusplus)
 #define BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END \
-       { bt_param_validation_map_value_entry_descr::end }
+       { bt_param_validation_map_value_entry_descr {} }
 #else
 #define BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END { NULL, 0, {} }
 #endif
@@ -53,29 +53,45 @@ typedef enum bt_param_validation_status
 
 struct bt_param_validation_value_descr {
 #if defined(__cplusplus)
-       static struct {} array_t;
-       static struct {} string_t;
-       static struct {} signed_integer_t;
-       static struct {} bool_t;
-
-       bt_param_validation_value_descr(decltype(array_t),
+       static bt_param_validation_value_descr makeArray(
                        uint64_t min_length, uint64_t max_length,
                        const bt_param_validation_value_descr &element_type)
-               : type{BT_VALUE_TYPE_ARRAY}, array{min_length, max_length, &element_type}
-       {}
+       {
+               bt_param_validation_value_descr descr {BT_VALUE_TYPE_ARRAY};
+
+               descr.array.min_length = min_length;
+               descr.array.max_length = max_length;
+               descr.array.element_type = &element_type;
 
-       bt_param_validation_value_descr(decltype(string_t),
+               return descr;
+       }
+
+       static bt_param_validation_value_descr makeString(
                        const char **choices = nullptr)
-               : type{BT_VALUE_TYPE_STRING}, string{choices}
-        {}
+       {
+               bt_param_validation_value_descr descr {BT_VALUE_TYPE_STRING};
 
-       bt_param_validation_value_descr(decltype(signed_integer_t))
-               : type{BT_VALUE_TYPE_SIGNED_INTEGER}
-       {}
+               descr.string.choices = choices;
+
+               return descr;
+       }
 
-       bt_param_validation_value_descr(decltype(bool_t))
-               : type{BT_VALUE_TYPE_BOOL}
+       static bt_param_validation_value_descr makeSignedInteger()
+       {
+               return bt_param_validation_value_descr {BT_VALUE_TYPE_SIGNED_INTEGER};
+       }
+
+       static bt_param_validation_value_descr makeBool()
+       {
+               return bt_param_validation_value_descr {BT_VALUE_TYPE_BOOL};
+       }
+
+private:
+       bt_param_validation_value_descr(bt_value_type type_)
+               : type {type_}
        {}
+
+public:
 #endif
 
        bt_value_type type;
@@ -107,12 +123,14 @@ struct bt_param_validation_value_descr {
 
 struct bt_param_validation_map_value_entry_descr {
 #if defined(__cplusplus)
-       static struct {} end;
-
-       bt_param_validation_map_value_entry_descr(decltype(end))
+       /*
+        * Construct an "end" descriptor, used to denote the end of a descriptor
+        * list.
+        */
+       bt_param_validation_map_value_entry_descr()
                : key{nullptr},
                /* These values are not important. */
-               is_optional{false}, value_descr(bt_param_validation_value_descr::bool_t)
+               is_optional{false}, value_descr(bt_param_validation_value_descr::makeBool())
        {}
 
        bt_param_validation_map_value_entry_descr(const char *key_, bool is_optional_,
index 5f5b2ac5a1663d489da71bce900a5ef2bb94eec1..13264660763c2b8dfe2ccb76fbbd1d1cca5a87b4 100644 (file)
@@ -47,21 +47,16 @@ end:
 }
 
 static bt_param_validation_map_value_entry_descr fs_sink_params_descr[] = {
-    {"path",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
-     {bt_param_validation_value_descr::string_t}},
-    {"assume-single-trace",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::bool_t}},
-    {"ignore-discarded-events",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::bool_t}},
-    {"ignore-discarded-packets",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::bool_t}},
-    {"quiet",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::bool_t}},
+    {"path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
+     bt_param_validation_value_descr::makeString()},
+    {"assume-single-trace", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeBool()},
+    {"ignore-discarded-events", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeBool()},
+    {"ignore-discarded-packets", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeBool()},
+    {"quiet", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeBool()},
     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END};
 
 static bt_component_class_initialize_method_status configure_component(struct fs_sink_comp *fs_sink,
index cd408e34b0c35c931d7296b3a3a29f8eecf90f39..5cdabcadf798e2028cbaf8499ce801c86f68b639 100644 (file)
@@ -2189,26 +2189,21 @@ end:
     return ret;
 }
 
-static const bt_param_validation_value_descr inputs_elem_descr {
-    bt_param_validation_value_descr::string_t};
+static const bt_param_validation_value_descr inputs_elem_descr =
+    bt_param_validation_value_descr::makeString();
 
 static bt_param_validation_map_value_entry_descr fs_params_entries_descr[] = {
-    {"inputs",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
-     {bt_param_validation_value_descr::array_t, 1, BT_PARAM_VALIDATION_INFINITE,
-      inputs_elem_descr}},
-    {"trace-name",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::string_t}},
-    {"clock-class-offset-s",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::signed_integer_t}},
-    {"clock-class-offset-ns",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::signed_integer_t}},
-    {"force-clock-class-origin-unix-epoch",
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::bool_t}},
+    {"inputs", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
+     bt_param_validation_value_descr::makeArray(1, BT_PARAM_VALIDATION_INFINITE,
+                                                inputs_elem_descr)},
+    {"trace-name", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeString()},
+    {"clock-class-offset-s", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeSignedInteger()},
+    {"clock-class-offset-ns", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeSignedInteger()},
+    {"force-clock-class-origin-unix-epoch", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeBool()},
     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END};
 
 bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs,
index 3a882b88070ad574552325650c047152d5f11bce..344fbe27c17441fa88b4b94403f9cc48b3cb2c70 100644 (file)
@@ -1876,9 +1876,8 @@ end:
 }
 
 static struct bt_param_validation_map_value_entry_descr list_sessions_params[] = {
-    {URL_PARAM,
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
-     {bt_param_validation_value_descr::string_t}},
+    {URL_PARAM, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
+     bt_param_validation_value_descr::makeString()},
     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END};
 
 static bt_component_class_query_method_status
@@ -2086,9 +2085,8 @@ parse_session_not_found_action_param(const bt_value *no_session_param)
     return action;
 }
 
-static bt_param_validation_value_descr inputs_elem_descr {
-    bt_param_validation_value_descr::string_t,
-};
+static bt_param_validation_value_descr inputs_elem_descr =
+    bt_param_validation_value_descr::makeString();
 
 static const char *sess_not_found_action_choices[] = {
     SESS_NOT_FOUND_ACTION_CONTINUE_STR,
@@ -2097,12 +2095,10 @@ static const char *sess_not_found_action_choices[] = {
 };
 
 static struct bt_param_validation_map_value_entry_descr params_descr[] = {
-    {INPUTS_PARAM,
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
-     {bt_param_validation_value_descr::array_t, 1, 1, inputs_elem_descr}},
-    {SESS_NOT_FOUND_ACTION_PARAM,
-     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
-     {bt_param_validation_value_descr::string_t, sess_not_found_action_choices}},
+    {INPUTS_PARAM, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY,
+     bt_param_validation_value_descr::makeArray(1, 1, inputs_elem_descr)},
+    {SESS_NOT_FOUND_ACTION_PARAM, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL,
+     bt_param_validation_value_descr::makeString(sess_not_found_action_choices)},
     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END};
 
 static bt_component_class_initialize_method_status
This page took 0.027594 seconds and 4 git commands to generate.