mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: return const pointer instead of bool from PtrList::set(label)
- can still test as a bool or use to 'peek' at the content.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -150,21 +150,22 @@ public:
|
||||
//- Transfer into this list and annul the argument list
|
||||
inline void transfer(PtrList<T>& list);
|
||||
|
||||
//- Return true if element is set (ie, not a nullptr)
|
||||
inline bool set(const label i) const;
|
||||
//- Return const pointer to element (if set) or nullptr.
|
||||
// The return value can be tested as a bool.
|
||||
inline const T* set(const label i) const;
|
||||
|
||||
//- Set element to given pointer and return old element (can be null)
|
||||
// No-op if the new pointer value is identical to the current content.
|
||||
inline autoPtr<T> set(label i, T* ptr);
|
||||
inline autoPtr<T> set(const label i, T* ptr);
|
||||
|
||||
//- Set element to given autoPtr and return old element
|
||||
inline autoPtr<T> set(label i, autoPtr<T>& aptr);
|
||||
inline autoPtr<T> set(const label i, autoPtr<T>& aptr);
|
||||
|
||||
//- Set element to given autoPtr and return old element
|
||||
inline autoPtr<T> set(label i, autoPtr<T>&& aptr);
|
||||
inline autoPtr<T> set(const label i, autoPtr<T>&& aptr);
|
||||
|
||||
//- Set element to given tmp and return old element
|
||||
inline autoPtr<T> set(label i, const tmp<T>& tptr);
|
||||
inline autoPtr<T> set(const label i, const tmp<T>& tptr);
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -123,35 +123,35 @@ inline void Foam::PtrList<T>::append(const tmp<T>& tptr)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::PtrList<T>::set(const label i) const
|
||||
inline const T* Foam::PtrList<T>::set(const label i) const
|
||||
{
|
||||
return UPtrList<T>::set(i);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, T* ptr)
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
|
||||
{
|
||||
return autoPtr<T>(UPtrList<T>::set(i, ptr));
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, autoPtr<T>& aptr)
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, autoPtr<T>& aptr)
|
||||
{
|
||||
return set(i, aptr.release());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, autoPtr<T>&& aptr)
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, autoPtr<T>&& aptr)
|
||||
{
|
||||
return set(i, aptr.release());
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, const tmp<T>& tptr)
|
||||
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, const tmp<T>& tptr)
|
||||
{
|
||||
return set(i, tptr.ptr());
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -177,8 +177,9 @@ public:
|
||||
//- Transfer contents into this list and annul the argument
|
||||
inline void transfer(UPtrList<T>& list);
|
||||
|
||||
//- Return true if element is set (not a nullptr)
|
||||
inline bool set(const label i) const;
|
||||
//- Return const pointer to element (if set) or nullptr.
|
||||
// The return value can be tested as a bool.
|
||||
inline const T* set(const label i) const;
|
||||
|
||||
//- Set element to specified pointer and return the old list element,
|
||||
//- which can be a nullptr.
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -170,9 +170,9 @@ inline void Foam::UPtrList<T>::append(T* ptr)
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::UPtrList<T>::set(const label i) const
|
||||
inline const T* Foam::UPtrList<T>::set(const label i) const
|
||||
{
|
||||
return ptrs_[i] != nullptr;
|
||||
return ptrs_[i];
|
||||
}
|
||||
|
||||
|
||||
@ -199,7 +199,7 @@ inline const T& Foam::UPtrList<T>::operator[](const label i) const
|
||||
if (!ptr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "cannot dereference nullptr at index " << i
|
||||
<< "Cannot dereference nullptr at index " << i
|
||||
<< " in range [0," << size() << ")"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -216,7 +216,7 @@ inline T& Foam::UPtrList<T>::operator[](const label i)
|
||||
if (!ptr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "cannot dereference nullptr at index " << i
|
||||
<< "Cannot dereference nullptr at index " << i
|
||||
<< " in range [0," << size() << ")"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user