summaryrefslogtreecommitdiff
path: root/src/utils/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/cpp')
-rw-r--r--src/utils/cpp/TARGETS17
-rw-r--r--src/utils/cpp/file_locking.hpp2
-rw-r--r--src/utils/cpp/gsl.hpp33
-rw-r--r--src/utils/cpp/hash_combine.hpp2
-rw-r--r--src/utils/cpp/json.hpp11
-rw-r--r--src/utils/cpp/tmp_dir.cpp2
-rw-r--r--src/utils/cpp/type_safe_arithmetic.hpp6
7 files changed, 57 insertions, 16 deletions
diff --git a/src/utils/cpp/TARGETS b/src/utils/cpp/TARGETS
index 42d8ae9e..fffb2e7b 100644
--- a/src/utils/cpp/TARGETS
+++ b/src/utils/cpp/TARGETS
@@ -2,21 +2,21 @@
{ "type": ["@", "rules", "CC", "library"]
, "name": ["hash_combine"]
, "hdrs": ["hash_combine.hpp"]
- , "deps": [["@", "gsl-lite", "", "gsl-lite"]]
+ , "deps": [["@", "gsl", "", "gsl"]]
, "stage": ["src", "utils", "cpp"]
}
, "type_safe_arithmetic":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["type_safe_arithmetic"]
, "hdrs": ["type_safe_arithmetic.hpp"]
- , "deps": [["@", "gsl-lite", "", "gsl-lite"]]
+ , "deps": [["@", "gsl", "", "gsl"]]
, "stage": ["src", "utils", "cpp"]
}
, "json":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["json"]
, "hdrs": ["json.hpp"]
- , "deps": [["@", "json", "", "json"], ["@", "gsl-lite", "", "gsl-lite"]]
+ , "deps": ["gsl", ["@", "json", "", "json"], ["@", "gsl", "", "gsl"]]
, "stage": ["src", "utils", "cpp"]
}
, "concepts":
@@ -54,7 +54,7 @@
, "name": ["tmp_dir"]
, "hdrs": ["tmp_dir.hpp"]
, "srcs": ["tmp_dir.cpp"]
- , "deps": [["@", "gsl-lite", "", "gsl-lite"]]
+ , "deps": [["@", "gsl", "", "gsl"]]
, "stage": ["src", "utils", "cpp"]
, "private-deps": [["src/buildtool/file_system", "file_system_manager"]]
}
@@ -63,11 +63,18 @@
, "name": ["file_locking"]
, "hdrs": ["file_locking.hpp"]
, "srcs": ["file_locking.cpp"]
- , "deps": [["@", "gsl-lite", "", "gsl-lite"]]
+ , "deps": [["@", "gsl", "", "gsl"]]
, "stage": ["src", "utils", "cpp"]
, "private-deps":
[ ["src/buildtool/file_system", "file_system_manager"]
, ["src/utils/cpp", "path"]
]
}
+, "gsl":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["gsl"]
+ , "hdrs": ["gsl.hpp"]
+ , "deps": [["@", "gsl", "", "gsl"]]
+ , "stage": ["src", "utils", "cpp"]
+ }
}
diff --git a/src/utils/cpp/file_locking.hpp b/src/utils/cpp/file_locking.hpp
index c9635d69..24aeb90b 100644
--- a/src/utils/cpp/file_locking.hpp
+++ b/src/utils/cpp/file_locking.hpp
@@ -19,7 +19,7 @@
#include <memory>
#include <optional>
-#include "gsl-lite/gsl-lite.hpp"
+#include "gsl/gsl"
/* \brief Thread- and process-safe file locking mechanism for paths.
* User guarantees write access in the parent directory of the path given, as
diff --git a/src/utils/cpp/gsl.hpp b/src/utils/cpp/gsl.hpp
new file mode 100644
index 00000000..882df29b
--- /dev/null
+++ b/src/utils/cpp/gsl.hpp
@@ -0,0 +1,33 @@
+// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_UTILS_CPP_GSL_HPP
+#define INCLUDED_SRC_UTILS_CPP_GSL_HPP
+
+#include <gsl/gsl>
+
+// implement EnsuresAudit/ExpectsAudit (from gsl-lite) only run in debug mode
+#ifdef NDEBUG
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ExpectsAudit(x) (void)0
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define EnsuresAudit(x) (void)0
+#else
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define ExpectsAudit(x) Expects(x)
+// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
+#define EnsuresAudit(x) Ensures(x)
+#endif
+
+#endif // INCLUDED_SRC_UTILS_CPP_GSL_HPP_
diff --git a/src/utils/cpp/hash_combine.hpp b/src/utils/cpp/hash_combine.hpp
index 68c01c57..6660815d 100644
--- a/src/utils/cpp/hash_combine.hpp
+++ b/src/utils/cpp/hash_combine.hpp
@@ -15,7 +15,7 @@
#ifndef INCLUDED_SRC_UTILS_CPP_HASH_COMBINE_HPP
#define INCLUDED_SRC_UTILS_CPP_HASH_COMBINE_HPP
-#include "gsl-lite/gsl-lite.hpp"
+#include "gsl/gsl"
// Taken from Boost, as hash_combine did not yet make it to STL.
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0814r0.pdf
diff --git a/src/utils/cpp/json.hpp b/src/utils/cpp/json.hpp
index 4921a39b..aed2f3f4 100644
--- a/src/utils/cpp/json.hpp
+++ b/src/utils/cpp/json.hpp
@@ -21,8 +21,9 @@
#include <string>
#include <unordered_map>
-#include "gsl-lite/gsl-lite.hpp"
+#include "gsl/gsl"
#include "nlohmann/json.hpp"
+#include "src/utils/cpp/gsl.hpp"
template <typename ValueT>
auto ExtractValueAs(
@@ -65,7 +66,7 @@ namespace detail {
}
std::fill_n(iterator{oss}, depth, indent);
oss << '}';
- gsl_EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
+ EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
return oss.str();
}
if (json.is_array() and depth < until) {
@@ -79,7 +80,7 @@ namespace detail {
}
std::fill_n(iterator{oss}, depth, indent);
oss << ']';
- gsl_EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
+ EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
return oss.str();
}
return json.dump();
@@ -116,7 +117,7 @@ namespace detail {
}
std::fill_n(iterator{oss}, depth, indent);
oss << '}';
- gsl_EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
+ EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
return oss.str();
}
if (json.is_array() and depth < until) {
@@ -131,7 +132,7 @@ namespace detail {
}
std::fill_n(iterator{oss}, depth, indent);
oss << ']';
- gsl_EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
+ EnsuresAudit(nlohmann::json::parse(oss.str()) == json);
return oss.str();
}
return json.dump();
diff --git a/src/utils/cpp/tmp_dir.cpp b/src/utils/cpp/tmp_dir.cpp
index d821558f..b0cc4905 100644
--- a/src/utils/cpp/tmp_dir.cpp
+++ b/src/utils/cpp/tmp_dir.cpp
@@ -14,7 +14,7 @@
#include "src/utils/cpp/tmp_dir.hpp"
-#include "gsl-lite/gsl-lite.hpp"
+#include "gsl/gsl"
#include "src/buildtool/file_system/file_system_manager.hpp"
auto TmpDir::Create(std::filesystem::path const& prefix,
diff --git a/src/utils/cpp/type_safe_arithmetic.hpp b/src/utils/cpp/type_safe_arithmetic.hpp
index 878631cb..090c266b 100644
--- a/src/utils/cpp/type_safe_arithmetic.hpp
+++ b/src/utils/cpp/type_safe_arithmetic.hpp
@@ -18,7 +18,7 @@
#include <limits>
#include <type_traits>
-#include "gsl-lite/gsl-lite.hpp"
+#include "gsl/gsl"
/// \struct type_safe_arithmetic_tag
/// \brief Abstract tag defining types and limits for custom arithmetic types.
@@ -87,8 +87,8 @@ class type_safe_arithmetic {
constexpr auto get() const -> value_t { return m_value; }
constexpr void set(value_t value) {
- gsl_Expects(value >= min_value && value <= max_value &&
- "value output of range");
+ Expects(value >= min_value && value <= max_value &&
+ "value output of range");
m_value = value;
}