Commit b2d7439b authored by Mark Olesen's avatar Mark Olesen
Browse files

Lists get first() and last() member functions

- this builds on Mattijs' commit 968f0bbd 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.
parent 1c6dd6de
......@@ -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
......
......@@ -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();
......
......@@ -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
......
......@@ -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>&);
......
......@@ -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
......
......@@ -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>&);
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
{
......
......@@ -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)
{
......
......@@ -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
......
......@@ -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
......
......@@ -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;
......
......@@ -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()
}
// ************************************************************************* //
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment