Visibility hidden by default
[babeltrace.git] / src / plugins / common / param-validation / param-validation.h
index 9acfb6fd0f2727b13d3da775d7644a413c01bac5..40d5760998d533d260be87e379a024b429b402b0 100644 (file)
@@ -1,27 +1,10 @@
-#ifndef BABELTRACE_PLUGINS_COMMON_PARAM_VALIDATION_PARAM_VALIDATION_H
-#define BABELTRACE_PLUGINS_COMMON_PARAM_VALIDATION_PARAM_VALIDATION_H
-
 /*
- * Copyright 2019 EfficiOS Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * SPDX-License-Identifier: MIT
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2019 EfficiOS Inc.
  */
+#ifndef BABELTRACE_PLUGINS_COMMON_PARAM_VALIDATION_PARAM_VALIDATION_H
+#define BABELTRACE_PLUGINS_COMMON_PARAM_VALIDATION_PARAM_VALIDATION_H
 
 #include <babeltrace2/babeltrace.h>
 #include <glib.h>
 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 {} }
+#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;
@@ -64,6 +52,48 @@ typedef enum bt_param_validation_status
                        struct bt_param_validation_context *);
 
 struct bt_param_validation_value_descr {
+#if defined(__cplusplus)
+       static bt_param_validation_value_descr makeArray(
+                       uint64_t min_length, uint64_t max_length,
+                       const bt_param_validation_value_descr &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;
+
+               return descr;
+       }
+
+       static bt_param_validation_value_descr makeString(
+                       const char **choices = nullptr)
+       {
+               bt_param_validation_value_descr descr {BT_VALUE_TYPE_STRING};
+
+               descr.string.choices = choices;
+
+               return descr;
+       }
+
+       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;
 
        /* Additional checks dependent on the type. */
@@ -81,26 +111,47 @@ 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)
+       /*
+        * 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::makeBool())
+       {}
+
+       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
 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_ATTR_FORMAT_PRINTF(2, 3)
 enum bt_param_validation_status bt_param_validation_error(
                struct bt_param_validation_context *ctx,
                const char *format, ...);
This page took 0.024919 seconds and 4 git commands to generate.