ENH: cleanup List constructors (issue #725)

- add copy construct from UList

- remove copy construct from dissimilar types.

  This templated constructor was too generous in what it accepted.
  For the special cases where a copy constructor is required with
  a change in the data type, now use the createList factory method,
  which accepts a unary operator. Eg,

      auto scalars = scalarList::createList
      (
          labels,
          [](const label& val){ return 1.5*val; }
      );
This commit is contained in:
Mark Olesen
2018-02-08 08:53:14 +01:00
parent e2332d6bd2
commit e42c228155
10 changed files with 398 additions and 129 deletions

View File

@ -48,6 +48,23 @@ See also
#include <list> #include <list>
#include <numeric> #include <numeric>
#include <functional>
namespace Foam
{
// Verify inheritance
class MyStrings
:
public List<string>
{
public:
using List<string>::List;
};
} // end namespace Foam
using namespace Foam; using namespace Foam;
@ -66,6 +83,14 @@ void testFind(const T& val, const ListType& lst)
} }
void printMyString(const UList<string>& lst)
{
MyStrings slist2(lst);
Info<<slist2 << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
@ -76,6 +101,7 @@ int main(int argc, char *argv[])
argList::addOption("wordList", "wordList"); argList::addOption("wordList", "wordList");
argList::addOption("stringList", "stringList"); argList::addOption("stringList", "stringList");
argList::addOption("float", "xx"); argList::addOption("float", "xx");
argList::addBoolOption("transform", "Test List::createList functionality");
argList::addBoolOption("flag"); argList::addBoolOption("flag");
#include "setRootCase.H" #include "setRootCase.H"
@ -336,6 +362,85 @@ int main(int argc, char *argv[])
Info<<"-flag:" << args["flag"] << endl; Info<<"-flag:" << args["flag"] << endl;
} }
if (args.found("transform"))
{
Info<< nl << "Test List::createList functionality" << nl;
const auto labels = identity(15);
Info<< "labels: " << flatOutput(labels) << endl;
{
auto scalars = List<scalar>::createList
(
labels,
[](const label& val){ return scalar(1.5*val); }
);
Info<< "scalars: " << flatOutput(scalars) << endl;
}
{
auto vectors = List<vector>::createList
(
labels,
[](const label& val){ return vector(1.2*val, -1.2*val, 0); }
);
Info<< "vectors: " << flatOutput(vectors) << endl;
}
{
auto longs = List<long>::createList
(
labels,
[](const label& val){ return val; }
);
Info<< "longs: " << flatOutput(longs) << endl;
}
{
auto negs = List<label>::createList
(
labels,
std::negate<label>()
);
Info<< "negs: " << flatOutput(negs) << endl;
}
{
auto scalars = List<scalar>::createList
(
labelRange::null.cbegin(),
labelRange::identity(15).cend(),
[](const label& val){ return scalar(-1.125*val); }
);
Info<< "scalars: " << flatOutput(scalars) << endl;
}
#if WM_LABEL_SIZE == 32
{
List<int64_t> input(10);
std::iota(input.begin(), input.end(), 0);
auto output = List<label>::createList
(
input,
toLabel<int64_t>()
);
Info<< "label (from int64): " << flatOutput(output) << endl;
}
#elif WM_LABEL_SIZE == 64
{
List<int32_t> input(10);
std::iota(input.begin(), input.end(), 0);
auto output = List<label>::createList
(
input,
toLabel<int32_t>()
);
Info<< "label (from int32): " << flatOutput(output) << endl;
}
#endif
}
if (args.readIfPresent<scalar>("float", xxx)) if (args.readIfPresent<scalar>("float", xxx))
{ {
Info<<"read float " << xxx << endl; Info<<"read float " << xxx << endl;
@ -354,6 +459,8 @@ int main(int argc, char *argv[])
if (args.found("stringList")) if (args.found("stringList"))
{ {
sLst = args.readList<string>("stringList"); sLst = args.readList<string>("stringList");
printMyString(sLst);
} }
Info<< nl Info<< nl

View File

@ -1007,7 +1007,11 @@ Foam::label Foam::checkGeometry
globalFaces().gather globalFaces().gather
( (
UPstream::worldComm, UPstream::worldComm,
labelList(UPstream::procID(UPstream::worldComm)), labelList::createList
(
UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label
),
ami.srcWeightsSum(), ami.srcWeightsSum(),
mergedWeights mergedWeights
); );
@ -1057,7 +1061,11 @@ Foam::label Foam::checkGeometry
globalFaces().gather globalFaces().gather
( (
UPstream::worldComm, UPstream::worldComm,
labelList(UPstream::procID(UPstream::worldComm)), labelList::createList
(
UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label
),
ami.tgtWeightsSum(), ami.tgtWeightsSum(),
mergedWeights mergedWeights
); );

View File

@ -84,7 +84,11 @@ void writeWeights
globalFaces().gather globalFaces().gather
( (
UPstream::worldComm, UPstream::worldComm,
labelList(UPstream::procID(UPstream::worldComm)), labelList::createList
(
UPstream::procID(UPstream::worldComm),
toLabel<int>() // int -> label
),
wghtSum, wghtSum,
mergedWeights mergedWeights
); );

View File

@ -162,13 +162,13 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
} }
// Reduction for non-empty strings // Reduction for non-empty strings.
class uniqueEqOp template<class StringType>
struct uniqueEqOp
{ {
public: void operator()(List<StringType>& x, const List<StringType>& y) const
void operator()(stringList& x, const stringList& y) const
{ {
stringList newX(x.size()+y.size()); List<StringType> newX(x.size()+y.size());
label n = 0; label n = 0;
forAll(x, i) forAll(x, i)
{ {
@ -215,8 +215,8 @@ bool writeOptionalMeshObject
bool haveFile = io.typeHeaderOk<IOField<label>>(false); bool haveFile = io.typeHeaderOk<IOField<label>>(false);
// Make sure all know if there is a valid class name // Make sure all know if there is a valid class name
stringList classNames(1, io.headerClassName()); wordList classNames(1, io.headerClassName());
combineReduce(classNames, uniqueEqOp()); combineReduce(classNames, uniqueEqOp<word>());
// Check for correct type // Check for correct type
if (classNames[0] == T::typeName) if (classNames[0] == T::typeName)
@ -395,7 +395,7 @@ int main(int argc, char *argv[])
// Check for lagrangian // Check for lagrangian
stringList lagrangianDirs fileNameList lagrangianDirs
( (
1, 1,
fileHandler().filePath fileHandler().filePath
@ -406,7 +406,7 @@ int main(int argc, char *argv[])
) )
); );
combineReduce(lagrangianDirs, uniqueEqOp()); combineReduce(lagrangianDirs, uniqueEqOp<fileName>());
if (!lagrangianDirs.empty()) if (!lagrangianDirs.empty())
{ {
@ -434,7 +434,7 @@ int main(int argc, char *argv[])
); );
} }
stringList cloudDirs fileNameList cloudDirs
( (
fileHandler().readDir fileHandler().readDir
( (
@ -443,7 +443,7 @@ int main(int argc, char *argv[])
) )
); );
combineReduce(cloudDirs, uniqueEqOp()); combineReduce(cloudDirs, uniqueEqOp<fileName>());
forAll(cloudDirs, i) forAll(cloudDirs, i)
{ {
@ -464,13 +464,11 @@ int main(int argc, char *argv[])
IOobjectList sprayObjs(runTime, runTime.timeName(), dir); IOobjectList sprayObjs(runTime, runTime.timeName(), dir);
// Combine with all other cloud objects // Combine with all other cloud objects
stringList sprayFields(sprayObjs.sortedToc()); wordList sprayFields(sprayObjs.sortedToc());
combineReduce(sprayFields, uniqueEqOp()); combineReduce(sprayFields, uniqueEqOp<word>());
forAll(sprayFields, fieldi) for (const word& name : sprayFields)
{ {
const word& name = sprayFields[fieldi];
// Note: try the various field types. Make sure to // Note: try the various field types. Make sure to
// exit once sucessful conversion to avoid re-read // exit once sucessful conversion to avoid re-read
// converted file. // converted file.

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,17 +35,76 @@ License
#include <utility> #include <utility>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
template<class T2, class UnaryOperation>
Foam::List<T> Foam::List<T>::createList
(
const UList<T2>& input,
const UnaryOperation& op
)
{
const label len = input.size();
List<T> output(len);
if (len)
{
List_ACCESS(T, output, out);
List_CONST_ACCESS(T2, input, in);
for (label i = 0; i < len; ++i)
{
out[i] = op(in[i]);
}
}
return output;
}
template<class T>
template<class InputIterator, class UnaryOperation>
Foam::List<T> Foam::List<T>::createList
(
InputIterator begIter,
InputIterator endIter,
const UnaryOperation& op
)
{
const label len = std::distance(begIter, endIter);
List<T> output(len);
if (len)
{
List_ACCESS(T, output, out);
InputIterator iter = begIter;
for (label i = 0; i < len; ++i)
{
out[i] = op(*iter);
++iter;
}
}
return output;
}
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T> template<class T>
Foam::List<T>::List(const label s) Foam::List<T>::List(const label len)
: :
UList<T>(nullptr, s) UList<T>(nullptr, len)
{ {
if (this->size_ < 0) if (len < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "bad size " << this->size_ << "bad size " << len
<< abort(FatalError); << abort(FatalError);
} }
@ -54,23 +113,23 @@ Foam::List<T>::List(const label s)
template<class T> template<class T>
Foam::List<T>::List(const label s, const T& val) Foam::List<T>::List(const label len, const T& val)
: :
UList<T>(nullptr, s) UList<T>(nullptr, len)
{ {
if (this->size_ < 0) if (len < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "bad size " << this->size_ << "bad size " << len
<< abort(FatalError); << abort(FatalError);
} }
if (len)
{
alloc(); alloc();
if (this->size_)
{
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i) for (label i=0; i < len; ++i)
{ {
vp[i] = val; vp[i] = val;
} }
@ -79,23 +138,23 @@ Foam::List<T>::List(const label s, const T& val)
template<class T> template<class T>
Foam::List<T>::List(const label s, const zero) Foam::List<T>::List(const label len, const zero)
: :
UList<T>(nullptr, s) UList<T>(nullptr, len)
{ {
if (this->size_ < 0) if (len < 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "bad size " << this->size_ << "bad size " << len
<< abort(FatalError); << abort(FatalError);
} }
if (len)
{
alloc(); alloc();
if (this->size_)
{
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i) for (label i=0; i < len; ++i)
{ {
vp[i] = Zero; vp[i] = Zero;
} }
@ -103,6 +162,34 @@ Foam::List<T>::List(const label s, const zero)
} }
template<class T>
Foam::List<T>::List(const UList<T>& a)
:
UList<T>(nullptr, a.size_)
{
if (this->size_)
{
alloc();
#ifdef USEMEMCPY
if (contiguous<T>())
{
memcpy(this->v_, a.v_, this->byteSize());
}
else
#endif
{
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i)
{
vp[i] = ap[i];
}
}
}
}
template<class T> template<class T>
Foam::List<T>::List(const List<T>& a) Foam::List<T>::List(const List<T>& a)
: :
@ -131,26 +218,6 @@ Foam::List<T>::List(const List<T>& a)
} }
template<class T>
template<class T2>
Foam::List<T>::List(const List<T2>& a)
:
UList<T>(nullptr, a.size())
{
if (this->size_)
{
alloc();
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T2, a, ap);
List_FOR_ALL((*this), i)
{
vp[i] = T(ap[i]);
}
}
}
template<class T> template<class T>
Foam::List<T>::List(List<T>& a, bool reuse) Foam::List<T>::List(List<T>& a, bool reuse)
: :
@ -191,13 +258,14 @@ Foam::List<T>::List(const UList<T>& lst, const labelUList& mapAddressing)
: :
UList<T>(nullptr, mapAddressing.size()) UList<T>(nullptr, mapAddressing.size())
{ {
if (this->size_) const label len = mapAddressing.size();
if (len)
{ {
alloc(); alloc();
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
const label len = (*this).size();
for (label i=0; i < len; ++i) for (label i=0; i < len; ++i)
{ {
vp[i] = lst[mapAddressing[i]]; vp[i] = lst[mapAddressing[i]];
@ -220,7 +288,8 @@ Foam::List<T>::List(const FixedList<T, Size>& lst)
: :
UList<T>(nullptr, Size) UList<T>(nullptr, Size)
{ {
allocCopyList(lst); alloc();
copyList(lst);
} }
@ -229,7 +298,8 @@ Foam::List<T>::List(const PtrList<T>& lst)
: :
UList<T>(nullptr, lst.size()) UList<T>(nullptr, lst.size())
{ {
allocCopyList(lst); alloc();
copyList(lst);
} }
@ -245,7 +315,8 @@ Foam::List<T>::List(const UIndirectList<T>& lst)
: :
UList<T>(nullptr, lst.size()) UList<T>(nullptr, lst.size())
{ {
allocCopyList(lst); alloc();
copyList(lst);
} }
@ -254,7 +325,8 @@ Foam::List<T>::List(const BiIndirectList<T>& lst)
: :
UList<T>(nullptr, lst.size()) UList<T>(nullptr, lst.size())
{ {
allocCopyList(lst); alloc();
copyList(lst);
} }
@ -329,7 +401,7 @@ void Foam::List<T>::setSize(const label newSize)
{ {
if (newSize > 0) if (newSize > 0)
{ {
T* nv = new T[label(newSize)]; T* nv = new T[newSize];
const label overlap = min(this->size_, newSize); const label overlap = min(this->size_, newSize);
@ -367,7 +439,7 @@ void Foam::List<T>::setSize(const label newSize)
template<class T> template<class T>
void Foam::List<T>::setSize(const label newSize, const T& val) void Foam::List<T>::setSize(const label newSize, const T& val)
{ {
const label oldSize = label(this->size_); const label oldSize = this->size_;
this->setSize(newSize); this->setSize(newSize);
List_ACCESS(T, *this, vp); List_ACCESS(T, *this, vp);
@ -474,28 +546,58 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
template<class T> template<class T>
void Foam::List<T>::operator=(const UIndirectList<T>& lst) void Foam::List<T>::operator=(const UIndirectList<T>& lst)
{ {
reAlloc(lst.size()); const label len = lst.size();
copyList(lst);
reAlloc(len);
if (len)
{
List_ACCESS(T, (*this), vp);
for (label i=0; i<len; ++i)
{
vp[i] = lst[i];
}
}
} }
template<class T> template<class T>
void Foam::List<T>::operator=(const BiIndirectList<T>& lst) void Foam::List<T>::operator=(const BiIndirectList<T>& lst)
{ {
reAlloc(lst.size()); const label len = lst.size();
copyList(lst);
reAlloc(len);
if (len)
{
List_ACCESS(T, (*this), vp);
for (label i=0; i<len; ++i)
{
vp[i] = lst[i];
}
}
} }
template<class T> template<class T>
void Foam::List<T>::operator=(std::initializer_list<T> lst) void Foam::List<T>::operator=(std::initializer_list<T> lst)
{ {
reAlloc(lst.size()); const label len = lst.size();
reAlloc(len);
if (len)
{
List_ACCESS(T, (*this), vp);
label i = 0; label i = 0;
for (const auto& val : lst) for (const auto& val : lst)
{ {
this->operator[](i++) = val; vp[i] = val;
++i;
}
} }
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,16 +50,12 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class Istream; class Istream;
class Ostream; class Ostream;
// Forward declaration of friend functions and operators
template<class T> class List; template<class T> class List;
template<class T> Istream& operator>>(Istream& is, List<T>& L);
template<class T, unsigned Size> class FixedList; template<class T, unsigned Size> class FixedList;
template<class T> class PtrList; template<class T> class PtrList;
@ -75,8 +71,11 @@ template<class T> class IndirectList;
template<class T> class UIndirectList; template<class T> class UIndirectList;
template<class T> class BiIndirectList; template<class T> class BiIndirectList;
template<class T> Istream& operator>>(Istream& is, List<T>& L);
typedef List<char> charList; typedef List<char> charList;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class List Declaration Class List Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -92,16 +91,12 @@ class List
inline void alloc(); inline void alloc();
//- Reallocate list storage to the given size //- Reallocate list storage to the given size
inline void reAlloc(const label s); inline void reAlloc(const label len);
//- Copy list of given type //- Copy list of given type.
template<class List2> template<class List2>
inline void copyList(const List2& lst); inline void copyList(const List2& lst);
//- Allocate storage and copy list of given type
template<class List2>
inline void allocCopyList(const List2& lst);
//- Construct given begin/end iterators and number of elements //- Construct given begin/end iterators and number of elements
// Since the size is provided, the end iterator is actually ignored. // Since the size is provided, the end iterator is actually ignored.
template<class InputIterator> template<class InputIterator>
@ -109,7 +104,7 @@ class List
( (
InputIterator begIter, InputIterator begIter,
InputIterator endIter, InputIterator endIter,
const label s const label len
); );
@ -120,6 +115,44 @@ public:
//- Return a null List //- Return a null List
inline static const List<T>& null(); inline static const List<T>& null();
//- Create from a list of a dissimilar type.
// Eg, convert a list of ints to floats, vectors etc.
// For example,
// \code
// auto vectors = List<vector>::createList
// (
// ints,
// [](const int& val){ return vector(1.5*val, 0, 0); }
// );
//
// auto neg = labelList::createList
// (
// ints,
// std::negate<label>()
// );
// auto labels = labelList::createList
// (
// ints,
// toLabel<int>()
// );
// \endcode
template<class T2, class UnaryOperation>
static List<T> createList
(
const UList<T2>& input,
const UnaryOperation& op
);
//- Create from an iterator range (uses std::distance for the size).
// The unary operation can be used to convert to other types.
template<class InputIterator, class UnaryOperation>
static List<T> createList
(
InputIterator begIter,
InputIterator endIter,
const UnaryOperation& op
);
// Constructors // Constructors
@ -127,22 +160,19 @@ public:
inline List(); inline List();
//- Construct with given size //- Construct with given size
explicit List(const label s); explicit List(const label len);
//- Construct with given size and value for all elements //- Construct with given size and value for all elements
List(const label s, const T& val); List(const label len, const T& val);
//- Construct with given size initializing all elements to zero //- Construct with given size initializing all elements to zero
List(const label s, const zero); List(const label len, const zero);
//- Copy constructor from list //- Copy construct from list
List(const List<T>& a); List(const List<T>& a);
//- Copy constructor from list containing another type. //- Copy construct contents from list
// This is primarily useful to convert a list of ints into floats, explicit List(const UList<T>& a);
// for example.
template<class T2>
explicit List(const List<T2>& a);
//- Construct as copy or re-use as specified //- Construct as copy or re-use as specified
List(List<T>& a, bool reuse); List(List<T>& a, bool reuse);
@ -151,7 +181,7 @@ public:
List(const UList<T>& lst, const labelUList& mapAddressing); List(const UList<T>& lst, const labelUList& mapAddressing);
//- Construct given begin/end iterators. //- Construct given begin/end iterators.
// Uses std::distance to determine the size. // Uses std::distance for the size.
template<class InputIterator> template<class InputIterator>
List(InputIterator begIter, InputIterator endIter); List(InputIterator begIter, InputIterator endIter);

View File

@ -36,12 +36,12 @@ inline void Foam::List<T>::alloc()
template<class T> template<class T>
inline void Foam::List<T>::reAlloc(const label s) inline void Foam::List<T>::reAlloc(const label len)
{ {
if (this->size_ != s) if (this->size_ != len)
{ {
clear(); clear();
this->size_ = s; this->size_ = len;
alloc(); alloc();
} }
} }
@ -51,26 +51,13 @@ template<class T>
template<class List2> template<class List2>
inline void Foam::List<T>::copyList(const List2& lst) inline void Foam::List<T>::copyList(const List2& lst)
{ {
if (this->size_) const label len = this->size_;
{
forAll(*this, i) for (label i=0; i<len; ++i)
{ {
this->operator[](i) = lst[i]; this->operator[](i) = lst[i];
} }
} }
}
template<class T>
template<class List2>
inline void Foam::List<T>::allocCopyList(const List2& lst)
{
if (this->size_)
{
alloc();
copyList(lst);
}
}
template<class T> template<class T>
@ -79,17 +66,17 @@ inline Foam::List<T>::List
( (
InputIterator begIter, InputIterator begIter,
InputIterator endIter, InputIterator endIter,
const label s const label len
) )
: :
UList<T>(nullptr, s) UList<T>(nullptr, len)
{ {
if (this->size_) if (this->size_)
{ {
alloc(); alloc();
InputIterator iter = begIter; InputIterator iter = begIter;
for (label i = 0; i < s; ++i) for (label i = 0; i < len; ++i)
{ {
this->operator[](i) = *iter; this->operator[](i) = *iter;
++iter; ++iter;
@ -135,16 +122,16 @@ inline void Foam::List<T>::clear()
template<class T> template<class T>
inline void Foam::List<T>::resize(const label newSize) inline void Foam::List<T>::resize(const label len)
{ {
this->setSize(newSize); this->setSize(len);
} }
template<class T> template<class T>
inline void Foam::List<T>::resize(const label newSize, const T& val) inline void Foam::List<T>::resize(const label len, const T& val)
{ {
this->setSize(newSize, val); this->setSize(len, val);
} }

View File

@ -25,7 +25,6 @@ License
#include "ListOps.H" #include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::labelList Foam::emptyLabelList; const Foam::labelList Foam::emptyLabelList;

View File

@ -141,10 +141,10 @@ void Foam::Time::readDict()
) )
{ {
// Remove the old watches since destroying the file // Remove the old watches since destroying the file
fileNameList oldWatchedFiles(controlDict_.watchIndices()); fileNameList oldWatchedFiles(controlDict_.watchIndices().size());
forAllReverse(controlDict_.watchIndices(), i) forAllReverse(controlDict_.watchIndices(), i)
{ {
label watchi = controlDict_.watchIndices()[i]; const label watchi = controlDict_.watchIndices()[i];
oldWatchedFiles[i] = fileHandler().getFile(watchi); oldWatchedFiles[i] = fileHandler().getFile(watchi);
fileHandler().removeWatch(watchi); fileHandler().removeWatch(watchi);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -120,6 +120,40 @@ inline label component(const label l, const direction)
return l; return l;
} }
/*---------------------------------------------------------------------------*\
Struct toLabel Declaration
\*---------------------------------------------------------------------------*/
//- Conversion to label structure
template<class Type> struct toLabel {};
//- Convert (likely promote) from int32_t to label
template<>
struct toLabel<int32_t>
{
constexpr label operator()(const int32_t& val) const noexcept
{
return val;
}
};
//- Convert (possibly truncate) from int64_t to label
template<>
struct toLabel<int64_t>
{
constexpr label operator()(const int64_t& val) const noexcept
{
#if WM_LABEL_SIZE == 32
return label(val);
#elif WM_LABEL_SIZE == 64
return val;
#endif
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam