From b5097a0e637ffaae978bae38b36a4520c4a5e969 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 1 Jul 2014 01:03:32 +0100 Subject: [PATCH] containers: added opaque pointer access to implementation container, to help with debugging --- src/blackmisc/collection.h | 9 +++++++++ src/blackmisc/sequence.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index e9c334366..f84dafae9 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -310,6 +310,13 @@ namespace BlackMisc */ bool operator !=(const CCollection &other) const { return !(*this == other); } + /*! + * \brief Return an opaque pointer to the implementation container. + * \details Can be useful in unusual debugging situations. + * \warning Not for general use. + */ + void *getImpl() { return pimpl() ? pimpl()->impl() : nullptr; } + private: class PimplBase { @@ -333,6 +340,7 @@ namespace BlackMisc virtual iterator find(const T &value) = 0; virtual const_iterator find(const T &value) const = 0; virtual bool operator ==(const PimplBase &other) const = 0; + virtual void *impl() = 0; }; template class Pimpl : public PimplBase @@ -359,6 +367,7 @@ namespace BlackMisc iterator find(const T &value) override { return iterator::fromImpl(m_impl.find(value)); } const_iterator find(const T &value) const override { return const_iterator::fromImpl(m_impl.find(value)); } bool operator ==(const PimplBase &other) const override { Pimpl copy = C(); for (auto i = other.cbegin(); i != other.cend(); ++i) copy.insert(*i); return m_impl == copy.m_impl; } + void *impl() override { return &m_impl; } private: C m_impl; // insertHelper: QOrderedSet::insert returns an iterator, but std::set::insert returns a std::pair diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index a6524194e..afa893758 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -486,6 +486,13 @@ namespace BlackMisc */ bool operator !=(const CSequence &other) const { return !(*this == other); } + /*! + * \brief Return an opaque pointer to the implementation container. + * \details Can be useful in unusual debugging situations. + * \warning Not for general use. + */ + void *getImpl() { return pimpl() ? pimpl()->impl() : nullptr; } + private: class PimplBase { @@ -515,6 +522,7 @@ namespace BlackMisc virtual iterator erase(iterator pos) = 0; virtual iterator erase(iterator it1, iterator it2) = 0; virtual bool operator ==(const PimplBase &other) const = 0; + virtual void *impl() = 0; }; template class Pimpl : public PimplBase @@ -546,6 +554,7 @@ namespace BlackMisc iterator erase(iterator pos) override { return iterator::fromImpl(m_impl.erase(*static_cast(pos.getImpl()))); } iterator erase(iterator it1, iterator it2) override { return iterator::fromImpl(m_impl.erase(*static_cast(it1.getImpl()), *static_cast(it2.getImpl()))); } bool operator ==(const PimplBase &other) const override { Pimpl copy = C(); for (auto i = other.cbegin(); i != other.cend(); ++i) copy.push_back(*i); return m_impl == copy.m_impl; } + void *impl() override { return &m_impl; } private: C m_impl; };