From c844b06a08b2cc646eef9a9837382a08e4a6fa2c Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Mon, 16 Dec 2024 17:49:26 -0500 Subject: [PATCH] Bring Bimap API closer to Lopmap --- lib/core/include/qx/core/qx-bimap.h | 9 ++++ lib/core/src/qx-bimap.dox | 71 ++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/lib/core/include/qx/core/qx-bimap.h b/lib/core/include/qx/core/qx-bimap.h index 81180196..d200fc31 100644 --- a/lib/core/include/qx/core/qx-bimap.h +++ b/lib/core/include/qx/core/qx-bimap.h @@ -125,9 +125,12 @@ class Bimap //-Aliases------------------------------------------------------------------------------------------------------ public: + using iterator = const_iterator; using left_type = Left; using right_type = Right; using ConstIterator = const_iterator; + using difference_type = typename QHash::difference_type; + using size_type = typename QHash::size_type; //-Instance Variables------------------------------------------------------------------------------------------- private: @@ -193,9 +196,11 @@ class Bimap } public: + iterator begin() { return iterator(mL2R.begin()); } const_iterator begin() const { return constBegin(); } const_iterator cbegin() const { return constBegin(); } const_iterator constBegin() const { return const_iterator(mL2R.cbegin()); } + iterator end() { return iterator(mL2R.end()); } const_iterator end() const { return constEnd(); } const_iterator cend() const { return constEnd(); } const_iterator constEnd() const { return const_iterator(mL2R.cend()); } @@ -209,9 +214,13 @@ class Bimap return const_iterator(rItr != mR2L.cend() ? mL2R.constFind(*(*rItr)) : mL2R.cend()); } + iterator find(const Left& l) requires asymmetric_bimap { return findLeft(l); } const_iterator find(const Left& l) const requires asymmetric_bimap { return findLeft(l); } + iterator find(const Right& r) requires asymmetric_bimap { return findRight(r); } const_iterator find(const Right& r) const requires asymmetric_bimap { return findRight(r); } + iterator findLeft(const Left& l) { return iterator(constFindLeft(l)); } const_iterator findLeft(const Left& l) const { return const_iterator(constFindLeft(l)); } + iterator findRight(const Right& r) { return iterator(constFindRight(r)); } const_iterator findRight(const Right& r) const { return const_iterator(constFindRight(r)); } const_iterator erase(const_iterator pos) diff --git a/lib/core/src/qx-bimap.dox b/lib/core/src/qx-bimap.dox index 80bfbb72..ab35122a 100644 --- a/lib/core/src/qx-bimap.dox +++ b/lib/core/src/qx-bimap.dox @@ -44,11 +44,20 @@ namespace Qx * significant than the other. Lookup of one of the "side's" values using the other is possible * via fromLeft(), fromRight(), and other similarly named functions. * + * iterator is simply an alias for const_iterator as values cannot be modified through + * bimap iterators due to technical limitations. + * * Both the Left and Right types must provide operator==() and a global qHash() overload. */ //-Aliases-------------------------------------------------------------------------------------------------- //Public: +/*! + * @typedef Bimap::iterator + * + * Typedef for const_iterator. + */ + /*! * @typedef Bimap::left_type * @@ -67,6 +76,18 @@ namespace Qx * Qt-style synonym for Bimap::const_iterator. */ +/*! + * @typedef Bimap::difference_type + * + * Typedef for ptrdiff_t. Provided for STL compatibility. + */ + +/*! + * @typedef Bimap::size_type + * + * Typedef for int. Provided for STL compatibility. + */ + //-Constructor---------------------------------------------------------------------------------------------- //Public: /*! @@ -86,11 +107,17 @@ namespace Qx //-Instance Functions---------------------------------------------------------------------------------------------- //Public: /*! - * @fn const_iterator Bimap::begin() const + * @fn iterator Bimap::begin() * * Same as constBegin(). */ +/*! + * @fn const_iterator Bimap::begin() const + * + * @overload + */ + /*! * @fn const_iterator Bimap::cbegin() const * @@ -109,11 +136,17 @@ namespace Qx */ /*! - * @fn const_iterator Bimap::end() const + * @fn iterator Bimap::end() * * Same as constEnd(). */ +/*! + * @fn const_iterator Bimap::end() const + * + * @overload + */ + /*! * @fn const_iterator Bimap::cend() const * @@ -123,7 +156,7 @@ namespace Qx /*! * @fn const_iterator Bimap::constEnd() const * - * Returns an STL-style iterator pointing to the first relationship in the bimap. + * Returns an STL-style iterator pointing to the last relationship in the bimap. * * @warning Returned iterators/references should be considered invalidated the next time you call * a non-const function on the bimap, or when the bimap is destroyed. @@ -166,29 +199,53 @@ namespace Qx */ /*! - * @fn const_iterator Bimap::find(const Left& l) const + * @fn iterator Bimap::find(const Left& l) * * Same as constFindLeft(). */ /*! - * @fn const_iterator Bimap::find(const Right& l) const + * @fn const_iterator Bimap::find(const Left& l) const + * + * @overload + */ + +/*! + * @fn iterator Bimap::find(const Right& r) * * Same as constFindRight(). */ /*! - * @fn const_iterator Bimap::findLeft(const Left& l) const + * @fn const_iterator Bimap::find(const Right& r) const + * + * @overload + */ + +/*! + * @fn iterator Bimap::findLeft(const Left& r) * * Same as constFindLeft(). */ /*! - * @fn const_iterator Bimap::findRight(const Right& l) const + * @fn const_iterator Bimap::findLeft(const Left& r) const + * + * @overload + */ + +/*! + * @fn iterator Bimap::findRight(const Right& r) * * Same as constFindRight(). */ +/*! + * @fn const_iterator Bimap::findRight(const Right& r) const + * + * @overload + */ + /*! * @fn const_iterator Bimap::erase(const_iterator pos) *