From 0ab0ecb5418c68f1d2fea781033df5fbc5dc1021 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 27 Feb 2023 15:33:03 +0100 Subject: [PATCH] ENH: change refCount (internal) from count() to use_count() - allows unambiguous of count() for other classes. Naming as per std::shared_ptr. STYLE: qualify use_count() and unique() methods with the refCount base - clearer/consistent meaning --- applications/test/tmp/Test-tmp.C | 2 +- src/OpenFOAM/db/IOstreams/token/tokenI.H | 2 +- src/OpenFOAM/memory/refCount/refCount.H | 4 ++-- src/OpenFOAM/memory/tmp/tmpI.H | 18 +++++++++--------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/applications/test/tmp/Test-tmp.C b/applications/test/tmp/Test-tmp.C index cd9e7083440..215459ddaec 100644 --- a/applications/test/tmp/Test-tmp.C +++ b/applications/test/tmp/Test-tmp.C @@ -41,7 +41,7 @@ void printInfo(const tmp<T>& item, const bool verbose = false) << " movable:" << Switch(item.movable()); if (item) { - Info<< " refCount:" << item->count(); + Info<< " refCount:" << item->use_count(); } Info<< " move-constructible:" diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index fe1a5355657..ccea31ef4ff 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -276,7 +276,7 @@ inline void Foam::token::reset() case tokenType::COMPOUND: { - if (data_.compoundPtr->unique()) + if (data_.compoundPtr->refCount::unique()) { delete data_.compoundPtr; } diff --git a/src/OpenFOAM/memory/refCount/refCount.H b/src/OpenFOAM/memory/refCount/refCount.H index 58ef0d0aa88..5df795b3e9d 100644 --- a/src/OpenFOAM/memory/refCount/refCount.H +++ b/src/OpenFOAM/memory/refCount/refCount.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,7 +72,7 @@ public: // Member Functions //- Return the current reference count - int count() const noexcept + int use_count() const noexcept { return count_; } diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index e753f5090cb..191b44a67f7 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,9 +34,9 @@ License template<class T> inline void Foam::tmp<T>::incrCount() { - ptr_->operator++(); + ptr_->refCount::operator++(); - if (ptr_->count() > 1) + if (ptr_->refCount::use_count() > 1) { FatalErrorInFunction << "Attempt to create more than 2 tmp's referring to the same" @@ -79,7 +79,7 @@ inline Foam::tmp<T>::tmp(T* p) ptr_(p), type_(PTR) { - if (ptr_ && !ptr_->unique()) + if (ptr_ && !ptr_->refCount::unique()) { FatalErrorInFunction << "Attempted construction of a " @@ -195,7 +195,7 @@ inline Foam::tmp<T>::~tmp() noexcept template<class T> inline bool Foam::tmp<T>::movable() const noexcept { - return (is_pointer() && ptr_ && ptr_->unique()); + return (is_pointer() && ptr_ && ptr_->refCount::unique()); } @@ -246,7 +246,7 @@ inline T* Foam::tmp<T>::ptr() const if (is_pointer()) { - if (!ptr_->unique()) + if (!ptr_->refCount::unique()) { FatalErrorInFunction << "Attempt to acquire pointer to object referred to" @@ -271,13 +271,13 @@ inline void Foam::tmp<T>::clear() const noexcept { if (is_pointer() && ptr_) { - if (ptr_->unique()) + if (ptr_->refCount::unique()) { delete ptr_; } else { - ptr_->operator--(); + ptr_->refCount::operator--(); } ptr_ = nullptr; } @@ -479,7 +479,7 @@ inline void Foam::tmp<T>::operator=(T* p) << this->typeName() << abort(FatalError); } - else if (!p->unique()) + else if (!p->refCount::unique()) { FatalErrorInFunction << "Attempted assignment of a " -- GitLab