ctf: compile plugin as C++
[babeltrace.git] / src / plugins / common / param-validation / param-validation.h
index 3113ff4debf6b8e5b78ea3b78822687c9c12d97e..0daee1ff9040e0c3498126e153a59d47b7d77df4 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>
 
 #include <stdio.h> /* For __MINGW_PRINTF_FORMAT. */
 
-#ifdef __MINGW_PRINTF_FORMAT
-# define BT_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
-#else
-# define BT_PRINTF_FORMAT printf
-#endif
+#include <common/macros.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::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;
@@ -68,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. */
@@ -85,25 +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_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);
 
-__attribute__((format(BT_PRINTF_FORMAT, 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, ...);
This page took 0.02566 seconds and 4 git commands to generate.