tests/lib/conds: make `condMain()` take a span for args
[babeltrace.git] / tests / lib / conds / utils.hpp
index 0fd4fa0adb2de2b96d395d40cb8c3aa20f8cdfda..d8abfafe11ac2ad2c2861146bbd80423c86dd58b 100644 (file)
@@ -4,16 +4,18 @@
  * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
  */
 
-#ifndef TESTS_LIB_CONDS_UTILS_H
-#define TESTS_LIB_CONDS_UTILS_H
+#ifndef TESTS_LIB_CONDS_UTILS_HPP
+#define TESTS_LIB_CONDS_UTILS_HPP
 
 #include <functional>
+#include <memory>
 #include <string>
 #include <utility>
+#include <vector>
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/bt2s/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
 #include "cpp-common/bt2s/span.hpp"
 
 #include "../utils/run-in.hpp"
@@ -28,6 +30,8 @@
 class CondTrigger
 {
 public:
+    using UP = std::unique_ptr<CondTrigger>;
+
     /*
      * Condition type.
      */
@@ -48,7 +52,7 @@ protected:
      * name of the created condition trigger with name().
      */
     explicit CondTrigger(Type type, const std::string& condId,
-                         const bt2s::optional<std::string>& nameSuffix) noexcept;
+                         const bt2c::CStringView nameSuffix) noexcept;
 
 public:
     virtual ~CondTrigger() = default;
@@ -88,7 +92,7 @@ class SimpleCondTrigger : public CondTrigger
 {
 public:
     explicit SimpleCondTrigger(std::function<void()> func, Type type, const std::string& condId,
-                               const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt);
+                               const bt2c::CStringView nameSuffix = {});
 
     void operator()() noexcept override
     {
@@ -111,14 +115,14 @@ class RunInCondTrigger : public CondTrigger
 {
 public:
     explicit RunInCondTrigger(RunInT runIn, const Type type, const std::string& condId,
-                              const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt) :
+                              const bt2c::CStringView nameSuffix = {}) :
         CondTrigger {type, condId, nameSuffix},
         _mRunIn {std::move(runIn)}
     {
     }
 
     explicit RunInCondTrigger(const Type type, const std::string& condId,
-                              const bt2s::optional<std::string>& nameSuffix = bt2s::nullopt) :
+                              const bt2c::CStringView nameSuffix = {}) :
         RunInCondTrigger {RunInT {}, type, condId, nameSuffix}
     {
     }
@@ -135,7 +139,7 @@ private:
 /*
  * List of condition triggers.
  */
-using CondTriggers = bt2s::span<CondTrigger * const>;
+using CondTriggers = std::vector<CondTrigger::UP>;
 
 /*
  * The entry point of a condition trigger program.
@@ -174,6 +178,6 @@ using CondTriggers = bt2s::span<CondTrigger * const>;
  *     The program is expected to abort through a libbabeltrace2
  *     condition failure.
  */
-void condMain(int argc, const char **argv, CondTriggers triggers) noexcept;
+void condMain(const bt2s::span<const char * const> argv, const CondTriggers& triggers) noexcept;
 
-#endif /* TESTS_LIB_CONDS_UTILS_H */
+#endif /* TESTS_LIB_CONDS_UTILS_HPP */
This page took 0.030696 seconds and 4 git commands to generate.