From b2d7439b86f54869c2bed8bc09dde34973df1cec Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Wed, 25 Nov 2009 14:47:48 +0100 Subject: [PATCH] Lists get first() and last() member functions - this builds on Mattijs' commit 968f0bbd57b85 but with a first() as well. - Added both to FixedList, IndirectList, UIndirectList and *PtrList and since they can certainly be useful there. Did not add to BiIndirectList, since I'm not sure what it should mean there. Did not add to PackedList, since it's not clear how useful they'd be yet in these contexts (and I'm not sure how it would interact with the iterator proxy implementation). - Note: STL defines front() and back() for these methods. --- .../DictionaryBase/DictionaryBase.H | 2 +- .../HashTables/HashTable/HashTable.H | 4 +- .../StaticHashTable/StaticHashTable.H | 2 +- .../LinkedLists/accessTypes/ILList/ILList.H | 2 +- .../LinkedLists/accessTypes/LList/LList.H | 2 +- .../accessTypes/LPtrList/LPtrList.H | 2 +- .../linkTypes/DLListBase/DLListBase.H | 2 +- .../linkTypes/SLListBase/SLListBase.H | 2 +- .../Lists/BiIndirectList/BiIndirectList.H | 9 ++++- .../Lists/CompactListList/CompactListList.H | 2 +- .../containers/Lists/FixedList/FixedList.H | 12 ++++++ .../containers/Lists/FixedList/FixedListI.H | 28 ++++++++++++++ .../Lists/IndirectList/IndirectList.H | 22 ++++++++++- .../Lists/IndirectList/IndirectListI.H | 28 ++++++++++++++ src/OpenFOAM/containers/Lists/List/List.C | 6 +-- src/OpenFOAM/containers/Lists/List/List.H | 6 +-- .../containers/Lists/PackedList/PackedList.H | 2 +- .../containers/Lists/PtrList/PtrList.H | 23 +++++++++--- .../containers/Lists/PtrList/PtrListI.H | 37 ++++++++++++++++--- .../Lists/UIndirectList/UIndirectList.H | 19 +++++++++- .../Lists/UIndirectList/UIndirectListI.H | 28 ++++++++++++++ src/OpenFOAM/containers/Lists/UList/UList.H | 20 ++++++---- src/OpenFOAM/containers/Lists/UList/UListI.H | 14 +++++++ .../containers/Lists/UPtrList/UPtrList.C | 2 - .../containers/Lists/UPtrList/UPtrList.H | 24 +++++++++--- .../containers/Lists/UPtrList/UPtrListI.H | 36 ++++++++++++++++-- 26 files changed, 284 insertions(+), 52 deletions(-) diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H index b8024031062..42bfbacb27b 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H @@ -144,7 +144,7 @@ public: void clear(); //- Transfer the contents of the argument into this DictionaryBase - // and annull the argument. + // and annul the argument. void transfer(DictionaryBase<IDLListType, T>&); // Member operators diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index a945859880a..492d6a9e0f4 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -287,7 +287,7 @@ public: void shrink(); //- Transfer the contents of the argument table into this table - // and annull the argument table. + // and annul the argument table. void transfer(HashTable<T, Key, Hash>&); //- Transfer contents to the Xfer container @@ -463,7 +463,7 @@ public: inline iterator operator++(int); }; - //- iterator set to the begining of the HashTable + //- iterator set to the beginning of the HashTable inline iterator begin(); diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H index 09edf50c464..9806a138e00 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H @@ -247,7 +247,7 @@ public: void clearStorage(); //- Transfer the contents of the argument table into this table - // and annull the argument table. + // and annul the argument table. void transfer(StaticHashTable<T, Key, Hash>&); //- Transfer contents to the Xfer container diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H index 20635fa53f9..759d0c5dbe1 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H @@ -140,7 +140,7 @@ public: void clear(); //- Transfer the contents of the argument into this List - // and annull the argument list. + // and annul the argument list. void transfer(ILList<LListBase, T>&); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H index 0905f5543cb..a5e99a63e4d 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H @@ -202,7 +202,7 @@ public: void clear(); //- Transfer the contents of the argument into this List - // and annull the argument list. + // and annul the argument list. void transfer(LList<LListBase, T>&); // Member operators diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H index 333d916a65a..c2e0250acd8 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H @@ -156,7 +156,7 @@ public: void clear(); //- Transfer the contents of the argument into this List - // and annull the argument list. + // and annul the argument list. void transfer(LPtrList<LListBase, T>&); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index 848b797b2ea..beb3c625da6 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H @@ -172,7 +172,7 @@ public: inline void clear(); //- Transfer the contents of the argument into this List - // and annull the argument list. + // and annul the argument list. inline void transfer(DLListBase&); // STL iterator diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index b5c957a5370..b2958c9e558 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -157,7 +157,7 @@ public: inline void clear(); //- Transfer the contents of the argument into this List - // and annull the argument list. + // and annul the argument list. inline void transfer(SLListBase&); // STL iterator diff --git a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H index 5afd48d0f36..1f761d9caf9 100644 --- a/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H +++ b/src/OpenFOAM/containers/Lists/BiIndirectList/BiIndirectList.H @@ -44,7 +44,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class BiIndirectList Declaration + Class BiIndirectList Declaration \*---------------------------------------------------------------------------*/ template<class T> @@ -82,11 +82,16 @@ public: // Access + //- Return the number of elements in the list inline label size() const; - inline bool empty() const; + + //- Return true if the list is empty (ie, size() is zero). + inline bool empty() const; inline const UList<T>& posList() const; inline const UList<T>& negList() const; + + //- Return the list addressing inline const List<label>& addressing() const; //- Calculate index given whether index is into posList or negList diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H index b2aad34d228..e8ee819add1 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H @@ -191,7 +191,7 @@ public: labelList sizes() const; //- Transfer the contents of the argument CompactListList - // into this CompactListList and annull the argument list. + // into this CompactListList and annul the argument list. void transfer(CompactListList<T, Container>&); //- Transfer the contents to the Xfer container diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 0e59184f668..1d7285d8683 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -154,6 +154,18 @@ public: // This can be used (with caution) when interfacing with C code. inline T* data(); + //- Return the first element of the list. + inline T& first(); + + //- Return first element of the list. + inline const T& first() const; + + //- Return the last element of the list. + inline T& last(); + + //- Return the last element of the list. + inline const T& last() const; + // Check diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 1c3fe7131e6..ae762edb479 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -208,6 +208,34 @@ Foam::FixedList<T, Size>::data() } +template<class T, unsigned Size> +inline T& Foam::FixedList<T, Size>::first() +{ + return v_[0]; +} + + +template<class T, unsigned Size> +inline const T& Foam::FixedList<T, Size>::first() const +{ + return v_[0]; +} + + +template<class T, unsigned Size> +inline T& Foam::FixedList<T, Size>::last() +{ + return v_[Size-1]; +} + + +template<class T, unsigned Size> +inline const T& Foam::FixedList<T, Size>::last() const +{ + return v_[Size-1]; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // element access diff --git a/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H b/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H index cfdc03d7dc1..a0d97af48ee 100644 --- a/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H +++ b/src/OpenFOAM/containers/Lists/IndirectList/IndirectList.H @@ -44,7 +44,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class IndirectList Declaration + Class IndirectList Declaration \*---------------------------------------------------------------------------*/ template<class T> @@ -70,10 +70,28 @@ public: // Access + //- Return the number of elements in the list inline label size() const; - inline bool empty() const; + //- Return true if the list is empty (ie, size() is zero). + inline bool empty() const; + + //- Return the first element of the list. + inline T& first(); + + //- Return first element of the list. + inline const T& first() const; + + //- Return the last element of the list. + inline T& last(); + + //- Return the last element of the list. + inline const T& last() const; + + //- Return the complete list inline const UList<T>& completeList() const; + + //- Return the list addressing inline const List<label>& addressing() const; // Edit diff --git a/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H b/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H index a1e2bf9a54e..47eedb733d1 100644 --- a/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H +++ b/src/OpenFOAM/containers/Lists/IndirectList/IndirectListI.H @@ -66,6 +66,34 @@ inline bool Foam::IndirectList<T>::empty() const } +template<class T> +inline T& Foam::IndirectList<T>::first() +{ + return completeList_[addressing_.first()]; +} + + +template<class T> +inline const T& Foam::IndirectList<T>::first() const +{ + return completeList_[addressing_.first()]; +} + + +template<class T> +inline T& Foam::IndirectList<T>::last() +{ + return completeList_[addressing_.last()]; +} + + +template<class T> +inline const T& Foam::IndirectList<T>::last() const +{ + return completeList_[addressing_.last()]; +} + + template<class T> inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const { diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index fb6d9a06789..4158043b083 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -404,7 +404,7 @@ void Foam::List<T>::clear() // Transfer the contents of the argument List into this List -// and anull the argument list +// and annul the argument list template<class T> void Foam::List<T>::transfer(List<T>& a) { @@ -418,7 +418,7 @@ void Foam::List<T>::transfer(List<T>& a) // Transfer the contents of the argument DynamicList into this List -// and anull the argument list +// and annul the argument list template<class T> template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a) @@ -431,7 +431,7 @@ void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a) // Transfer the contents of the argument SortableList into this List -// and anull the argument list +// and annul the argument list template<class T> void Foam::List<T>::transfer(SortableList<T>& a) { diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 7e623f6560f..5fec41ef4d7 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -188,16 +188,16 @@ public: inline void append(const UIndirectList<T>&); //- Transfer the contents of the argument List into this list - // and annull the argument list. + // and annul the argument list. void transfer(List<T>&); //- Transfer the contents of the argument List into this list - // and annull 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 annull the argument list. + // and annul the argument list. void transfer(SortableList<T>&); //- Transfer contents to the Xfer container diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 82ac19fc0e5..78c7306b6e4 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -253,7 +253,7 @@ public: inline void shrink(); //- Transfer the contents of the argument list into this list - // and annull the argument list. + // and annul the argument list. inline void transfer(PackedList<nBits>&); //- Transfer contents to the Xfer container diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index 3f3e6d8fe6c..fdefbf597c6 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -29,8 +29,8 @@ Description A templated 1D list of pointers to objects of type \<T\>, where the size of the array is known and used for subscript bounds checking, etc. - The element operator [] returns a reference to the object - rather than to the pointer. + The element operator [] returns a reference to the object rather than a + pointer. SourceFiles PtrList.C @@ -119,7 +119,7 @@ public: //- Null Constructor. PtrList(); - //- Construct with length specified. + //- Construct with size specified. explicit PtrList(const label); //- Copy constructor. @@ -130,7 +130,7 @@ public: PtrList(const PtrList<T>&, const CloneArg&); //- Construct by transferring the parameter contents - PtrList(const Xfer<PtrList<T> >&); + PtrList(const Xfer< PtrList<T> >&); //- Construct as copy or re-use as specified. PtrList(PtrList<T>&, bool reUse); @@ -161,6 +161,17 @@ public: //- 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 @@ -181,11 +192,11 @@ public: void clear(); //- Transfer the contents of the argument PtrList into this PtrList - // and annull the argument list. + // and annul the argument list. void transfer(PtrList<T>&); //- Transfer contents to the Xfer container - inline Xfer<PtrList<T> > xfer(); + inline Xfer< PtrList<T> > xfer(); //- Is element set inline bool set(const label) const; diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H index d450cdd09fe..72cb24f78dd 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListI.H @@ -45,6 +45,34 @@ inline bool Foam::PtrList<T>::empty() const } +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) { @@ -63,9 +91,7 @@ template<class T> inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr) { autoPtr<T> old(ptrs_[i]); - ptrs_[i] = ptr; - return old; } @@ -102,7 +128,7 @@ inline Foam::Xfer<Foam::PtrList<T> > Foam::PtrList<T>::xfer() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class T> -const T& Foam::PtrList<T>::operator[](const label i) const +inline const T& Foam::PtrList<T>::operator[](const label i) const { if (!ptrs_[i]) { @@ -116,7 +142,7 @@ const T& Foam::PtrList<T>::operator[](const label i) const template<class T> -T& Foam::PtrList<T>::operator[](const label i) +inline T& Foam::PtrList<T>::operator[](const label i) { if (!ptrs_[i]) { @@ -130,7 +156,7 @@ T& Foam::PtrList<T>::operator[](const label i) template<class T> -const T* Foam::PtrList<T>::operator()(const label i) const +inline const T* Foam::PtrList<T>::operator()(const label i) const { return ptrs_[i]; } @@ -297,5 +323,4 @@ Foam::PtrList<T>::end() } - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H index 0219e02af72..61ec6bf2d14 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H @@ -27,6 +27,7 @@ Class Description A List with indirect addressing. + Like IndirectList but does not store addressing. SourceFiles @@ -73,8 +74,24 @@ public: // Access + //- Return the number of elements in the list inline label size() const; - inline bool empty() const; + + //- Return true if the list is empty (ie, size() is zero). + inline bool empty() const; + + //- Return the first element of the list. + inline T& first(); + + //- Return first element of the list. + inline const T& first() const; + + //- Return the last element of the list. + inline T& last(); + + //- Return the last element of the list. + inline const T& last() const; + inline const UList<T>& completeList() const; inline const List<label>& addressing() const; diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H index ff8b3ebbd6d..e8e7565ed13 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H @@ -54,6 +54,34 @@ inline bool Foam::UIndirectList<T>::empty() const } +template<class T> +inline T& Foam::UIndirectList<T>::first() +{ + return completeList_[addressing_.first()]; +} + + +template<class T> +inline const T& Foam::UIndirectList<T>::first() const +{ + return completeList_[addressing_.first()]; +} + + +template<class T> +inline T& Foam::UIndirectList<T>::last() +{ + return completeList_[addressing_.last()]; +} + + +template<class T> +inline const T& Foam::UIndirectList<T>::last() const +{ + return completeList_[addressing_.last()]; +} + + template<class T> inline const Foam::UList<T>& Foam::UIndirectList<T>::completeList() const { diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index b829c99ea5f..b9332d04c2e 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -132,7 +132,7 @@ public: inline label fcIndex(const label i) const; //- Return the reverse circular index, i.e. the previous index - // which returns to the last at the begining of the list + // which returns to the last at the beginning of the list inline label rcIndex(const label i) const; //- Return the binary size in number of characters of the UList @@ -151,6 +151,18 @@ public: // This can be used (with caution) when interfacing with C code. inline T* data(); + //- Return the first element of the list. + inline T& first(); + + //- Return first element of the list. + inline const T& first() const; + + //- Return the last element of the list. + inline T& last(); + + //- Return the last element of the list. + inline const T& last() const; + // Check @@ -184,12 +196,6 @@ public: // an out-of-range element returns false without any ill-effects inline const T& operator[](const label) const; - //- Return last element of UList. - inline T& last(); - - //- Return last element of UList. - inline const T& last() const; - //- Allow cast to a const List<T>& inline operator const Foam::List<T>&() const; diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index aa7d396f105..fb68f29ee86 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -114,6 +114,20 @@ inline void Foam::UList<T>::checkIndex(const label i) const } +template<class T> +inline T& Foam::UList<T>::first() +{ + return this->operator[](0); +} + + +template<class T> +inline const T& Foam::UList<T>::first() const +{ + return this->operator[](0); +} + + template<class T> inline T& Foam::UList<T>::last() { diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C index bed0214749e..93b7a514c66 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C @@ -93,8 +93,6 @@ void Foam::UPtrList<T>::clear() } -// Transfer the contents of the argument List into this List -// and anull the argument list template<class T> void Foam::UPtrList<T>::transfer(UPtrList<T>& a) { diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index a334e812543..eaf70c3b05b 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -26,8 +26,8 @@ Class Foam::UPtrList Description - A 1D array of pointers to objects of type \<T\>, where the size of the - array is known and used for subscript bounds checking, etc. + A templated 1D list of pointers to objects of type \<T\>, where the + size of the array is known and used for subscript bounds checking, etc. The element operator [] returns a reference to the object rather than a pointer. Storage is not allocated during construction or use but is @@ -107,11 +107,11 @@ public: //- Null Constructor. UPtrList(); - //- Construct with length specified. + //- Construct with size specified. explicit UPtrList(const label); //- Construct by transferring the parameter contents - UPtrList(const Xfer<UPtrList<T> >&); + UPtrList(const Xfer< UPtrList<T> >&); //- Construct as copy or re-use as specified. UPtrList(UPtrList<T>&, bool reUse); @@ -127,6 +127,18 @@ public: //- Return true if the UPtrList 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 @@ -144,11 +156,11 @@ public: void clear(); //- Transfer the contents of the argument UPtrList into this - // UPtrList and annull the argument list. + // UPtrList and annul the argument list. void transfer(UPtrList<T>&); //- Transfer contents to the Xfer container - inline Xfer<UPtrList<T> > xfer(); + inline Xfer< UPtrList<T> > xfer(); //- Is element set inline bool set(const label) const; diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H index 859f54fce5f..1d73bc920da 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrListI.H @@ -42,6 +42,34 @@ inline bool Foam::UPtrList<T>::empty() const } +template<class T> +inline T& Foam::UPtrList<T>::first() +{ + return this->operator[](0); +} + + +template<class T> +inline const T& Foam::UPtrList<T>::first() const +{ + return this->operator[](0); +} + + +template<class T> +inline T& Foam::UPtrList<T>::last() +{ + return this->operator[](this->size()-1); +} + + +template<class T> +inline const T& Foam::UPtrList<T>::last() const +{ + return this->operator[](this->size()-1); +} + + template<class T> inline void Foam::UPtrList<T>::resize(const label newSize) { @@ -55,6 +83,7 @@ inline bool Foam::UPtrList<T>::set(const label i) const return ptrs_[i] != NULL; } + template<class T> inline T* Foam::UPtrList<T>::set(const label i, T* ptr) { @@ -63,6 +92,7 @@ inline T* Foam::UPtrList<T>::set(const label i, T* ptr) return old; } + template<class T> inline Foam::Xfer<Foam::UPtrList<T> > Foam::UPtrList<T>::xfer() { @@ -73,7 +103,7 @@ inline Foam::Xfer<Foam::UPtrList<T> > Foam::UPtrList<T>::xfer() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class T> -const T& Foam::UPtrList<T>::operator[](const label i) const +inline const T& Foam::UPtrList<T>::operator[](const label i) const { if (!ptrs_[i]) { @@ -87,7 +117,7 @@ const T& Foam::UPtrList<T>::operator[](const label i) const template<class T> -T& Foam::UPtrList<T>::operator[](const label i) +inline T& Foam::UPtrList<T>::operator[](const label i) { if (!ptrs_[i]) { @@ -101,7 +131,7 @@ T& Foam::UPtrList<T>::operator[](const label i) template<class T> -const T* Foam::UPtrList<T>::operator()(const label i) const +inline const T* Foam::UPtrList<T>::operator()(const label i) const { return ptrs_[i]; } -- GitLab