X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fcommon%2Fparam-validation%2Fparam-validation.h;fp=src%2Fplugins%2Fcommon%2Fparam-validation%2Fparam-validation.h;h=0daee1ff9040e0c3498126e153a59d47b7d77df4;hb=087cd0f57f0f7d815a609a4e041d1200f380e4aa;hp=f89ae34971720b971addae5d4204d0f17d0d133d;hpb=516bf0a77e025cfccce2fa400b757e94dc0bf1d8;p=babeltrace.git diff --git a/src/plugins/common/param-validation/param-validation.h b/src/plugins/common/param-validation/param-validation.h index f89ae349..0daee1ff 100644 --- a/src/plugins/common/param-validation/param-validation.h +++ b/src/plugins/common/param-validation/param-validation.h @@ -17,7 +17,12 @@ struct bt_param_validation_context; 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 } +#else #define BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END { NULL, 0, {} } +#endif struct bt_param_validation_map_value_descr { const struct bt_param_validation_map_value_entry_descr *entries; @@ -47,6 +52,32 @@ typedef enum bt_param_validation_status struct bt_param_validation_context *); 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), + 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(decltype(string_t), + const char **choices = nullptr) + : type{BT_VALUE_TYPE_STRING}, string{choices} + {} + + bt_param_validation_value_descr(decltype(signed_integer_t)) + : type{BT_VALUE_TYPE_SIGNED_INTEGER} + {} + + bt_param_validation_value_descr(decltype(bool_t)) + : type{BT_VALUE_TYPE_BOOL} + {} +#endif + bt_value_type type; /* Additional checks dependent on the type. */ @@ -64,26 +95,45 @@ struct bt_param_validation_value_descr { * `bt_param_validation_error` with the provided context * to set the error string. */ - bt_param_validation_func *validation_func; + bt_param_validation_func *validation_func +#if defined(__cplusplus) + = nullptr +#endif + ; }; #define BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL true #define BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY false struct bt_param_validation_map_value_entry_descr { +#if defined(__cplusplus) + static struct {} end; + + bt_param_validation_map_value_entry_descr(decltype(end)) + : key{nullptr}, + /* These values are not important. */ + is_optional{false}, value_descr(bt_param_validation_value_descr::bool_t) + {} + + bt_param_validation_map_value_entry_descr(const char *key_, bool is_optional_, + bt_param_validation_value_descr value_descr_) + : key(key_), is_optional(is_optional_), value_descr(value_descr_) + {} + +#endif + /* If NULL/nullptr, this entry represents the end of the list. */ const char *key; bool is_optional; - const struct bt_param_validation_value_descr value_descr; }; -BT_HIDDEN +BT_EXTERN_C BT_HIDDEN enum bt_param_validation_status bt_param_validation_validate( const bt_value *params, const struct bt_param_validation_map_value_entry_descr *entries, gchar **error); -BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(2, 3) +BT_EXTERN_C BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(2, 3) enum bt_param_validation_status bt_param_validation_error( struct bt_param_validation_context *ctx, const char *format, ...);