Commit 8060826b authored by Henry Weller's avatar Henry Weller
Browse files

LList, SLList: Added construction from and assignment to initializer_list

SLList: now a C++11 template alias rather than a wrapper-class.
parent 3d742e78
......@@ -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
......@@ -39,7 +39,8 @@ using namespace Foam;
int main(int argc, char *argv[])
{
SLList<scalar> myList;
SLList<scalar> myList{2.1, 3.4};
myList = {2.1, 3.4, 4.3};
for (int i = 0; i<10; i++)
{
......
......@@ -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
......@@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "LList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -33,9 +32,21 @@ Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
:
LListBase()
{
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
for (const T& val : lst)
{
this->append(iter());
this->append(val);
}
}
template<class LListBase, class T>
Foam::LList<LListBase, T>::LList(std::initializer_list<T> lst)
:
LListBase()
{
for (const T& val : lst)
{
this->append(val);
}
}
......@@ -77,9 +88,21 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
{
this->clear();
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
for (const T& val : lst)
{
this->append(iter());
this->append(val);
}
}
template<class LListBase, class T>
void Foam::LList<LListBase, T>::operator=(std::initializer_list<T> lst)
{
this->clear();
for (const T& val : lst)
{
this->append(val);
}
}
......@@ -88,5 +111,4 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
#include "LListIO.C"
// ************************************************************************* //
......@@ -37,7 +37,7 @@ SourceFiles
#define LList_H
#include "label.H"
#include "uLabel.H"
#include <initializer_list>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -121,6 +121,9 @@ public:
//- Construct as copy
LList(const LList<LListBase, T>&);
//- Construct from an initializer list
LList(std::initializer_list<T>);
//- Destructor
~LList();
......@@ -206,8 +209,12 @@ public:
// Member operators
//- Assignment operator
void operator=(const LList<LListBase, T>&);
//- Assignment to an initializer list
void operator=(std::initializer_list<T>);
// STL type definitions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -144,14 +144,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
os << nl << token::BEGIN_LIST << nl;
// Write contents
for
(
typename LList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
for (const T& val : lst)
{
os << iter() << nl;
os << val << nl;
}
// Write end of contents
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -21,7 +21,7 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Alias
Foam::SLList
Description
......@@ -39,42 +39,9 @@ Description
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class SLList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class SLList
:
public LList<SLListBase, T>
{
public:
// Constructors
//- Null construct
SLList()
{}
//- Construct given initial T
explicit SLList(T a)
:
LList<SLListBase, T>(a)
{}
//- Construct from Istream
explicit SLList(Istream& is)
:
LList<SLListBase, T>(is)
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
template<class T>
using SLList = LList<SLListBase, T>;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -61,8 +61,11 @@ template<class T, unsigned Size>
Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
template<class T> class UList;
template<class T> class SLList;
class SLListBase;
template<class LListBase, class T> class LList;
template<class T>
using SLList = LList<SLListBase, T>;
/*---------------------------------------------------------------------------*\
Class FixedList Declaration
......@@ -219,16 +222,16 @@ public:
//- Return element of constant FixedList
inline const T& operator[](const label) const;
//- Assignment from array operator. Takes linear time
//- Assignment to array operator. Takes linear time
inline void operator=(const T v[Size]);
//- Assignment from UList operator. Takes linear time
//- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>&);
//- Assignment from SLList operator. Takes linear time
//- Assignment to SLList operator. Takes linear time
inline void operator=(const SLList<T>&);
//- Assignment from an initializer list. Takes linear time
//- Assignment to an initializer list. Takes linear time
inline void operator=(std::initializer_list<T>);
//- Assignment of all entries to the given value
......
......@@ -62,7 +62,11 @@ template<class T> Istream& operator>>(Istream&, List<T>&);
template<class T, unsigned Size> class FixedList;
template<class T> class PtrList;
template<class T> class SLList;
class SLListBase;
template<class LListBase, class T> class LList;
template<class T>
using SLList = LList<SLListBase, T>;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
class DynamicList;
......@@ -247,22 +251,22 @@ public:
// Member operators
//- Assignment from UList operator. Takes linear time
//- Assignment to UList operator. Takes linear time
void operator=(const UList<T>&);
//- Assignment operator. Takes linear time
void operator=(const List<T>&);
//- Assignment from SLList operator. Takes linear time
//- Assignment to SLList operator. Takes linear time
void operator=(const SLList<T>&);
//- Assignment from UIndirectList operator. Takes linear time
//- Assignment to UIndirectList operator. Takes linear time
void operator=(const UIndirectList<T>&);
//- Assignment from BiIndirectList operator. Takes linear time
//- Assignment to BiIndirectList operator. Takes linear time
void operator=(const BiIndirectList<T>&);
//- Construct from an initializer list
//- Assignment to an initializer list
void operator=(std::initializer_list<T>);
//- Assignment of all entries to the given value
......
......@@ -157,7 +157,7 @@ void Foam::ParticleCollector<CloudType>::initConcentricCircles()
vector origin(this->coeffDict().lookup("origin"));
radius_ = this->coeffDict().lookup("radius");
this->coeffDict().lookup("radius") >> radius_;
nSector_ = readLabel(this->coeffDict().lookup("nSector"));
label nS = nSector_;
......
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