mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add get() dereferencing for PtrList iterators
- gets the pointer within the list.
This commit is contained in:
@ -68,7 +68,7 @@ Foam::PtrList<T>::PtrList(const SLPtrList<T>& list)
|
|||||||
template<class T>
|
template<class T>
|
||||||
Foam::PtrList<T>::~PtrList()
|
Foam::PtrList<T>::~PtrList()
|
||||||
{
|
{
|
||||||
(this->ptrs_).free();
|
(this->ptrs_).free(); // free old pointers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ License
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::PtrList<T>::free()
|
inline void Foam::PtrList<T>::free()
|
||||||
{
|
{
|
||||||
(this->ptrs_).free();
|
(this->ptrs_).free(); // free old pointers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ inline Foam::PtrList<T>::PtrList
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::PtrList<T>::clear()
|
inline void Foam::PtrList<T>::clear()
|
||||||
{
|
{
|
||||||
(this->ptrs_).free();
|
(this->ptrs_).free(); // free old pointers
|
||||||
UPtrList<T>::clear();
|
UPtrList<T>::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, const tmp<T>& tptr)
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::PtrList<T>::transfer(PtrList<T>& list)
|
inline void Foam::PtrList<T>::transfer(PtrList<T>& list)
|
||||||
{
|
{
|
||||||
this->free(); // free old pointers
|
(this->ptrs_).free(); // free old pointers
|
||||||
UPtrList<T>::transfer(list);
|
UPtrList<T>::transfer(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ Description
|
|||||||
Note
|
Note
|
||||||
The class definition is such that it contains a list of pointers, but
|
The class definition is such that it contains a list of pointers, but
|
||||||
itself does not inherit from a list of pointers since this would
|
itself does not inherit from a list of pointers since this would
|
||||||
wreak havoc later inheritance resolution.
|
wreak havoc later with inheritance resolution.
|
||||||
|
|
||||||
See Also
|
See Also
|
||||||
Foam::PtrList
|
Foam::PtrList
|
||||||
@ -226,6 +226,11 @@ public:
|
|||||||
//- Construct for a given entry
|
//- Construct for a given entry
|
||||||
inline iterator(T** ptr);
|
inline iterator(T** ptr);
|
||||||
|
|
||||||
|
// Member functions
|
||||||
|
|
||||||
|
//- Return pointer, can be nullptr.
|
||||||
|
inline pointer get() const;
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
inline bool operator==(const iterator& iter) const;
|
inline bool operator==(const iterator& iter) const;
|
||||||
@ -280,6 +285,11 @@ public:
|
|||||||
//- Copy construct from non-const iterator
|
//- Copy construct from non-const iterator
|
||||||
inline const_iterator(const iterator& iter);
|
inline const_iterator(const iterator& iter);
|
||||||
|
|
||||||
|
// Member functions
|
||||||
|
|
||||||
|
//- Return pointer, can be nullptr.
|
||||||
|
inline pointer get() const;
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
inline bool operator==(const const_iterator& iter) const;
|
inline bool operator==(const const_iterator& iter) const;
|
||||||
|
|||||||
@ -237,6 +237,13 @@ inline Foam::UPtrList<T>::iterator::iterator(T** ptr)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline T* Foam::UPtrList<T>::iterator::get() const
|
||||||
|
{
|
||||||
|
return *ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
|
inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const
|
||||||
{
|
{
|
||||||
@ -403,6 +410,13 @@ inline Foam::UPtrList<T>::const_iterator::const_iterator(const iterator& iter)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline const T* Foam::UPtrList<T>::const_iterator::get() const
|
||||||
|
{
|
||||||
|
return *ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool Foam::UPtrList<T>::const_iterator::operator==
|
inline bool Foam::UPtrList<T>::const_iterator::operator==
|
||||||
(
|
(
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -366,7 +366,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
indices.setSize(this->size());
|
indices.resize(this->size());
|
||||||
label count = 0;
|
label count = 0;
|
||||||
forAll(*this, i)
|
forAll(*this, i)
|
||||||
{
|
{
|
||||||
@ -375,7 +375,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
indices[count++] = i;
|
indices[count++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indices.setSize(count);
|
indices.resize(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
@ -487,11 +487,12 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::findMatching
|
|||||||
bitSet bitset;
|
bitSet bitset;
|
||||||
|
|
||||||
const labelList indices = this->findIndices(key);
|
const labelList indices = this->findIndices(key);
|
||||||
forAll(indices, i)
|
|
||||||
|
for (const label zonei : indices)
|
||||||
{
|
{
|
||||||
bitset.set
|
bitset.set
|
||||||
(
|
(
|
||||||
static_cast<const labelList&>(this->operator[](indices[i]))
|
static_cast<const labelList&>(this->operator[](zonei))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,6 +500,50 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::findMatching
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class ZoneType, class MeshType>
|
||||||
|
const ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::zonePtr
|
||||||
|
(
|
||||||
|
const word& zoneName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const PtrList<ZoneType>& zones = *this;
|
||||||
|
|
||||||
|
for (auto iter = zones.begin(); iter != zones.end(); ++iter)
|
||||||
|
{
|
||||||
|
const ZoneType* ptr = iter.get();
|
||||||
|
|
||||||
|
if (ptr && zoneName == ptr->name())
|
||||||
|
{
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class ZoneType, class MeshType>
|
||||||
|
ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::zonePtr
|
||||||
|
(
|
||||||
|
const word& zoneName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PtrList<ZoneType>& zones = *this;
|
||||||
|
|
||||||
|
for (auto iter = zones.begin(); iter != zones.end(); ++iter)
|
||||||
|
{
|
||||||
|
ZoneType* ptr = iter.get();
|
||||||
|
|
||||||
|
if (ptr && zoneName == ptr->name())
|
||||||
|
{
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class ZoneType, class MeshType>
|
template<class ZoneType, class MeshType>
|
||||||
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
|
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -49,13 +49,14 @@ namespace Foam
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declarations
|
||||||
|
|
||||||
template<class ZoneType, class MeshType> class ZoneMesh;
|
template<class ZoneType, class MeshType> class ZoneMesh;
|
||||||
|
|
||||||
template<class ZoneType, class MeshType>
|
template<class ZoneType, class MeshType>
|
||||||
Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones);
|
Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class ZoneMesh Declaration
|
Class ZoneMesh Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -186,6 +187,14 @@ public:
|
|||||||
//- Mark items (cells, faces, points) that match the zone specification
|
//- Mark items (cells, faces, points) that match the zone specification
|
||||||
bitSet findMatching(const keyType& key) const;
|
bitSet findMatching(const keyType& key) const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Lookup zone by name and return const pointer, nullptr on error.
|
||||||
|
const ZoneType* zonePtr(const word& zoneName) const;
|
||||||
|
|
||||||
|
//- Lookup zone by name and return pointer, nullptr on error.
|
||||||
|
ZoneType* zonePtr(const word& zoneName);
|
||||||
|
|
||||||
|
|
||||||
//- Clear addressing
|
//- Clear addressing
|
||||||
void clearAddressing();
|
void clearAddressing();
|
||||||
|
|
||||||
@ -205,6 +214,7 @@ public:
|
|||||||
//- writeData member function required by regIOobject
|
//- writeData member function required by regIOobject
|
||||||
bool writeData(Ostream& os) const;
|
bool writeData(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Return const and non-const reference to zone by index.
|
//- Return const and non-const reference to zone by index.
|
||||||
|
|||||||
Reference in New Issue
Block a user