From 085f0113691319849ca59efe5cc379e772838914 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Fri, 6 May 2016 14:08:12 +0100 Subject: [PATCH] PtrList: Now derived from UPtrList to avoid unnecessary code duplication consistency with UList/List and so that functions which take a UPtrList argument can also be called for PtrList. --- src/OpenFOAM/containers/Lists/List/List.H | 53 +- .../containers/Lists/PackedList/PackedListI.H | 1 - .../containers/Lists/PtrList/PtrList.C | 66 ++- .../containers/Lists/PtrList/PtrList.H | 295 +---------- .../containers/Lists/PtrList/PtrListI.H | 498 +----------------- .../containers/Lists/PtrList/PtrListIO.C | 25 - src/OpenFOAM/containers/Lists/UList/UList.C | 2 - src/OpenFOAM/containers/Lists/UList/UList.H | 104 ++-- .../containers/Lists/UPtrList/UPtrList.C | 2 - .../containers/Lists/UPtrList/UPtrList.H | 163 +++++- .../containers/Lists/UPtrList/UPtrListI.H | 225 +++++++- .../containers/Lists/UPtrList/UPtrListIO.C | 7 +- 12 files changed, 506 insertions(+), 935 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 77c9a5e40a..61f5074fe9 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -49,11 +49,12 @@ SourceFiles namespace Foam { +// Forward declaration of classes + class Istream; class Ostream; // Forward declaration of friend functions and operators - template<class T> class List; template<class T> Istream& operator>>(Istream&, List<T>&); @@ -85,7 +86,7 @@ class List protected: //- Override size to be inconsistent with allocated storage. - // Use with care. + // Use with care inline void size(const label); @@ -98,28 +99,28 @@ public: // Constructors - //- Null constructor. + //- Null constructor inline List(); - //- Construct with given size. + //- Construct with given size explicit List(const label); - //- Construct with given size and value for all elements. + //- Construct with given size and value for all elements List(const label, const T&); - //- Construct with given size initializing all elements to zero. + //- Construct with given size initializing all elements to zero List(const label, const zero); - //- Copy constructor. + //- Copy constructor List(const List<T>&); //- Construct by transferring the parameter contents List(const Xfer<List<T>>&); - //- Construct as copy or re-use as specified. + //- Construct as copy or re-use as specified List(List<T>&, bool reuse); - //- Construct as subset. + //- Construct as subset List(const UList<T>&, const labelUList& mapAddressing); //- Construct as copy of FixedList<T, Size> @@ -138,7 +139,7 @@ public: //- Construct as copy of BiIndirectList<T> explicit List(const BiIndirectList<T>&); - //- Construct from Istream. + //- Construct from Istream List(Istream&); //- Clone @@ -157,7 +158,7 @@ public: // Member Functions - //- Return the number of elements in the UList. + //- Return the number of elements in the UList inline label size() const; @@ -169,13 +170,13 @@ public: //- Alias for setSize(const label, const T&) inline void resize(const label, const T&); - //- Reset size of List. + //- Reset size of List void setSize(const label); - //- Reset size of List and value for new elements. + //- Reset size of List and value for new elements void setSize(const label, const T&); - //- Clear the list, i.e. set size to zero. + //- Clear the list, i.e. set size to zero void clear(); //- Append an element at the end of the list @@ -188,22 +189,22 @@ public: inline void append(const UIndirectList<T>&); //- Transfer the contents of the argument List into this list - // and annul the argument list. + // and annul the argument list void transfer(List<T>&); //- Transfer the contents of the argument List into this list - // and annul the argument list. + // and annul the argument list template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); //- Transfer the contents of the argument List into this list - // and annul the argument list. + // and annul the argument list void transfer(SortableList<T>&); //- Transfer contents to the Xfer container inline Xfer<List<T>> xfer(); - //- Return subscript-checked element of UList. + //- Return subscript-checked element of UList inline T& newElmt(const label); @@ -213,19 +214,19 @@ public: // Member operators - //- Assignment from UList operator. Takes linear time. + //- Assignment from UList operator. Takes linear time void operator=(const UList<T>&); - //- Assignment operator. Takes linear time. + //- Assignment operator. Takes linear time void operator=(const List<T>&); - //- Assignment from SLList operator. Takes linear time. + //- Assignment from SLList operator. Takes linear time void operator=(const SLList<T>&); - //- Assignment from UIndirectList operator. Takes linear time. + //- Assignment from UIndirectList operator. Takes linear time void operator=(const UIndirectList<T>&); - //- Assignment from BiIndirectList operator. Takes linear time. + //- Assignment from BiIndirectList operator. Takes linear time void operator=(const BiIndirectList<T>&); //- Assignment of all entries to the given value @@ -237,19 +238,19 @@ public: // Istream operator - //- Read List from Istream, discarding contents of existing List. + //- Read List from Istream, discarding contents of existing List friend Istream& operator>> <T> (Istream&, List<T>&); }; -//- Read a bracket-delimited list, or handle a single value as list of size 1. +//- Read a bracket-delimited list, or handle a single value as list of size 1 // For example, // \code // wList = readList<word>(IStringStream("(patch1 patch2 patch3)")()); // wList = readList<word>(IStringStream("patch0")()); // \endcode -// Mostly useful for handling command-line arguments. +// Mostly useful for handling command-line arguments template<class T> List<T> readList(Istream&); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 69d68a8b32..c945ca0ba3 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -23,7 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" #include <climits> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C index 2fdafcbb74..52ce53cb40 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "PtrList.H" #include "SLPtrList.H" @@ -33,25 +31,25 @@ License template<class T> Foam::PtrList<T>::PtrList() : - ptrs_() + UPtrList<T>() {} template<class T> Foam::PtrList<T>::PtrList(const label s) : - ptrs_(s, reinterpret_cast<T*>(0)) + UPtrList<T>(s) {} template<class T> Foam::PtrList<T>::PtrList(const PtrList<T>& a) : - ptrs_(a.size()) + UPtrList<T>(a.size()) { forAll(*this, i) { - ptrs_[i] = (a[i]).clone().ptr(); + this->ptrs_[i] = (a[i]).clone().ptr(); } } @@ -60,11 +58,11 @@ template<class T> template<class CloneArg> Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg) : - ptrs_(a.size()) + UPtrList<T>(a.size()) { forAll(*this, i) { - ptrs_[i] = (a[i]).clone(cloneArg).ptr(); + this->ptrs_[i] = (a[i]).clone(cloneArg).ptr(); } } @@ -79,13 +77,13 @@ Foam::PtrList<T>::PtrList(const Xfer<PtrList<T>>& lst) template<class T> Foam::PtrList<T>::PtrList(PtrList<T>& a, bool reuse) : - ptrs_(a.ptrs_, reuse) + UPtrList<T>(a, reuse) { if (!reuse) { forAll(*this, i) { - ptrs_[i] = (a[i]).clone().ptr(); + this->ptrs_[i] = (a[i]).clone().ptr(); } } } @@ -94,7 +92,7 @@ Foam::PtrList<T>::PtrList(PtrList<T>& a, bool reuse) template<class T> Foam::PtrList<T>::PtrList(const SLPtrList<T>& sll) : - ptrs_(sll.size()) + UPtrList<T>(sll.size()) { if (sll.size()) { @@ -106,7 +104,7 @@ Foam::PtrList<T>::PtrList(const SLPtrList<T>& sll) ++iter ) { - ptrs_[i++] = (iter()).clone().ptr(); + this->ptrs_[i++] = (iter()).clone().ptr(); } } } @@ -119,9 +117,9 @@ Foam::PtrList<T>::~PtrList() { forAll(*this, i) { - if (ptrs_[i]) + if (this->ptrs_[i]) { - delete ptrs_[i]; + delete this->ptrs_[i]; } } } @@ -140,7 +138,7 @@ void Foam::PtrList<T>::setSize(const label newSize) << abort(FatalError); } - label oldSize = size(); + label oldSize = this->size(); if (newSize == 0) { @@ -151,22 +149,22 @@ void Foam::PtrList<T>::setSize(const label newSize) label i; for (i=newSize; i<oldSize; i++) { - if (ptrs_[i]) + if (this->ptrs_[i]) { - delete ptrs_[i]; + delete this->ptrs_[i]; } } - ptrs_.setSize(newSize); + this->ptrs_.setSize(newSize); } else // newSize > oldSize { - ptrs_.setSize(newSize); + this->ptrs_.setSize(newSize); label i; for (i=oldSize; i<newSize; i++) { - ptrs_[i] = NULL; + this->ptrs_[i] = NULL; } } } @@ -177,13 +175,13 @@ void Foam::PtrList<T>::clear() { forAll(*this, i) { - if (ptrs_[i]) + if (this->ptrs_[i]) { - delete ptrs_[i]; + delete this->ptrs_[i]; } } - ptrs_.clear(); + this->ptrs_.clear(); } @@ -191,33 +189,33 @@ template<class T> void Foam::PtrList<T>::transfer(PtrList<T>& a) { clear(); - ptrs_.transfer(a.ptrs_); + this->ptrs_.transfer(a.ptrs_); } template<class T> void Foam::PtrList<T>::reorder(const labelUList& oldToNew) { - if (oldToNew.size() != size()) + if (oldToNew.size() != this->size()) { FatalErrorInFunction << "Size of map (" << oldToNew.size() - << ") not equal to list size (" << size() + << ") not equal to list size (" << this->size() << ") for type " << typeid(T).name() << abort(FatalError); } - List<T*> newPtrs_(ptrs_.size(), reinterpret_cast<T*>(0)); + List<T*> newPtrs_(this->ptrs_.size(), reinterpret_cast<T*>(0)); forAll(*this, i) { label newI = oldToNew[i]; - if (newI < 0 || newI >= size()) + if (newI < 0 || newI >= this->size()) { FatalErrorInFunction << "Illegal index " << newI << nl - << "Valid indices are 0.." << size()-1 + << "Valid indices are 0.." << this->size()-1 << " for type " << typeid(T).name() << abort(FatalError); } @@ -229,7 +227,7 @@ void Foam::PtrList<T>::reorder(const labelUList& oldToNew) << " already set for type " << typeid(T).name() << abort(FatalError); } - newPtrs_[newI] = ptrs_[i]; + newPtrs_[newI] = this->ptrs_[i]; } forAll(newPtrs_, i) @@ -242,7 +240,7 @@ void Foam::PtrList<T>::reorder(const labelUList& oldToNew) } } - ptrs_.transfer(newPtrs_); + this->ptrs_.transfer(newPtrs_); } @@ -258,16 +256,16 @@ void Foam::PtrList<T>::operator=(const PtrList<T>& a) << abort(FatalError); } - if (size() == 0) + if (this->size() == 0) { setSize(a.size()); forAll(*this, i) { - ptrs_[i] = (a[i]).clone().ptr(); + this->ptrs_[i] = (a[i]).clone().ptr(); } } - else if (a.size() == size()) + else if (a.size() == this->size()) { forAll(*this, i) { diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index 2b5e5584d6..623aca4f45 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -41,83 +41,25 @@ SourceFiles #ifndef PtrList_H #define PtrList_H -#include "List.H" +#include "UPtrList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward declaration of friend functions and operators +// Forward declaration of classes -template<class T> class PtrList; template<class T> class SLPtrList; +template<class T> class autoPtr; +template<class T> class tmp; -template<class T> -inline typename PtrList<T>::iterator operator+ -( - const typename PtrList<T>::iterator&, - label -); - -template<class T> -inline typename PtrList<T>::iterator operator+ -( - label, - const typename PtrList<T>::iterator& -); - -template<class T> -inline typename PtrList<T>::iterator operator- -( - const typename PtrList<T>::iterator&, - label -); - -template<class T> -inline label operator- -( - const typename PtrList<T>::iterator&, - const typename PtrList<T>::iterator& -); - -template<class T> -inline typename PtrList<T>::const_iterator operator+ -( - const typename PtrList<T>::const_iterator&, - label -); - -template<class T> -inline typename PtrList<T>::const_iterator operator+ -( - label, - const typename PtrList<T>::const_iterator& -); - -template<class T> -inline typename PtrList<T>::const_iterator operator- -( - const typename PtrList<T>::const_iterator&, - label -); - -template<class T> -inline label operator- -( - const typename PtrList<T>::const_iterator&, - const typename PtrList<T>::const_iterator& -); +// Forward declaration of friend functions and operators +template<class T> class PtrList; template<class T> Istream& operator>>(Istream&, PtrList<T>&); -template<class T> -Ostream& operator<<(Ostream&, const PtrList<T>&); - -template<class T> class autoPtr; -template<class T> class tmp; - /*---------------------------------------------------------------------------*\ Class PtrList Declaration @@ -125,11 +67,9 @@ template<class T> class tmp; template<class T> class PtrList +: + public UPtrList<T> { - // Private data - - List<T*> ptrs_; - protected: @@ -144,13 +84,13 @@ public: // Constructors - //- Null Constructor. + //- Null Constructor PtrList(); - //- Construct with size specified. + //- Construct with size specified explicit PtrList(const label); - //- Copy constructor. + //- Copy constructor PtrList(const PtrList<T>&); //- Copy constructor with additional argument for clone @@ -160,7 +100,7 @@ public: //- Construct by transferring the parameter contents PtrList(const Xfer<PtrList<T>>&); - //- Construct as copy or re-use as specified. + //- Construct as copy or re-use as specified PtrList(PtrList<T>&, bool reuse); //- Construct as copy of SLPtrList<T> @@ -180,38 +120,18 @@ public: // Member functions - // Access - - //- Return the number of elements in the PtrList - inline label size() const; - - //- Return true if the PtrList is empty (ie, size() is zero). - inline bool empty() const; - - //- Return reference to the first element of the list. - inline T& first(); - - //- Return reference to first element of the list. - inline const T& first() const; - - //- Return reference to the last element of the list. - inline T& last(); - - //- Return reference to the last element of the list. - inline const T& last() const; - // Edit //- Reset size of PtrList. If extending the PtrList, new entries are // set to NULL. If truncating the PtrList, removed entries are - // deleted. + // deleted void setSize(const label); //- Alias for setSize(const label) inline void resize(const label); //- Clear the PtrList, i.e. set size to zero deleting all the - // allocated entries. + // allocated entries void clear(); //- Append an element at the end of the list @@ -220,7 +140,7 @@ public: inline void append(const tmp<T>&); //- Transfer the contents of the argument PtrList into this PtrList - // and annul the argument list. + // and annul the argument list void transfer(PtrList<T>&); //- Transfer contents to the Xfer container @@ -229,10 +149,13 @@ public: //- Is element set inline bool set(const label) const; - //- Set element. Return old element (can be NULL). - // No checks on new element. + //- Set element to given T* and return old element (can be NULL) inline autoPtr<T> set(const label, T*); + + //- Set element to given autoPtr<T> and return old element inline autoPtr<T> set(const label, const autoPtr<T>&); + + //- Set element to given tmp<T> and return old element inline autoPtr<T> set(const label, const tmp<T>&); //- Reorders elements. Ordering does not have to be done in @@ -243,186 +166,14 @@ public: // Member operators - //- Return element const reference. - inline const T& operator[](const label) const; - - //- Return element reference. - inline T& operator[](const label); - - //- Return element const pointer. - inline const T* operator()(const label) const; - - //- Assignment. + //- Assignment void operator=(const PtrList<T>&); - // STL type definitions - - //- Type of values the PtrList contains. - typedef T value_type; - - //- Type that can be used for storing into PtrList::value_type objects. - typedef T& reference; - - //- Type that can be used for storing into constant PtrList::value_type - // objects. - typedef const T& const_reference; - - - // STL iterator - // Random access iterator for traversing PtrList. - - class iterator; - class const_iterator; - friend class iterator; - friend class const_iterator; - - //- An STL-conforming iterator - class iterator - { - T** ptr_; - - public: - - friend class const_iterator; - - //- Construct for a given PtrList entry - inline iterator(T**); - - // Member operators - - inline bool operator==(const iterator&) const; - inline bool operator!=(const iterator&) const; - - typedef T& Tref; - inline Tref operator*(); - inline Tref operator()(); - - inline iterator operator++(); - inline iterator operator++(int); - - inline iterator operator--(); - inline iterator operator--(int); - - inline iterator operator+=(label); - - friend iterator operator+ <T>(const iterator&, label); - friend iterator operator+ <T>(label, const iterator&); - - inline iterator operator-=(label); - - friend iterator operator- <T>(const iterator&, label); - - friend label operator- <T> - ( - const iterator&, - const iterator& - ); - - inline T& operator[](label); - - inline bool operator<(const iterator&) const; - inline bool operator>(const iterator&) const; - - inline bool operator<=(const iterator&) const; - inline bool operator>=(const iterator&) const; - }; - - //- Return an iterator to begin traversing the PtrList. - inline iterator begin(); - - //- Return an iterator to end traversing the PtrList. - inline iterator end(); - - - // STL const_iterator - // Random access iterator for traversing PtrList. - - //- An STL-conforming const_iterator - class const_iterator - { - const T* const* ptr_; - - public: - - //- Construct for a given PtrList entry - inline const_iterator(const T* const*); - - //- Construct from an iterator - inline const_iterator(const iterator&); - - - // Member operators - - inline bool operator==(const const_iterator&) const; - inline bool operator!=(const const_iterator&) const; - - typedef const T& Tref; - inline Tref operator*(); - inline Tref operator()(); - - inline const_iterator operator++(); - inline const_iterator operator++(int); - - inline const_iterator operator--(); - inline const_iterator operator--(int); - - inline const_iterator operator+=(label); - - friend const_iterator operator+ <T> - ( - const const_iterator&, - label - ); - friend const_iterator operator+ <T> - ( - label, - const const_iterator& - ); - - inline const_iterator operator-=(label); - - friend const_iterator operator- <T> - ( - const const_iterator&, - label - ); - - friend label operator- <T> - ( - const const_iterator&, - const const_iterator& - ); - - inline const T& operator[](label); - - inline bool operator<(const const_iterator&) const; - inline bool operator>(const const_iterator&) const; - - inline bool operator<=(const const_iterator&) const; - inline bool operator>=(const const_iterator&) const; - }; - - //- Return an const_iterator to begin traversing the PtrList. - inline const_iterator cbegin() const; - - //- Return an const_iterator to end traversing the PtrList. - inline const_iterator cend() const; - - //- Return an const_iterator to begin traversing the PtrList. - inline const_iterator begin() const; - - //- Return an const_iterator to end traversing the PtrList. - inline const_iterator end() const; - - // IOstream operator - //- Read List from Istream, discarding contents of existing List. + //- Read PtrList from Istream, discarding contents of existing PtrList friend Istream& operator>> <T>(Istream&, PtrList<T>&); - - // Write List to Ostream. - friend Ostream& operator<< <T>(Ostream&, const PtrList<T>&); }; @@ -432,7 +183,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #include "PtrListI.H" +#include "PtrListI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H index 2913f19106..cfe7e26534 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H @@ -28,48 +28,6 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class T> -inline Foam::label Foam::PtrList<T>::size() const -{ - return ptrs_.size(); -} - - -template<class T> -inline bool Foam::PtrList<T>::empty() const -{ - return ptrs_.empty(); -} - - -template<class T> -inline T& Foam::PtrList<T>::first() -{ - return this->operator[](0); -} - - -template<class T> -inline const T& Foam::PtrList<T>::first() const -{ - return this->operator[](0); -} - - -template<class T> -inline T& Foam::PtrList<T>::last() -{ - return this->operator[](this->size()-1); -} - - -template<class T> -inline const T& Foam::PtrList<T>::last() const -{ - return this->operator[](this->size()-1); -} - - template<class T> inline void Foam::PtrList<T>::resize(const label newSize) { @@ -80,9 +38,9 @@ inline void Foam::PtrList<T>::resize(const label newSize) template<class T> inline void Foam::PtrList<T>::append(T* ptr) { - label sz = size(); + label sz = this->size(); this->setSize(sz+1); - ptrs_[sz] = ptr; + this->ptrs_[sz] = ptr; } @@ -106,15 +64,15 @@ inline void Foam::PtrList<T>::append template<class T> inline bool Foam::PtrList<T>::set(const label i) const { - return ptrs_[i] != NULL; + return this->ptrs_[i] != NULL; } template<class T> inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr) { - autoPtr<T> old(ptrs_[i]); - ptrs_[i] = ptr; + autoPtr<T> old(this->ptrs_[i]); + this->ptrs_[i] = ptr; return old; } @@ -148,450 +106,4 @@ inline Foam::Xfer<Foam::PtrList<T>> Foam::PtrList<T>::xfer() } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template<class T> -inline const T& Foam::PtrList<T>::operator[](const label i) const -{ - if (!ptrs_[i]) - { - FatalErrorInFunction - << "hanging pointer of type " << typeid(T).name() - << " at index " << i - << " (size " << size() - << "), cannot dereference" - << abort(FatalError); - } - - return *(ptrs_[i]); -} - - -template<class T> -inline T& Foam::PtrList<T>::operator[](const label i) -{ - if (!ptrs_[i]) - { - FatalErrorInFunction - << "hanging pointer of type " << typeid(T).name() - << " at index " << i - << " (size " << size() - << "), cannot dereference" - << abort(FatalError); - } - - return *(ptrs_[i]); -} - - -template<class T> -inline const T* Foam::PtrList<T>::operator()(const label i) const -{ - return ptrs_[i]; -} - - -// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // - -template<class T> -inline Foam::PtrList<T>::iterator::iterator(T** ptr) -: - ptr_(ptr) -{} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator==(const iterator& iter) const -{ - return ptr_ == iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator!=(const iterator& iter) const -{ - return ptr_ != iter.ptr_; -} - - -template<class T> -inline T& Foam::PtrList<T>::iterator::operator*() -{ - return **ptr_; -} - - -template<class T> -inline T& Foam::PtrList<T>::iterator::operator()() -{ - return operator*(); -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator++() -{ - ++ptr_; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator++(int) -{ - iterator tmp = *this; - ++ptr_; - return tmp; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator--() -{ - --ptr_; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator--(int) -{ - iterator tmp = *this; - --ptr_; - return tmp; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator+=(label n) -{ - ptr_ += n; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::operator+(const typename PtrList<T>::iterator& iter, label n) -{ - typename PtrList<T>::iterator tmp = iter; - return tmp += n; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::operator+(label n, const typename PtrList<T>::iterator& iter) -{ - typename PtrList<T>::iterator tmp = iter; - return tmp += n; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::PtrList<T>::iterator::operator-=(label n) -{ - ptr_ -= n; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator -Foam::operator-(const typename PtrList<T>::iterator& iter, label n) -{ - typename PtrList<T>::iterator tmp = iter; - return tmp -= n; -} - - -template<class T> -inline Foam::label Foam::operator- -( - const typename PtrList<T>::iterator& iter1, - const typename PtrList<T>::iterator& iter2 -) -{ - return (iter1.ptr_ - iter2.ptr_)/sizeof(T*); -} - - -template<class T> -inline T& Foam::PtrList<T>::iterator::operator[](label n) -{ - return *(*this + n); -} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator<(const iterator& iter) const -{ - return ptr_ < iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator>(const iterator& iter) const -{ - return ptr_ > iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator<=(const iterator& iter) const -{ - return ptr_ <= iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::iterator::operator>=(const iterator& iter) const -{ - return ptr_ >= iter.ptr_; -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator Foam::PtrList<T>::begin() -{ - return ptrs_.begin(); -} - - -template<class T> -inline typename Foam::PtrList<T>::iterator Foam::PtrList<T>::end() -{ - return ptrs_.end(); -} - - -// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * // - -template<class T> -inline Foam::PtrList<T>::const_iterator::const_iterator(const T* const* ptr) -: - ptr_(ptr) -{} - - -template<class T> -inline Foam::PtrList<T>::const_iterator::const_iterator(const iterator& iter) -: - ptr_(iter.ptr_) -{} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator== -( - const const_iterator& iter -) const -{ - return ptr_ == iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator!= -( - const const_iterator& iter -) const -{ - return ptr_ != iter.ptr_; -} - - -template<class T> -inline const T& Foam::PtrList<T>::const_iterator::operator*() -{ - return **ptr_; -} - - -template<class T> -inline const T& Foam::PtrList<T>::const_iterator::operator()() -{ - return operator*(); -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator++() -{ - ++ptr_; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator++(int) -{ - const_iterator tmp = *this; - ++ptr_; - return tmp; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator--() -{ - --ptr_; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator--(int) -{ - const_iterator tmp = *this; - --ptr_; - return tmp; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator+=(label n) -{ - ptr_ += n; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::operator+(const typename PtrList<T>::const_iterator& iter, label n) -{ - typename PtrList<T>::const_iterator tmp = iter; - return tmp += n; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::operator+(label n, const typename PtrList<T>::const_iterator& iter) -{ - typename PtrList<T>::const_iterator tmp = iter; - return tmp += n; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::const_iterator::operator-=(label n) -{ - ptr_ -= n; - return *this; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::operator-(const typename PtrList<T>::const_iterator& iter, label n) -{ - typename PtrList<T>::const_iterator tmp = iter; - return tmp -= n; -} - - -template<class T> -inline Foam::label Foam::operator- -( - const typename PtrList<T>::const_iterator& iter1, - const typename PtrList<T>::const_iterator& iter2 -) -{ - return (iter1.ptr_ - iter2.ptr_)/sizeof(T*); -} - - -template<class T> -inline const T& Foam::PtrList<T>::const_iterator::operator[](label n) -{ - return *(*this + n); -} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator< -( - const const_iterator& iter -) const -{ - return ptr_ < iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator> -( - const const_iterator& iter -) const -{ - return ptr_ > iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator<= -( - const const_iterator& iter -) const -{ - return ptr_ <= iter.ptr_; -} - - -template<class T> -inline bool Foam::PtrList<T>::const_iterator::operator>= -( - const const_iterator& iter -) const -{ - return ptr_ >= iter.ptr_; -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::begin() const -{ - return ptrs_.begin(); -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::end() const -{ - return ptrs_.end(); -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::cbegin() const -{ - return ptrs_.begin(); -} - - -template<class T> -inline typename Foam::PtrList<T>::const_iterator -Foam::PtrList<T>::cend() const -{ - return ptrs_.end(); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C index 893a1cfd02..902b716961 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C @@ -182,29 +182,4 @@ Foam::Istream& Foam::operator>>(Istream& is, PtrList<T>& L) } -// * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * // - -template<class T> -Foam::Ostream& Foam::operator<<(Ostream& os, const PtrList<T>& L) -{ - // Write size and start delimiter - os << nl << indent << L.size() << nl - << indent << token::BEGIN_LIST << incrIndent; - - // Write contents - forAll(L, i) - { - os << nl << L[i]; - } - - // Write end delimiter - os << nl << decrIndent << indent << token::END_LIST << nl; - - // Check state of IOstream - os.check("Ostream& operator<<(Ostream&, const PtrList&)"); - - return os; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index ea871ed3f9..52177d79bc 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "UList.H" #include "ListLoopM.H" #include "contiguous.H" diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 984bd90436..ee574c33ec 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -73,10 +73,10 @@ class UList { // Private data - //- Number of elements in UList. + //- Number of elements in UList label size_; - //- Vector of values of type T. + //- Vector of values of type T T* __restrict__ v_; @@ -89,7 +89,7 @@ class UList // of list derived from UList and it is confusing and prone to error // for the default assignment to be either. The solution is to // disallow default assignment and provide separate 'shallowCopy' and - // 'deepCopy' member functions. + // 'deepCopy' member functions void operator=(const UList<T>&) = delete; @@ -151,7 +151,7 @@ public: // Constructors - //- Null constructor. + //- Null constructor inline UList(); //- Construct from components @@ -180,58 +180,58 @@ public: //- Return a const pointer to the first data element, // similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code. + // This can be used (with caution) when interfacing with C code inline const T* cdata() const; //- Return a pointer to the first data element, // similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code. + // This can be used (with caution) when interfacing with C code inline T* data(); - //- Return the first element of the list. + //- Return the first element of the list inline T& first(); - //- Return first element of the list. + //- Return first element of the list inline const T& first() const; - //- Return the last element of the list. + //- Return the last element of the list inline T& last(); - //- Return the last element of the list. + //- Return the last element of the list inline const T& last() const; // Check - //- Check start is within valid range (0 ... size-1). + //- Check start is within valid range (0 ... size-1) inline void checkStart(const label start) const; - //- Check size is within valid range (0 ... size). + //- Check size is within valid range (0 ... size) inline void checkSize(const label size) const; - //- Check index i is within valid range (0 ... size-1). + //- Check index i is within valid range (0 ... size-1) inline void checkIndex(const label i) const; - //- Copy the pointer held by the given UList. + //- Copy the pointer held by the given UList inline void shallowCopy(const UList<T>&); - //- Copy elements of the given UList. + //- Copy elements of the given UList void deepCopy(const UList<T>&); - //- Write the UList as a dictionary entry. + //- Write the UList as a dictionary entry void writeEntry(Ostream&) const; - //- Write the UList as a dictionary entry with keyword. + //- Write the UList as a dictionary entry with keyword void writeEntry(const word& keyword, Ostream&) const; // Member operators - //- Return element of UList. + //- Return element of UList inline T& operator[](const label); - //- Return element of constant UList. + //- Return element of constant UList // Note that the bool specialization adds lazy evaluation so reading // an out-of-range element returns false without any ill-effects inline const T& operator[](const label) const; @@ -248,11 +248,11 @@ public: // STL type definitions - //- Type of values the UList contains. + //- Type of values the UList contains typedef T value_type; //- Type that can be used for storing into - // UList::value_type objects. + // UList::value_type objects typedef T& reference; //- Type that can be used for storing into @@ -260,85 +260,85 @@ public: typedef const T& const_reference; //- The type that can represent the difference between any two - // UList iterator objects. + // UList iterator objects typedef label difference_type; - //- The type that can represent the size of a UList. + //- The type that can represent the size of a UList typedef label size_type; // STL iterator - //- Random access iterator for traversing UList. + //- Random access iterator for traversing UList typedef T* iterator; - //- Return an iterator to begin traversing the UList. + //- Return an iterator to begin traversing the UList inline iterator begin(); - //- Return an iterator to end traversing the UList. + //- Return an iterator to end traversing the UList inline iterator end(); // STL const_iterator - //- Random access iterator for traversing UList. + //- Random access iterator for traversing UList typedef const T* const_iterator; - //- Return const_iterator to begin traversing the constant UList. + //- Return const_iterator to begin traversing the constant UList inline const_iterator cbegin() const; - //- Return const_iterator to end traversing the constant UList. + //- Return const_iterator to end traversing the constant UList inline const_iterator cend() const; - //- Return const_iterator to begin traversing the constant UList. + //- Return const_iterator to begin traversing the constant UList inline const_iterator begin() const; - //- Return const_iterator to end traversing the constant UList. + //- Return const_iterator to end traversing the constant UList inline const_iterator end() const; // STL reverse_iterator - //- Reverse iterator for reverse traversal of UList. + //- Reverse iterator for reverse traversal of UList typedef T* reverse_iterator; - //- Return reverse_iterator to begin reverse traversing the UList. + //- Return reverse_iterator to begin reverse traversing the UList inline reverse_iterator rbegin(); - //- Return reverse_iterator to end reverse traversing the UList. + //- Return reverse_iterator to end reverse traversing the UList inline reverse_iterator rend(); // STL const_reverse_iterator - //- Reverse iterator for reverse traversal of constant UList. + //- Reverse iterator for reverse traversal of constant UList typedef const T* const_reverse_iterator; - //- Return const_reverse_iterator to begin reverse traversing the UList. + //- Return const_reverse_iterator to begin reverse traversing the UList inline const_reverse_iterator crbegin() const; - //- Return const_reverse_iterator to end reverse traversing the UList. + //- Return const_reverse_iterator to end reverse traversing the UList inline const_reverse_iterator crend() const; - //- Return const_reverse_iterator to begin reverse traversing the UList. + //- Return const_reverse_iterator to begin reverse traversing the UList inline const_reverse_iterator rbegin() const; - //- Return const_reverse_iterator to end reverse traversing the UList. + //- Return const_reverse_iterator to end reverse traversing the UList inline const_reverse_iterator rend() const; // STL member functions - //- Return the number of elements in the UList. + //- Return the number of elements in the UList inline label size() const; - //- Return size of the largest possible UList. + //- Return size of the largest possible UList inline label max_size() const; - //- Return true if the UList is empty (ie, size() is zero). + //- Return true if the UList is empty (ie, size() is zero) inline bool empty() const; - //- Swap two ULists of the same type in constant time. + //- Swap two ULists of the same type in constant time void swap(UList<T>&); @@ -346,28 +346,28 @@ public: //- Equality operation on ULists of the same type. // Returns true when the ULists are element-wise equal - // (using UList::value_type::operator==). Takes linear time. + // (using UList::value_type::operator==). Takes linear time bool operator==(const UList<T>&) const; - //- The opposite of the equality operation. Takes linear time. + //- The opposite of the equality operation. Takes linear time bool operator!=(const UList<T>&) const; - //- Compare two ULists lexicographically. Takes linear time. + //- Compare two ULists lexicographically. Takes linear time bool operator<(const UList<T>&) const; - //- Compare two ULists lexicographically. Takes linear time. + //- Compare two ULists lexicographically. Takes linear time bool operator>(const UList<T>&) const; - //- Return true if !(a > b). Takes linear time. + //- Return true if !(a > b). Takes linear time bool operator<=(const UList<T>&) const; - //- Return true if !(a < b). Takes linear time. + //- Return true if !(a < b). Takes linear time bool operator>=(const UList<T>&) const; // Ostream operator - // Write UList to Ostream. + // Write UList to Ostream friend Ostream& operator<< <T> ( Ostream&, @@ -375,7 +375,7 @@ public: ); //- Read UList contents from Istream. Requires size to have been set - // before. + // before friend Istream& operator>> <T> ( Istream&, @@ -413,7 +413,7 @@ inline void reverse(UList<T>&); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #include "UListI.H" +#include "UListI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C index 0936f9ac0d..c95d480825 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "UPtrList.H" // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index fd8fe3f2d2..9c92a8f347 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -48,8 +48,10 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators +// Forward declaration of friend classes +template<class T> class PtrList; +// Forward declaration of friend functions and operators template<class T> class UPtrList; template<class T> @@ -80,6 +82,34 @@ inline label operator- const typename UPtrList<T>::iterator& ); +template<class T> +inline typename UPtrList<T>::const_iterator operator+ +( + const typename UPtrList<T>::const_iterator&, + label +); + +template<class T> +inline typename UPtrList<T>::const_iterator operator+ +( + label, + const typename UPtrList<T>::const_iterator& +); + +template<class T> +inline typename UPtrList<T>::const_iterator operator- +( + const typename UPtrList<T>::const_iterator&, + label +); + +template<class T> +inline label operator- +( + const typename UPtrList<T>::const_iterator&, + const typename UPtrList<T>::const_iterator& +); + template<class T> Istream& operator>>(Istream&, UPtrList<T>&); @@ -101,18 +131,24 @@ class UPtrList public: + // Related types + + //- Declare friendship with the UPtrList class + friend class PtrList<T>; + + // Constructors - //- Null Constructor. + //- Null Constructor UPtrList(); - //- Construct with size specified. + //- Construct with size specified explicit UPtrList(const label); //- Construct by transferring the parameter contents UPtrList(const Xfer<UPtrList<T>>&); - //- Construct as copy or re-use as specified. + //- Construct as copy or re-use as specified UPtrList(UPtrList<T>&, bool reuse); @@ -123,19 +159,19 @@ public: //- Return the number of elements in the UPtrList inline label size() const; - //- Return true if the UPtrList is empty (ie, size() is zero). + //- Return true if the UPtrList is empty (ie, size() is zero) inline bool empty() const; - //- Return reference to the first element of the list. + //- Return reference to the first element of the list inline T& first(); - //- Return reference to first element of the list. + //- Return reference to first element of the list inline const T& first() const; - //- Return reference to the last element of the list. + //- Return reference to the last element of the list inline T& last(); - //- Return reference to the last element of the list. + //- Return reference to the last element of the list inline const T& last() const; @@ -143,19 +179,19 @@ public: //- Reset size of UPtrList. This can only be used to set the size // of an empty UPtrList, extend a UPtrList, remove entries from - // the end of a UPtrList. + // the end of a UPtrList void setSize(const label); //- Reset size of UPtrList. This can only be used to set the size // of an empty UPtrList, extend a UPtrList, remove entries from - // the end of a UPtrList. + // the end of a UPtrList inline void resize(const label); //- Clear the UPtrList, i.e. set size to zero void clear(); //- Transfer the contents of the argument UPtrList into this - // UPtrList and annul the argument list. + // UPtrList and annul the argument list void transfer(UPtrList<T>&); //- Transfer contents to the Xfer container @@ -165,7 +201,7 @@ public: inline bool set(const label) const; //- Set element. Return old element (can be NULL). - // No checks on new element. + // No checks on new element inline T* set(const label, T*); //- Reorders elements. Ordering does not have to be done in @@ -176,31 +212,31 @@ public: // Member operators - //- Return element const reference. + //- Return element const reference inline const T& operator[](const label) const; - //- Return element reference. + //- Return element reference inline T& operator[](const label); - //- Return element const pointer. + //- Return element const pointer inline const T* operator()(const label) const; // STL type definitions - //- Type of values the UPtrList contains. + //- Type of values the UPtrList contains typedef T value_type; - //- Type that can be used for storing into UPtrList::value_type objects. + //- Type that can be used for storing into UPtrList::value_type objects typedef T& reference; //- Type that can be used for storing into constant UPtrList::value_type - // objects. + // objects typedef const T& const_reference; // STL iterator - // Random access iterator for traversing UPtrList. + // Random access iterator for traversing UPtrList class iterator; friend class iterator; @@ -253,16 +289,97 @@ public: inline bool operator>=(const iterator&) const; }; - //- Return an iterator to begin traversing the UPtrList. + //- Return an iterator to begin traversing the UPtrList inline iterator begin(); - //- Return an iterator to end traversing the UPtrList. + //- Return an iterator to end traversing the UPtrList inline iterator end(); + // STL const_iterator + // Random access iterator for traversing UPtrList + + //- An STL-conforming const_iterator + class const_iterator + { + const T* const* ptr_; + + public: + + //- Construct for a given UPtrList entry + inline const_iterator(const T* const*); + + //- Construct from an iterator + inline const_iterator(const iterator&); + + + // Member operators + + inline bool operator==(const const_iterator&) const; + inline bool operator!=(const const_iterator&) const; + + typedef const T& Tref; + inline Tref operator*(); + inline Tref operator()(); + + inline const_iterator operator++(); + inline const_iterator operator++(int); + + inline const_iterator operator--(); + inline const_iterator operator--(int); + + inline const_iterator operator+=(label); + + friend const_iterator operator+ <T> + ( + const const_iterator&, + label + ); + friend const_iterator operator+ <T> + ( + label, + const const_iterator& + ); + + inline const_iterator operator-=(label); + + friend const_iterator operator- <T> + ( + const const_iterator&, + label + ); + + friend label operator- <T> + ( + const const_iterator&, + const const_iterator& + ); + + inline const T& operator[](label); + + inline bool operator<(const const_iterator&) const; + inline bool operator>(const const_iterator&) const; + + inline bool operator<=(const const_iterator&) const; + inline bool operator>=(const const_iterator&) const; + }; + + //- Return an const_iterator to begin traversing the UPtrList + inline const_iterator cbegin() const; + + //- Return an const_iterator to end traversing the UPtrList + inline const_iterator cend() const; + + //- Return an const_iterator to begin traversing the UPtrList + inline const_iterator begin() const; + + //- Return an const_iterator to end traversing the UPtrList + inline const_iterator end() const; + + // IOstream operator - // Write List to Ostream. + //- Write UPtrList to Ostream friend Ostream& operator<< <T>(Ostream&, const UPtrList<T>&); }; diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H index 7162cd5c3d..06002c2ae4 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class T> @@ -301,4 +299,227 @@ Foam::UPtrList<T>::end() } +// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * // + +template<class T> +inline Foam::UPtrList<T>::const_iterator::const_iterator(const T* const* ptr) +: + ptr_(ptr) +{} + + +template<class T> +inline Foam::UPtrList<T>::const_iterator::const_iterator(const iterator& iter) +: + ptr_(iter.ptr_) +{} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator== +( + const const_iterator& iter +) const +{ + return ptr_ == iter.ptr_; +} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator!= +( + const const_iterator& iter +) const +{ + return ptr_ != iter.ptr_; +} + + +template<class T> +inline const T& Foam::UPtrList<T>::const_iterator::operator*() +{ + return **ptr_; +} + + +template<class T> +inline const T& Foam::UPtrList<T>::const_iterator::operator()() +{ + return operator*(); +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator++() +{ + ++ptr_; + return *this; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator++(int) +{ + const_iterator tmp = *this; + ++ptr_; + return tmp; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator--() +{ + --ptr_; + return *this; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator--(int) +{ + const_iterator tmp = *this; + --ptr_; + return tmp; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator+=(label n) +{ + ptr_ += n; + return *this; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::operator+(const typename UPtrList<T>::const_iterator& iter, label n) +{ + typename UPtrList<T>::const_iterator tmp = iter; + return tmp += n; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::operator+(label n, const typename UPtrList<T>::const_iterator& iter) +{ + typename UPtrList<T>::const_iterator tmp = iter; + return tmp += n; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::const_iterator::operator-=(label n) +{ + ptr_ -= n; + return *this; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::operator-(const typename UPtrList<T>::const_iterator& iter, label n) +{ + typename UPtrList<T>::const_iterator tmp = iter; + return tmp -= n; +} + + +template<class T> +inline Foam::label Foam::operator- +( + const typename UPtrList<T>::const_iterator& iter1, + const typename UPtrList<T>::const_iterator& iter2 +) +{ + return (iter1.ptr_ - iter2.ptr_)/sizeof(T*); +} + + +template<class T> +inline const T& Foam::UPtrList<T>::const_iterator::operator[](label n) +{ + return *(*this + n); +} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator< +( + const const_iterator& iter +) const +{ + return ptr_ < iter.ptr_; +} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator> +( + const const_iterator& iter +) const +{ + return ptr_ > iter.ptr_; +} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator<= +( + const const_iterator& iter +) const +{ + return ptr_ <= iter.ptr_; +} + + +template<class T> +inline bool Foam::UPtrList<T>::const_iterator::operator>= +( + const const_iterator& iter +) const +{ + return ptr_ >= iter.ptr_; +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::begin() const +{ + return ptrs_.begin(); +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::end() const +{ + return ptrs_.end(); +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::cbegin() const +{ + return ptrs_.begin(); +} + + +template<class T> +inline typename Foam::UPtrList<T>::const_iterator +Foam::UPtrList<T>::cend() const +{ + return ptrs_.end(); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C index 5f61f97499..5965767613 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,7 +32,8 @@ template<class T> Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& L) { // Write size and start delimiter - os << nl << L.size() << nl << token::BEGIN_LIST; + os << nl << indent << L.size() << nl + << indent << token::BEGIN_LIST << incrIndent; // Write contents forAll(L, i) @@ -41,7 +42,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& L) } // Write end delimiter - os << nl << token::END_LIST << nl; + os << nl << decrIndent << indent << token::END_LIST << nl; // Check state of IOstream os.check("Ostream& operator<<(Ostream&, const UPtrList&)"); -- GitLab