cpp-common/bt2/component-port.hpp \
cpp-common/bt2/exc.hpp \
cpp-common/bt2/field-class.hpp \
- cpp-common/bt2/field.hpp \
cpp-common/bt2/field-path.hpp \
- cpp-common/bt2/integer-range.hpp \
+ cpp-common/bt2/field.hpp \
cpp-common/bt2/integer-range-set.hpp \
+ cpp-common/bt2/integer-range.hpp \
cpp-common/bt2/internal/utils.hpp \
cpp-common/bt2/logging.hpp \
cpp-common/bt2/message-array.hpp \
cpp-common/bt2/self-component-port.hpp \
cpp-common/bt2/self-message-iterator-configuration.hpp \
cpp-common/bt2/self-message-iterator.hpp \
+ cpp-common/bt2/shared-object.hpp \
cpp-common/bt2/trace-ir.hpp \
cpp-common/bt2/type-traits.hpp \
cpp-common/bt2/value.hpp \
cpp-common/bt2/wrap.hpp \
- cpp-common/align.hpp \
- cpp-common/endian.hpp \
- cpp-common/exc.hpp \
- cpp-common/glib-up.hpp \
- cpp-common/libc-up.hpp \
- cpp-common/lib-str.hpp \
- cpp-common/make-unique.hpp \
+ cpp-common/bt2c/align.hpp \
+ cpp-common/bt2c/endian.hpp \
+ cpp-common/bt2c/exc.hpp \
+ cpp-common/bt2c/glib-up.hpp \
+ cpp-common/bt2c/lib-str.hpp \
+ cpp-common/bt2c/libc-up.hpp \
+ cpp-common/bt2c/make-unique.hpp \
+ cpp-common/bt2c/read-fixed-len-int.hpp \
+ cpp-common/bt2c/safe-ops.hpp \
+ cpp-common/bt2c/std-int.hpp \
+ cpp-common/bt2c/uuid-view.hpp \
+ cpp-common/bt2c/uuid.hpp \
+ cpp-common/bt2c/vector.hpp \
cpp-common/nlohmann/json.hpp \
cpp-common/optional.hpp \
- cpp-common/read-fixed-len-int.hpp \
- cpp-common/safe-ops.hpp \
- cpp-common/std-int.hpp \
- cpp-common/string_view.hpp \
- cpp-common/uuid.hpp \
- cpp-common/uuid-view.hpp \
- cpp-common/vector.hpp
+ cpp-common/string_view.hpp
## This target generates an include file that contains the git version
## string of the current branch, it must be continuously updated when
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_ALIGN_HPP
-#define BABELTRACE_CPP_COMMON_ALIGN_HPP
-
-#include <type_traits>
-
-#include "common/align.h"
-
-namespace bt2_common {
-
-template <typename ValT, typename AlignT>
-ValT align(const ValT val, const AlignT align) noexcept
-{
- static_assert(std::is_unsigned<ValT>::value, "`ValT` is unsigned.");
- return BT_ALIGN(val, static_cast<ValT>(align));
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_ALIGN_HPP */
#include <babeltrace2/babeltrace.h>
+#include "cpp-common/bt2c/uuid-view.hpp"
#include "cpp-common/optional.hpp"
-#include "cpp-common/uuid-view.hpp"
#include "borrowed-object.hpp"
#include "exc.hpp"
bt_clock_class_set_uuid(this->libObjPtr(), uuid);
}
- nonstd::optional<bt2_common::UuidView> uuid() const noexcept
+ nonstd::optional<bt2c::UuidView> uuid() const noexcept
{
const auto uuid = bt_clock_class_get_uuid(this->libObjPtr());
if (uuid) {
- return bt2_common::UuidView {uuid};
+ return bt2c::UuidView {uuid};
}
return nonstd::nullopt;
#ifndef BABELTRACE_CPP_COMMON_BT2_EXC_HPP
#define BABELTRACE_CPP_COMMON_BT2_EXC_HPP
-#include "cpp-common/exc.hpp"
+#include "cpp-common/bt2c/exc.hpp"
namespace bt2 {
-using Error = bt2_common::Error;
-using OverflowError = bt2_common::OverflowError;
-using MemoryError = bt2_common::MemoryError;
-using TryAgain = bt2_common::TryAgain;
+using Error = bt2c::Error;
+using OverflowError = bt2c::OverflowError;
+using MemoryError = bt2c::MemoryError;
+using TryAgain = bt2c::TryAgain;
} /* namespace bt2 */
return bt_trace_get_name(this->libObjPtr());
}
- void uuid(const bt2_common::UuidView& uuid) const noexcept
+ void uuid(const bt2c::UuidView& uuid) const noexcept
{
bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
}
- nonstd::optional<bt2_common::UuidView> uuid() const noexcept
+ nonstd::optional<bt2c::UuidView> uuid() const noexcept
{
const auto uuid = bt_trace_get_uuid(this->libObjPtr());
if (uuid) {
- return bt2_common::UuidView {uuid};
+ return bt2c::UuidView {uuid};
}
return nonstd::nullopt;
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_ALIGN_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_ALIGN_HPP
+
+#include <type_traits>
+
+#include "common/align.h"
+
+namespace bt2c {
+
+template <typename ValT, typename AlignT>
+ValT align(const ValT val, const AlignT align) noexcept
+{
+ static_assert(std::is_unsigned<ValT>::value, "`ValT` is unsigned.");
+ return BT_ALIGN(val, static_cast<ValT>(align));
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_ALIGN_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_ENDIAN_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_ENDIAN_HPP
+
+#include <cstdint>
+
+#include "compat/endian.h" /* IWYU pragma: keep */
+
+namespace bt2c {
+
+static inline std::uint8_t littleEndianToNative(const std::uint8_t val) noexcept
+{
+ return val;
+}
+
+static inline std::uint8_t bigEndianToNative(const std::uint8_t val) noexcept
+{
+ return val;
+}
+
+static inline std::int8_t littleEndianToNative(const std::int8_t val) noexcept
+{
+ return val;
+}
+
+static inline std::int8_t bigEndianToNative(const std::int8_t val) noexcept
+{
+ return val;
+}
+
+static inline std::uint16_t littleEndianToNative(const std::uint16_t val) noexcept
+{
+ return static_cast<std::uint16_t>(le16toh(val));
+}
+
+static inline std::uint16_t bigEndianToNative(const std::uint16_t val) noexcept
+{
+ return static_cast<std::uint16_t>(be16toh(val));
+}
+
+static inline std::int16_t littleEndianToNative(const std::int16_t val) noexcept
+{
+ return static_cast<std::int16_t>(littleEndianToNative(static_cast<std::uint16_t>(val)));
+}
+
+static inline std::int16_t bigEndianToNative(const std::int16_t val) noexcept
+{
+ return static_cast<std::int16_t>(bigEndianToNative(static_cast<std::uint16_t>(val)));
+}
+
+static inline std::uint32_t littleEndianToNative(const std::uint32_t val) noexcept
+{
+ return static_cast<std::uint32_t>(le32toh(val));
+}
+
+static inline std::uint32_t bigEndianToNative(const std::uint32_t val) noexcept
+{
+ return static_cast<std::uint32_t>(be32toh(val));
+}
+
+static inline std::int32_t littleEndianToNative(const std::int32_t val) noexcept
+{
+ return static_cast<std::int32_t>(littleEndianToNative(static_cast<std::uint32_t>(val)));
+}
+
+static inline std::int32_t bigEndianToNative(const std::int32_t val) noexcept
+{
+ return static_cast<std::int32_t>(bigEndianToNative(static_cast<std::uint32_t>(val)));
+}
+
+static inline std::uint64_t littleEndianToNative(const std::uint64_t val) noexcept
+{
+ return static_cast<std::uint64_t>(le64toh(val));
+}
+
+static inline std::uint64_t bigEndianToNative(const std::uint64_t val) noexcept
+{
+ return static_cast<std::uint64_t>(be64toh(val));
+}
+
+static inline std::int64_t littleEndianToNative(const std::int64_t val) noexcept
+{
+ return static_cast<std::int64_t>(littleEndianToNative(static_cast<std::uint64_t>(val)));
+}
+
+static inline std::int64_t bigEndianToNative(const std::int64_t val) noexcept
+{
+ return static_cast<std::int64_t>(bigEndianToNative(static_cast<std::uint64_t>(val)));
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_ENDIAN_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_EXC_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_EXC_HPP
+
+#include <exception>
+#include <new>
+#include <stdexcept>
+#include <string>
+
+namespace bt2c {
+
+/*
+ * End of iteration.
+ */
+class End : public std::exception
+{
+public:
+ explicit End() noexcept : std::exception {}
+ {
+ }
+};
+
+/*
+ * General error.
+ */
+class Error : public std::runtime_error
+{
+public:
+ explicit Error(std::string msg = "Error") : std::runtime_error {std::move(msg)}
+ {
+ }
+};
+
+/*
+ * Overflow error.
+ */
+class OverflowError : public Error
+{
+public:
+ explicit OverflowError() noexcept : Error {"Overflow error"}
+ {
+ }
+};
+
+/*
+ * Memory error.
+ */
+class MemoryError : public std::bad_alloc
+{
+public:
+ explicit MemoryError() noexcept : std::bad_alloc {}
+ {
+ }
+};
+
+/*
+ * Not available right now: try again later.
+ */
+class TryAgain : public std::exception
+{
+public:
+ explicit TryAgain() noexcept : std::exception {}
+ {
+ }
+};
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_EXC_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 EfficiOS, inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_GLIB_UP_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_GLIB_UP_HPP
+
+#include <memory>
+
+#include <glib.h>
+
+namespace bt2c {
+namespace internal {
+
+struct GCharDeleter final
+{
+ void operator()(gchar * const p) noexcept
+ {
+ g_free(p);
+ }
+};
+
+} /* namespace internal */
+
+using GCharUP = std::unique_ptr<gchar, internal::GCharDeleter>;
+
+namespace internal {
+
+struct GStringDeleter final
+{
+ void operator()(GString * const str)
+ {
+ g_string_free(str, TRUE);
+ }
+};
+
+} /* namespace internal */
+
+using GStringUP = std::unique_ptr<GString, internal::GStringDeleter>;
+
+namespace internal {
+
+struct GDirDeleter final
+{
+ void operator()(GDir * const dir)
+ {
+ g_dir_close(dir);
+ }
+};
+
+} /* namespace internal */
+
+using GDirUP = std::unique_ptr<GDir, internal::GDirDeleter>;
+
+namespace internal {
+
+struct GMappedFileDeleter final
+{
+ void operator()(GMappedFile * const f)
+ {
+ g_mapped_file_unref(f);
+ }
+};
+
+} /* namespace internal */
+
+using GMappedFileUP = std::unique_ptr<GMappedFile, internal::GMappedFileDeleter>;
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_GLIB_UP_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 EfficiOS, Inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_LIB_STR_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_LIB_STR_HPP
+
+#include "cpp-common/bt2/message.hpp"
+
+namespace bt2c {
+
+static inline const char *messageTypeStr(const bt2::MessageType type)
+{
+ return bt_common_message_type_string(static_cast<bt_message_type>(type));
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_LIB_STR_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 EfficiOS, inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_LIBC_UP_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_LIBC_UP_HPP
+
+#include <cstdio>
+#include <memory>
+
+namespace bt2c {
+namespace internal {
+
+struct FileCloserDeleter
+{
+ void operator()(std::FILE * const f) noexcept
+ {
+ std::fclose(f);
+ }
+};
+
+} /* namespace internal */
+
+using FileUP = std::unique_ptr<std::FILE, internal::FileCloserDeleter>;
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_LIBC_UP_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP
+
+#include <memory>
+#include <type_traits>
+#include <utility>
+
+namespace bt2c {
+
+/*
+ * Our implementation of std::make_unique<>() for C++11.
+ */
+template <typename T, typename... ArgTs>
+std::unique_ptr<T> makeUnique(ArgTs&&...args)
+{
+ static_assert(!std::is_array<T>::value, "`T` is not an array (unsupported).");
+
+ return std::unique_ptr<T>(new T {std::forward<ArgTs>(args)...});
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_MAKE_UNIQUE_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_READ_FIXED_LEN_INT_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_READ_FIXED_LEN_INT_HPP
+
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
+
+#include "endian.hpp"
+
+namespace bt2c {
+
+/*
+ * Reads a fixed-length integer of unknown byte order into a value of integral
+ * type `IntT` from the buffer `buf` and returns it.
+ */
+template <typename IntT>
+IntT readFixedLenInt(const std::uint8_t * const buf)
+{
+ static_assert(std::is_integral<IntT>::value, "`IntT` is an integral type.");
+
+ IntT val;
+
+ std::memcpy(&val, buf, sizeof(val));
+ return val;
+}
+
+/*
+ * Reads a fixed-length little-endian integer into a value of integral
+ * type `IntT` from the buffer `buf` and returns it.
+ */
+template <typename IntT>
+IntT readFixedLenIntLe(const std::uint8_t * const buf)
+{
+ return bt2c::littleEndianToNative(readFixedLenInt<IntT>(buf));
+}
+
+/*
+ * Reads a fixed-length big-endian integer into a value of integral
+ * type `IntT` from the buffer `buf` and returns it.
+ */
+template <typename IntT>
+IntT readFixedLenIntBe(const std::uint8_t * const buf)
+{
+ return bt2c::bigEndianToNative(readFixedLenInt<IntT>(buf));
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_READ_FIXED_LEN_INT_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_SAFE_OPS_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_SAFE_OPS_HPP
+
+#include <limits>
+#include <type_traits>
+
+#include "common/assert.h"
+
+namespace bt2c {
+
+template <typename T>
+constexpr bool safeToMul(const T a, const T b)
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ return a == 0 || b == 0 || a < std::numeric_limits<T>::max() / b;
+}
+
+template <typename T>
+T safeMul(const T a, const T b) noexcept
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ BT_ASSERT_DBG(safeToMul(a, b));
+ return a * b;
+}
+
+template <typename T>
+constexpr bool safeToAdd(const T a, const T b)
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ return a <= std::numeric_limits<T>::max() - b;
+}
+
+template <typename T>
+T safeAdd(const T a, const T b) noexcept
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ BT_ASSERT_DBG(safeToAdd(a, b));
+ return a + b;
+}
+
+template <typename T>
+constexpr bool safeToSub(const T a, const T b)
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ return a >= b;
+}
+
+template <typename T>
+T safeSub(const T a, const T b) noexcept
+{
+ static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
+
+ BT_ASSERT_DBG(safeToSub(a, b));
+ return a - b;
+}
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_SAFE_OPS_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
+
+#include <cstdint>
+
+namespace bt2c {
+namespace internal {
+
+template <std::size_t LenBitsV, bool IsSignedV>
+struct StdIntTBase;
+
+template <>
+struct StdIntTBase<8, true>
+{
+ using Type = std::int8_t;
+};
+
+template <>
+struct StdIntTBase<8, false>
+{
+ using Type = std::uint8_t;
+};
+
+template <>
+struct StdIntTBase<16, true>
+{
+ using Type = std::int16_t;
+};
+
+template <>
+struct StdIntTBase<16, false>
+{
+ using Type = std::uint16_t;
+};
+
+template <>
+struct StdIntTBase<32, true>
+{
+ using Type = std::int32_t;
+};
+
+template <>
+struct StdIntTBase<32, false>
+{
+ using Type = std::uint32_t;
+};
+
+template <>
+struct StdIntTBase<64, true>
+{
+ using Type = std::int64_t;
+};
+
+template <>
+struct StdIntTBase<64, false>
+{
+ using Type = std::uint64_t;
+};
+
+} /* namespace internal */
+
+/*
+ * Standard fixed-length integer type `Type` of length `LenBitsV` bits
+ * and signedness `IsSignedV`.
+ *
+ * `LenBitsV` must be one of 8, 16, 32, or 64.
+ *
+ * For example, `StdIntT<32, true>` is `std::int32_t`.
+ */
+template <std::size_t LenBitsV, bool IsSignedV>
+using StdIntT = typename internal::StdIntTBase<LenBitsV, IsSignedV>::Type;
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2016-2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "uuid-view.hpp"
+#include "uuid.hpp"
+
+namespace bt2c {
+
+UuidView::UuidView(const Uuid& uuid) noexcept : _mUuid {uuid.data()}
+{
+}
+
+UuidView::operator Uuid() const noexcept
+{
+ return Uuid {*this};
+}
+
+} /* namespace bt2c */
--- /dev/null
+/*
+ * SPDX-FileCopyrightText: 2020 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP
+
+#include <algorithm>
+#include <cstdint>
+#include <string>
+
+#include "common/assert.h"
+#include "common/uuid.h"
+
+namespace bt2c {
+
+class Uuid;
+
+/*
+ * A view on existing UUID data.
+ *
+ * A `UuidView` object doesn't contain its UUID data: see `Uuid` for a
+ * UUID data container.
+ */
+class UuidView final
+{
+public:
+ using Val = std::uint8_t;
+ using ConstIter = const Val *;
+
+public:
+ explicit UuidView(const Val * const uuid) noexcept : _mUuid {uuid}
+ {
+ BT_ASSERT_DBG(uuid);
+ }
+
+ explicit UuidView(const Uuid& uuid) noexcept;
+ UuidView(const UuidView&) noexcept = default;
+ UuidView& operator=(const UuidView&) noexcept = default;
+
+ UuidView& operator=(const Val * const uuid) noexcept
+ {
+ _mUuid = uuid;
+ return *this;
+ }
+
+ operator Uuid() const noexcept;
+
+ std::string str() const
+ {
+ std::string s;
+
+ s.resize(BT_UUID_STR_LEN);
+ bt_uuid_to_str(_mUuid, &s[0]);
+
+ return s;
+ }
+
+ bool operator==(const UuidView& other) const noexcept
+ {
+ return bt_uuid_compare(_mUuid, other._mUuid) == 0;
+ }
+
+ bool operator!=(const UuidView& other) const noexcept
+ {
+ return !(*this == other);
+ }
+
+ bool operator<(const UuidView& other) const noexcept
+ {
+ return bt_uuid_compare(_mUuid, other._mUuid) < 0;
+ }
+
+ static constexpr std::size_t size() noexcept
+ {
+ return BT_UUID_LEN;
+ }
+
+ const Val *data() const noexcept
+ {
+ return _mUuid;
+ }
+
+ Val operator[](const std::size_t index) const noexcept
+ {
+ return _mUuid[index];
+ }
+
+ ConstIter begin() const noexcept
+ {
+ return _mUuid;
+ }
+
+ ConstIter end() const noexcept
+ {
+ return _mUuid + this->size();
+ }
+
+ bool isNil() const noexcept
+ {
+ return std::all_of(this->begin(), this->end(), [](const std::uint8_t byte) {
+ return byte == 0;
+ });
+ }
+
+private:
+ const Val *_mUuid;
+};
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_UUID_VIEW_HPP */
--- /dev/null
+/*
+ * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_UUID_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_UUID_HPP
+
+#include <algorithm>
+#include <array>
+#include <string>
+
+#include "common/assert.h"
+#include "common/uuid.h"
+
+#include "uuid-view.hpp"
+
+namespace bt2c {
+
+/*
+ * A universally unique identifier.
+ *
+ * A `Uuid` object contains its UUID data: see `UuidView` to have a
+ * UUID view on existing UUID data.
+ */
+class Uuid final
+{
+public:
+ using Val = UuidView::Val;
+ using ConstIter = UuidView::ConstIter;
+
+public:
+ /*
+ * Builds a nil UUID.
+ */
+ explicit Uuid() noexcept = default;
+
+ explicit Uuid(const Val * const uuid) noexcept
+ {
+ this->_setFromPtr(uuid);
+ }
+
+ explicit Uuid(const char * const str) noexcept
+ {
+ const auto ret = bt_uuid_from_str(str, _mUuid.data());
+ BT_ASSERT(ret == 0);
+ }
+
+ explicit Uuid(const std::string& str) noexcept : Uuid {str.c_str()}
+ {
+ }
+
+ explicit Uuid(const UuidView& view) noexcept : Uuid {view.data()}
+ {
+ }
+
+ Uuid(const Uuid&) noexcept = default;
+ Uuid& operator=(const Uuid&) noexcept = default;
+
+ Uuid& operator=(const Val * const uuid) noexcept
+ {
+ this->_setFromPtr(uuid);
+ return *this;
+ }
+
+ static Uuid generate() noexcept
+ {
+ bt_uuid_t uuidGen;
+
+ bt_uuid_generate(uuidGen);
+ return Uuid {uuidGen};
+ }
+
+ std::string str() const
+ {
+ return this->_view().str();
+ }
+
+ bool operator==(const Uuid& other) const noexcept
+ {
+ return this->_view() == other._view();
+ }
+
+ bool operator!=(const Uuid& other) const noexcept
+ {
+ return this->_view() != other._view();
+ }
+
+ bool operator<(const Uuid& other) const noexcept
+ {
+ return this->_view() < other._view();
+ }
+
+ /*
+ * The returned UUID view must not outlive the UUID object.
+ */
+ operator UuidView() const noexcept
+ {
+ return this->_view();
+ }
+
+ static constexpr std::size_t size() noexcept
+ {
+ return UuidView::size();
+ }
+
+ const Val *data() const noexcept
+ {
+ return _mUuid.data();
+ }
+
+ Val operator[](const std::size_t index) const noexcept
+ {
+ return this->_view()[index];
+ }
+
+ ConstIter begin() const noexcept
+ {
+ return this->_view().begin();
+ }
+
+ ConstIter end() const noexcept
+ {
+ return this->_view().end();
+ }
+
+ bool isNil() const noexcept
+ {
+ return this->_view().isNil();
+ }
+
+private:
+ /*
+ * std::copy_n() won't throw when simply copying bytes below,
+ * therefore this method won't throw.
+ */
+ void _setFromPtr(const Val * const uuid) noexcept
+ {
+ BT_ASSERT(uuid);
+ std::copy_n(uuid, BT_UUID_LEN, std::begin(_mUuid));
+ }
+
+ UuidView _view() const noexcept
+ {
+ return UuidView {_mUuid.data()};
+ }
+
+ std::array<Val, UuidView::size()> _mUuid = {};
+};
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_UUID_HPP */
--- /dev/null
+/*
+ * SPDX-FileCopyrightText: 2022 Simon Marchi <simon.marchi@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef SRC_CPP_COMMON_VECTOR_HPP
+#define SRC_CPP_COMMON_VECTOR_HPP
+
+#include <vector>
+
+#include "common/assert.h"
+
+namespace bt2c {
+
+/*
+ * Moves the last entry of `vec` to the index `idx`, then removes the last entry.
+ *
+ * Meant to be a direct replacement for g_ptr_array_remove_index_fast(), but for
+ * `std::vector`.
+ */
+template <typename T, typename AllocatorT>
+void vectorFastRemove(std::vector<T, AllocatorT>& vec,
+ const typename std::vector<T, AllocatorT>::size_type idx)
+{
+ BT_ASSERT_DBG(idx < vec.size());
+
+ if (idx < vec.size() - 1) {
+ vec[idx] = std::move(vec.back());
+ }
+
+ vec.pop_back();
+}
+
+} /* namespace bt2c */
+
+#endif /* SRC_CPP_COMMON_VECTOR_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_ENDIAN_HPP
-#define BABELTRACE_CPP_COMMON_ENDIAN_HPP
-
-#include <cstdint>
-
-#include "compat/endian.h" /* IWYU pragma: keep */
-
-namespace bt2_common {
-
-static inline std::uint8_t littleEndianToNative(const std::uint8_t val) noexcept
-{
- return val;
-}
-
-static inline std::uint8_t bigEndianToNative(const std::uint8_t val) noexcept
-{
- return val;
-}
-
-static inline std::int8_t littleEndianToNative(const std::int8_t val) noexcept
-{
- return val;
-}
-
-static inline std::int8_t bigEndianToNative(const std::int8_t val) noexcept
-{
- return val;
-}
-
-static inline std::uint16_t littleEndianToNative(const std::uint16_t val) noexcept
-{
- return static_cast<std::uint16_t>(le16toh(val));
-}
-
-static inline std::uint16_t bigEndianToNative(const std::uint16_t val) noexcept
-{
- return static_cast<std::uint16_t>(be16toh(val));
-}
-
-static inline std::int16_t littleEndianToNative(const std::int16_t val) noexcept
-{
- return static_cast<std::int16_t>(littleEndianToNative(static_cast<std::uint16_t>(val)));
-}
-
-static inline std::int16_t bigEndianToNative(const std::int16_t val) noexcept
-{
- return static_cast<std::int16_t>(bigEndianToNative(static_cast<std::uint16_t>(val)));
-}
-
-static inline std::uint32_t littleEndianToNative(const std::uint32_t val) noexcept
-{
- return static_cast<std::uint32_t>(le32toh(val));
-}
-
-static inline std::uint32_t bigEndianToNative(const std::uint32_t val) noexcept
-{
- return static_cast<std::uint32_t>(be32toh(val));
-}
-
-static inline std::int32_t littleEndianToNative(const std::int32_t val) noexcept
-{
- return static_cast<std::int32_t>(littleEndianToNative(static_cast<std::uint32_t>(val)));
-}
-
-static inline std::int32_t bigEndianToNative(const std::int32_t val) noexcept
-{
- return static_cast<std::int32_t>(bigEndianToNative(static_cast<std::uint32_t>(val)));
-}
-
-static inline std::uint64_t littleEndianToNative(const std::uint64_t val) noexcept
-{
- return static_cast<std::uint64_t>(le64toh(val));
-}
-
-static inline std::uint64_t bigEndianToNative(const std::uint64_t val) noexcept
-{
- return static_cast<std::uint64_t>(be64toh(val));
-}
-
-static inline std::int64_t littleEndianToNative(const std::int64_t val) noexcept
-{
- return static_cast<std::int64_t>(littleEndianToNative(static_cast<std::uint64_t>(val)));
-}
-
-static inline std::int64_t bigEndianToNative(const std::int64_t val) noexcept
-{
- return static_cast<std::int64_t>(bigEndianToNative(static_cast<std::uint64_t>(val)));
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_ENDIAN_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_EXC_HPP
-#define BABELTRACE_CPP_COMMON_EXC_HPP
-
-#include <exception>
-#include <new>
-#include <stdexcept>
-#include <string>
-
-namespace bt2_common {
-
-/*
- * End of iteration.
- */
-class End : public std::exception
-{
-public:
- explicit End() noexcept : std::exception {}
- {
- }
-};
-
-/*
- * General error.
- */
-class Error : public std::runtime_error
-{
-public:
- explicit Error(std::string msg = "Error") : std::runtime_error {std::move(msg)}
- {
- }
-};
-
-/*
- * Overflow error.
- */
-class OverflowError : public Error
-{
-public:
- explicit OverflowError() noexcept : Error {"Overflow error"}
- {
- }
-};
-
-/*
- * Memory error.
- */
-class MemoryError : public std::bad_alloc
-{
-public:
- explicit MemoryError() noexcept : std::bad_alloc {}
- {
- }
-};
-
-/*
- * Not available right now: try again later.
- */
-class TryAgain : public std::exception
-{
-public:
- explicit TryAgain() noexcept : std::exception {}
- {
- }
-};
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_EXC_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 EfficiOS, inc.
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_GLIB_UP_HPP
-#define BABELTRACE_CPP_COMMON_GLIB_UP_HPP
-
-#include <memory>
-
-#include <glib.h>
-
-namespace bt2_common {
-namespace internal {
-
-struct GCharDeleter final
-{
- void operator()(gchar * const p) noexcept
- {
- g_free(p);
- }
-};
-
-} /* namespace internal */
-
-using GCharUP = std::unique_ptr<gchar, internal::GCharDeleter>;
-
-namespace internal {
-
-struct GStringDeleter final
-{
- void operator()(GString * const str)
- {
- g_string_free(str, TRUE);
- }
-};
-
-} /* namespace internal */
-
-using GStringUP = std::unique_ptr<GString, internal::GStringDeleter>;
-
-namespace internal {
-
-struct GDirDeleter final
-{
- void operator()(GDir * const dir)
- {
- g_dir_close(dir);
- }
-};
-
-} /* namespace internal */
-
-using GDirUP = std::unique_ptr<GDir, internal::GDirDeleter>;
-
-namespace internal {
-
-struct GMappedFileDeleter final
-{
- void operator()(GMappedFile * const f)
- {
- g_mapped_file_unref(f);
- }
-};
-
-} /* namespace internal */
-
-using GMappedFileUP = std::unique_ptr<GMappedFile, internal::GMappedFileDeleter>;
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_GLIB_UP_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 EfficiOS, Inc.
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_LIB_STR_HPP
-#define BABELTRACE_CPP_COMMON_LIB_STR_HPP
-
-#include "bt2/message.hpp"
-
-namespace bt2_common {
-
-static inline const char *messageTypeStr(const bt2::MessageType type)
-{
- return bt_common_message_type_string(static_cast<bt_message_type>(type));
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_LIB_STR_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 EfficiOS, inc.
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_LIBC_UP_HPP
-#define BABELTRACE_CPP_COMMON_LIBC_UP_HPP
-
-#include <cstdio>
-#include <memory>
-
-namespace bt2_common {
-namespace internal {
-
-struct FileCloserDeleter
-{
- void operator()(std::FILE * const f) noexcept
- {
- std::fclose(f);
- }
-};
-
-} /* namespace internal */
-
-using FileUP = std::unique_ptr<std::FILE, internal::FileCloserDeleter>;
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_LIBC_UP_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_MAKE_UNIQUE_HPP
-#define BABELTRACE_CPP_COMMON_MAKE_UNIQUE_HPP
-
-#include <memory>
-#include <type_traits>
-#include <utility>
-
-namespace bt2_common {
-
-/*
- * Our implementation of std::make_unique<>() for C++11.
- */
-template <typename T, typename... ArgTs>
-std::unique_ptr<T> makeUnique(ArgTs&&...args)
-{
- static_assert(!std::is_array<T>::value, "`T` is not an array (unsupported).");
-
- return std::unique_ptr<T>(new T {std::forward<ArgTs>(args)...});
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_MAKE_UNIQUE_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_READ_FIXED_LEN_INT_HPP
-#define BABELTRACE_CPP_COMMON_READ_FIXED_LEN_INT_HPP
-
-#include <cstdint>
-#include <cstring>
-#include <type_traits>
-
-#include "cpp-common/endian.hpp"
-
-namespace bt2_common {
-
-/*
- * Reads a fixed-length integer of unknown byte order into a value of integral
- * type `IntT` from the buffer `buf` and returns it.
- */
-template <typename IntT>
-IntT readFixedLenInt(const std::uint8_t * const buf)
-{
- static_assert(std::is_integral<IntT>::value, "`IntT` is an integral type.");
-
- IntT val;
-
- std::memcpy(&val, buf, sizeof(val));
- return val;
-}
-
-/*
- * Reads a fixed-length little-endian integer into a value of integral
- * type `IntT` from the buffer `buf` and returns it.
- */
-template <typename IntT>
-IntT readFixedLenIntLe(const std::uint8_t * const buf)
-{
- return bt2_common::littleEndianToNative(readFixedLenInt<IntT>(buf));
-}
-
-/*
- * Reads a fixed-length big-endian integer into a value of integral
- * type `IntT` from the buffer `buf` and returns it.
- */
-template <typename IntT>
-IntT readFixedLenIntBe(const std::uint8_t * const buf)
-{
- return bt2_common::bigEndianToNative(readFixedLenInt<IntT>(buf));
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_READ_FIXED_LEN_INT_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_SAFE_OPS_HPP
-#define BABELTRACE_CPP_COMMON_SAFE_OPS_HPP
-
-#include <limits>
-#include <type_traits>
-
-#include "common/assert.h"
-
-namespace bt2_common {
-
-template <typename T>
-constexpr bool safeToMul(const T a, const T b)
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- return a == 0 || b == 0 || a < std::numeric_limits<T>::max() / b;
-}
-
-template <typename T>
-T safeMul(const T a, const T b) noexcept
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- BT_ASSERT_DBG(safeToMul(a, b));
- return a * b;
-}
-
-template <typename T>
-constexpr bool safeToAdd(const T a, const T b)
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- return a <= std::numeric_limits<T>::max() - b;
-}
-
-template <typename T>
-T safeAdd(const T a, const T b) noexcept
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- BT_ASSERT_DBG(safeToAdd(a, b));
- return a + b;
-}
-
-template <typename T>
-constexpr bool safeToSub(const T a, const T b)
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- return a >= b;
-}
-
-template <typename T>
-T safeSub(const T a, const T b) noexcept
-{
- static_assert(std::is_unsigned<T>::value, "`T` is an unsigned type.");
-
- BT_ASSERT_DBG(safeToSub(a, b));
- return a - b;
-}
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_SAFE_OPS_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_STD_INT_HPP
-#define BABELTRACE_CPP_COMMON_STD_INT_HPP
-
-#include <cstdint>
-
-namespace bt2_common {
-namespace internal {
-
-template <std::size_t LenBitsV, bool IsSignedV>
-struct StdIntTBase;
-
-template <>
-struct StdIntTBase<8, true>
-{
- using Type = std::int8_t;
-};
-
-template <>
-struct StdIntTBase<8, false>
-{
- using Type = std::uint8_t;
-};
-
-template <>
-struct StdIntTBase<16, true>
-{
- using Type = std::int16_t;
-};
-
-template <>
-struct StdIntTBase<16, false>
-{
- using Type = std::uint16_t;
-};
-
-template <>
-struct StdIntTBase<32, true>
-{
- using Type = std::int32_t;
-};
-
-template <>
-struct StdIntTBase<32, false>
-{
- using Type = std::uint32_t;
-};
-
-template <>
-struct StdIntTBase<64, true>
-{
- using Type = std::int64_t;
-};
-
-template <>
-struct StdIntTBase<64, false>
-{
- using Type = std::uint64_t;
-};
-
-} /* namespace internal */
-
-/*
- * Standard fixed-length integer type `Type` of length `LenBitsV` bits
- * and signedness `IsSignedV`.
- *
- * `LenBitsV` must be one of 8, 16, 32, or 64.
- *
- * For example, `StdIntT<32, true>` is `std::int32_t`.
- */
-template <std::size_t LenBitsV, bool IsSignedV>
-using StdIntT = typename internal::StdIntTBase<LenBitsV, IsSignedV>::Type;
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_STD_INT_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2016-2022 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#include "uuid-view.hpp"
-#include "uuid.hpp"
-
-namespace bt2_common {
-
-UuidView::UuidView(const Uuid& uuid) noexcept : _mUuid {uuid.data()}
-{
-}
-
-UuidView::operator Uuid() const noexcept
-{
- return Uuid {*this};
-}
-
-} /* namespace bt2_common */
+++ /dev/null
-/*
- * SPDX-FileCopyrightText: 2020 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
-#define BABELTRACE_CPP_COMMON_UUID_VIEW_HPP
-
-#include <algorithm>
-#include <cstdint>
-#include <string>
-
-#include "common/assert.h"
-#include "common/uuid.h"
-
-namespace bt2_common {
-
-class Uuid;
-
-/*
- * A view on existing UUID data.
- *
- * A `UuidView` object doesn't contain its UUID data: see `Uuid` for a
- * UUID data container.
- */
-class UuidView final
-{
-public:
- using Val = std::uint8_t;
- using ConstIter = const Val *;
-
-public:
- explicit UuidView(const Val * const uuid) noexcept : _mUuid {uuid}
- {
- BT_ASSERT_DBG(uuid);
- }
-
- explicit UuidView(const Uuid& uuid) noexcept;
- UuidView(const UuidView&) noexcept = default;
- UuidView& operator=(const UuidView&) noexcept = default;
-
- UuidView& operator=(const Val * const uuid) noexcept
- {
- _mUuid = uuid;
- return *this;
- }
-
- operator Uuid() const noexcept;
-
- std::string str() const
- {
- std::string s;
-
- s.resize(BT_UUID_STR_LEN);
- bt_uuid_to_str(_mUuid, &s[0]);
-
- return s;
- }
-
- bool operator==(const UuidView& other) const noexcept
- {
- return bt_uuid_compare(_mUuid, other._mUuid) == 0;
- }
-
- bool operator!=(const UuidView& other) const noexcept
- {
- return !(*this == other);
- }
-
- bool operator<(const UuidView& other) const noexcept
- {
- return bt_uuid_compare(_mUuid, other._mUuid) < 0;
- }
-
- static constexpr std::size_t size() noexcept
- {
- return BT_UUID_LEN;
- }
-
- const Val *data() const noexcept
- {
- return _mUuid;
- }
-
- Val operator[](const std::size_t index) const noexcept
- {
- return _mUuid[index];
- }
-
- ConstIter begin() const noexcept
- {
- return _mUuid;
- }
-
- ConstIter end() const noexcept
- {
- return _mUuid + this->size();
- }
-
- bool isNil() const noexcept
- {
- return std::all_of(this->begin(), this->end(), [](const std::uint8_t byte) {
- return byte == 0;
- });
- }
-
-private:
- const Val *_mUuid;
-};
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_UUID_VIEW_HPP */
+++ /dev/null
-/*
- * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_UUID_HPP
-#define BABELTRACE_CPP_COMMON_UUID_HPP
-
-#include <algorithm>
-#include <array>
-#include <string>
-
-#include "common/assert.h"
-#include "common/uuid.h"
-
-#include "uuid-view.hpp"
-
-namespace bt2_common {
-
-/*
- * A universally unique identifier.
- *
- * A `Uuid` object contains its UUID data: see `UuidView` to have a
- * UUID view on existing UUID data.
- */
-class Uuid final
-{
-public:
- using Val = UuidView::Val;
- using ConstIter = UuidView::ConstIter;
-
-public:
- /*
- * Builds a nil UUID.
- */
- explicit Uuid() noexcept = default;
-
- explicit Uuid(const Val * const uuid) noexcept
- {
- this->_setFromPtr(uuid);
- }
-
- explicit Uuid(const char * const str) noexcept
- {
- const auto ret = bt_uuid_from_str(str, _mUuid.data());
- BT_ASSERT(ret == 0);
- }
-
- explicit Uuid(const std::string& str) noexcept : Uuid {str.c_str()}
- {
- }
-
- explicit Uuid(const UuidView& view) noexcept : Uuid {view.data()}
- {
- }
-
- Uuid(const Uuid&) noexcept = default;
- Uuid& operator=(const Uuid&) noexcept = default;
-
- Uuid& operator=(const Val * const uuid) noexcept
- {
- this->_setFromPtr(uuid);
- return *this;
- }
-
- static Uuid generate() noexcept
- {
- bt_uuid_t uuidGen;
-
- bt_uuid_generate(uuidGen);
- return Uuid {uuidGen};
- }
-
- std::string str() const
- {
- return this->_view().str();
- }
-
- bool operator==(const Uuid& other) const noexcept
- {
- return this->_view() == other._view();
- }
-
- bool operator!=(const Uuid& other) const noexcept
- {
- return this->_view() != other._view();
- }
-
- bool operator<(const Uuid& other) const noexcept
- {
- return this->_view() < other._view();
- }
-
- /*
- * The returned UUID view must not outlive the UUID object.
- */
- operator UuidView() const noexcept
- {
- return this->_view();
- }
-
- static constexpr std::size_t size() noexcept
- {
- return UuidView::size();
- }
-
- const Val *data() const noexcept
- {
- return _mUuid.data();
- }
-
- Val operator[](const std::size_t index) const noexcept
- {
- return this->_view()[index];
- }
-
- ConstIter begin() const noexcept
- {
- return this->_view().begin();
- }
-
- ConstIter end() const noexcept
- {
- return this->_view().end();
- }
-
- bool isNil() const noexcept
- {
- return this->_view().isNil();
- }
-
-private:
- /*
- * std::copy_n() won't throw when simply copying bytes below,
- * therefore this method won't throw.
- */
- void _setFromPtr(const Val * const uuid) noexcept
- {
- BT_ASSERT(uuid);
- std::copy_n(uuid, BT_UUID_LEN, std::begin(_mUuid));
- }
-
- UuidView _view() const noexcept
- {
- return UuidView {_mUuid.data()};
- }
-
- std::array<Val, UuidView::size()> _mUuid = {};
-};
-
-} /* namespace bt2_common */
-
-#endif /* BABELTRACE_CPP_COMMON_UUID_HPP */
+++ /dev/null
-/*
- * SPDX-FileCopyrightText: 2022 Simon Marchi <simon.marchi@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef SRC_CPP_COMMON_VECTOR_HPP
-#define SRC_CPP_COMMON_VECTOR_HPP
-
-#include <vector>
-
-#include "common/assert.h"
-
-namespace bt2_common {
-
-/*
- * Moves the last entry of `vec` to the index `idx`, then removes the last entry.
- *
- * Meant to be a direct replacement for g_ptr_array_remove_index_fast(), but for
- * `std::vector`.
- */
-template <typename T, typename AllocatorT>
-void vectorFastRemove(std::vector<T, AllocatorT>& vec,
- const typename std::vector<T, AllocatorT>::size_type idx)
-{
- BT_ASSERT_DBG(idx < vec.size());
-
- if (idx < vec.size() - 1) {
- vec[idx] = std::move(vec.back());
- }
-
- vec.pop_back();
-}
-
-} /* namespace bt2_common */
-
-#endif /* SRC_CPP_COMMON_VECTOR_HPP */