From: Philippe Proulx Date: Fri, 27 Oct 2023 18:52:32 +0000 (-0400) Subject: cpp-common/bt2: rename `common-iter.hpp` to `common-iterator.hpp` X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=8aee46a3d5fa54b6fdacf8684fb9bb819901677d;p=babeltrace.git cpp-common/bt2: rename `common-iter.hpp` to `common-iterator.hpp` Signed-off-by: Philippe Proulx Change-Id: I4816ab3ecf2b19423f8ab0a92924e62c438df4f9 Reviewed-on: https://review.lttng.org/c/babeltrace/+/11164 Reviewed-by: Simon Marchi --- diff --git a/src/Makefile.am b/src/Makefile.am index 1f90d14b..5e2ac10a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,7 +15,7 @@ noinst_HEADERS = \ cpp-common/bt2/borrowed-object.hpp \ cpp-common/bt2/clock-class.hpp \ cpp-common/bt2/clock-snapshot.hpp \ - cpp-common/bt2/common-iter.hpp \ + cpp-common/bt2/common-iterator.hpp \ cpp-common/bt2/exc.hpp \ cpp-common/bt2/field-class.hpp \ cpp-common/bt2/field.hpp \ diff --git a/src/cpp-common/bt2/common-iter.hpp b/src/cpp-common/bt2/common-iter.hpp deleted file mode 100644 index 84888844..00000000 --- a/src/cpp-common/bt2/common-iter.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022 Francis Deslauriers - * - * SPDX-License-Identifier: MIT - */ - -#ifndef BABELTRACE_CPP_COMMON_BT2_COMMON_ITER_HPP -#define BABELTRACE_CPP_COMMON_BT2_COMMON_ITER_HPP - -#include -#include - -#include "cpp-common/optional.hpp" - -namespace bt2 { - -template -class CommonIterator -{ - friend ContainerT; - -public: - using difference_type = std::ptrdiff_t; - using value_type = ElemT; - using pointer = value_type *; - using reference = value_type&; - using iterator_category = std::input_iterator_tag; - -private: - explicit CommonIterator(const ContainerT container, const uint64_t idx) : - _mContainer {container}, _mIdx {idx} - { - this->_updateCurrentValue(); - } - -public: - CommonIterator(const CommonIterator&) = default; - CommonIterator(CommonIterator&&) = default; - CommonIterator& operator=(const CommonIterator&) = default; - CommonIterator& operator=(CommonIterator&&) = default; - - CommonIterator& operator++() noexcept - { - ++_mIdx; - this->_updateCurrentValue(); - return *this; - } - - CommonIterator operator++(int) noexcept - { - const auto tmp = *this; - - ++(*this); - return tmp; - } - - bool operator==(const CommonIterator& other) const noexcept - { - return _mIdx == other._mIdx; - } - - bool operator!=(const CommonIterator& other) const noexcept - { - return !(*this == other); - } - - reference operator*() noexcept - { - return *_mCurrVal; - } - - pointer operator->() noexcept - { - return &(*_mCurrVal); - } - -private: - void _updateCurrentValue() noexcept - { - if (_mIdx < _mContainer.size()) { - _mCurrVal = _mContainer[_mIdx]; - } else { - _mCurrVal = nonstd::nullopt; - } - } - - nonstd::optional _mCurrVal; - ContainerT _mContainer; - uint64_t _mIdx; -}; - -} /* namespace bt2 */ - -#endif /* BABELTRACE_CPP_COMMON_BT2_COMMON_ITER_HPP */ diff --git a/src/cpp-common/bt2/common-iterator.hpp b/src/cpp-common/bt2/common-iterator.hpp new file mode 100644 index 00000000..e878b1b9 --- /dev/null +++ b/src/cpp-common/bt2/common-iterator.hpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 Francis Deslauriers + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_COMMON_ITERATOR_HPP +#define BABELTRACE_CPP_COMMON_BT2_COMMON_ITERATOR_HPP + +#include +#include + +#include "cpp-common/optional.hpp" + +namespace bt2 { + +template +class CommonIterator +{ + friend ContainerT; + +public: + using difference_type = std::ptrdiff_t; + using value_type = ElemT; + using pointer = value_type *; + using reference = value_type&; + using iterator_category = std::input_iterator_tag; + +private: + explicit CommonIterator(const ContainerT container, const uint64_t idx) : + _mContainer {container}, _mIdx {idx} + { + this->_updateCurrentValue(); + } + +public: + CommonIterator(const CommonIterator&) = default; + CommonIterator(CommonIterator&&) = default; + CommonIterator& operator=(const CommonIterator&) = default; + CommonIterator& operator=(CommonIterator&&) = default; + + CommonIterator& operator++() noexcept + { + ++_mIdx; + this->_updateCurrentValue(); + return *this; + } + + CommonIterator operator++(int) noexcept + { + const auto tmp = *this; + + ++(*this); + return tmp; + } + + bool operator==(const CommonIterator& other) const noexcept + { + return _mIdx == other._mIdx; + } + + bool operator!=(const CommonIterator& other) const noexcept + { + return !(*this == other); + } + + reference operator*() noexcept + { + return *_mCurrVal; + } + + pointer operator->() noexcept + { + return &(*_mCurrVal); + } + +private: + void _updateCurrentValue() noexcept + { + if (_mIdx < _mContainer.size()) { + _mCurrVal = _mContainer[_mIdx]; + } else { + _mCurrVal = nonstd::nullopt; + } + } + + nonstd::optional _mCurrVal; + ContainerT _mContainer; + uint64_t _mIdx; +}; + +} /* namespace bt2 */ + +#endif /* BABELTRACE_CPP_COMMON_BT2_COMMON_ITERATOR_HPP */ diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 168af69c..0999b135 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -17,7 +17,7 @@ #include "cpp-common/string_view.hpp" #include "borrowed-object.hpp" -#include "common-iter.hpp" +#include "common-iterator.hpp" #include "exc.hpp" #include "field-path.hpp" #include "integer-range-set.hpp" diff --git a/src/cpp-common/bt2/field-path.hpp b/src/cpp-common/bt2/field-path.hpp index 97c1addd..ef5ff090 100644 --- a/src/cpp-common/bt2/field-path.hpp +++ b/src/cpp-common/bt2/field-path.hpp @@ -14,7 +14,7 @@ #include "common/assert.h" #include "borrowed-object.hpp" -#include "common-iter.hpp" +#include "common-iterator.hpp" #include "shared-object.hpp" namespace bt2 { diff --git a/src/cpp-common/bt2/integer-range-set.hpp b/src/cpp-common/bt2/integer-range-set.hpp index b090a330..d58b93cb 100644 --- a/src/cpp-common/bt2/integer-range-set.hpp +++ b/src/cpp-common/bt2/integer-range-set.hpp @@ -13,7 +13,7 @@ #include #include "borrowed-object.hpp" -#include "common-iter.hpp" +#include "common-iterator.hpp" #include "exc.hpp" #include "integer-range.hpp" #include "internal/utils.hpp" diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index 7596694c..1aa41318 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -19,7 +19,7 @@ #include "cpp-common/string_view.hpp" #include "borrowed-object.hpp" -#include "common-iter.hpp" +#include "common-iterator.hpp" #include "exc.hpp" #include "internal/utils.hpp" #include "shared-object.hpp"