src/cpp-common: improve C++ UUID utilities
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 30 Mar 2023 16:14:09 +0000 (12:14 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
commit638a0d1225b0950245c027d06834d20236455bfd
tree986d399235b061fba1f3e4cca599561bab0fcdd9
parente3e662d30a75231e283abd26a0d0349f8d5c8816
src/cpp-common: improve C++ UUID utilities

Philippe Proulx writing below.

This patch improves the C++ common UUID utilities.

Francis wrote the initial version of `bt2_common::Uuid`, and then we
worked together to improve many little things at once, leading to this
patch.

His original message was:

> Add `bt2_common::Uuid`
>
> This patch adds the `bt2_common::Uuid` class which represent UUIDs.
>
> `Uuid` instances can be created from byte array, strings, or
> bt2_common::UuidView objects.
>
> The generate() static method returns a Uuid object with newly
> generated UUID.
>
> The operator UuidView() method returns a bt2_common::UuidView object
> representing the entire content of the UUID.
>
> The data() method returns a const pointer to the underlying
> std::array<>.
>
> The str() method returns a new `std::string` instance containing the
> canonical string representation of the UUID.

The final improvements are:

* Add said `bt2_common::Uuid` class.

  I also added the operator[](), operator=(), isNil(), begin(), and
  end() methods, the `Val` and `ConstIter` aliases, and the fact that
  most of the class relies on creating a `bt2_common::UuidView` to wrap
  itself when needed.

  data() just returns `const Val *`.

* In `bt2_common::UuidView`:

  * Make the class `final`.

  * Add the `Val` and `ConstIter` aliases.

  * Add operator<(): makes it possible to use a `bt2_common::UuidView`
    as an `std::set` value type or as an `std::map` key type, and to use
    it with STL algorithms.

  * Make size() `constexpr`.

  * Rename string() to str() for consistency with internal C++ naming.

  * Add begin() and end().

  * Add operator=() which accepts a UUID pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id049953aecc51562e5939db546cb7d82bbaf88eb
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10822
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/Makefile.am
src/cpp-common/uuid-view.cpp [new file with mode: 0644]
src/cpp-common/uuid-view.hpp
src/cpp-common/uuid.hpp [new file with mode: 0644]
This page took 0.024261 seconds and 4 git commands to generate.