Commit 68e75338 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: include <utility> in stdFoam, formatting of list loop macros

parent 24577907
......@@ -35,10 +35,11 @@ void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a)
List_ACCESS(T, a, ap);
T tmp;
List_FOR_ALL((*this), i)
{
tmp = List_CELEM((*this), vp, i);
List_ELEM((*this), vp, i) = List_CELEM(a, ap, i);
List_ELEM(a, ap, i) = tmp;
List_END_FOR_ALL
}
}
......@@ -53,9 +54,10 @@ bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const
List_CONST_ACCESS(T, (a), ap);
List_FOR_ALL((*this), i)
{
equal = (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
if (!equal) break;
List_END_FOR_ALL
}
return equal;
}
......
......@@ -69,8 +69,9 @@ Foam::List<T>::List(const label s, const T& a)
{
List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = a;
List_END_FOR_ALL
}
}
}
......@@ -93,8 +94,9 @@ Foam::List<T>::List(const label s, const zero)
{
List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = Zero;
List_END_FOR_ALL
}
}
}
......@@ -119,8 +121,9 @@ Foam::List<T>::List(const List<T>& a)
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
List_END_FOR_ALL
}
}
}
}
......@@ -139,8 +142,9 @@ Foam::List<T>::List(const List<T2>& a)
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T2, a, ap);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = T(List_ELEM(a, ap, i));
List_END_FOR_ALL
}
}
}
......@@ -178,8 +182,9 @@ Foam::List<T>::List(List<T>& a, bool reuse)
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
List_END_FOR_ALL
}
}
}
}
......@@ -390,8 +395,9 @@ void Foam::List<T>::operator=(const UList<T>& a)
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
List_END_FOR_ALL
}
}
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -37,10 +37,7 @@ Description
#define List_FOR_ALL(f, i) \
const label _n##i = (f).size(); \
for (label i=0; i<_n##i; ++i) \
{
#define List_END_FOR_ALL }
for (label i=0; i<_n##i; ++i)
// Provide current element
#define List_CELEM(f, fp, i) (fp[i])
......@@ -60,10 +57,7 @@ Description
#define List_FOR_ALL(f, i) \
label i = (f).size(); \
while (i--) \
{ \
#define List_END_FOR_ALL }
while (i--)
// Provide current element without incrementing pointer
#define List_CELEM(f, fp, i) (*fp)
......
......@@ -95,8 +95,9 @@ void Foam::UList<T>::deepCopy(const UList<T>& a)
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
List_END_FOR_ALL
}
}
}
}
......@@ -152,8 +153,9 @@ void Foam::UList<T>::operator=(const T& t)
{
List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = t;
List_END_FOR_ALL
}
}
......@@ -162,8 +164,9 @@ void Foam::UList<T>::operator=(const zero)
{
List_ACCESS(T, (*this), vp);
List_FOR_ALL((*this), i)
{
List_ELEM((*this), vp, i) = Zero;
List_END_FOR_ALL
}
}
......@@ -244,9 +247,10 @@ bool Foam::UList<T>::operator==(const UList<T>& a) const
List_CONST_ACCESS(T, (a), ap);
List_FOR_ALL((*this), i)
{
equal = (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
if (!equal) break;
List_END_FOR_ALL
}
return equal;
}
......
......@@ -120,8 +120,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP FUNC(List_ELEM(f2, f2P, i)); \
List_END_FOR_ALL \
}
#define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC) \
......@@ -135,13 +136,14 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i).FUNC(); \
List_END_FOR_ALL \
}
// member function : this field f1 OP fUNC f2, f3
#define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3)\
#define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3) \
\
/* check the three fields have same Field<Type> mesh */ \
checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3)"); \
......@@ -153,9 +155,10 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) \
OP FUNC(List_ELEM(f2, f2P, i), List_ELEM(f3, f3P, i)); \
List_END_FOR_ALL \
}
// member function : this field f1 OP fUNC f2, f3
......@@ -171,8 +174,9 @@ void checkFields
\
/* loop through fields performing s OP FUNC(f1, f2) */ \
List_FOR_ALL(f1, i) \
{ \
(s) OP FUNC(List_ELEM(f1, f1P, i), List_ELEM(f2, f2P, i)); \
List_END_FOR_ALL \
}
// member function : this f1 OP fUNC f2, s
......@@ -188,8 +192,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP FUNC(List_ELEM(f2, f2P, i), (s)); \
List_END_FOR_ALL
}
// member function : s1 OP fUNC f, s2
......@@ -201,8 +206,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f, i) \
{ \
(s1) OP FUNC(List_ELEM(f, fP, i), (s2)); \
List_END_FOR_ALL \
}
// member function : this f1 OP fUNC s, f2
......@@ -218,21 +224,23 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP FUNC((s), List_ELEM(f2, f2P, i)); \
List_END_FOR_ALL \
}
// member function : this f1 OP fUNC s, f2
#define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2)\
#define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2) \
\
/* set access to f1 at end of field */ \
List_ACCESS(typeF1, f1, f1P); \
\
/* loop through fields performing f1 OP1 FUNC(s1, s2) */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP FUNC((s1), (s2)); \
List_END_FOR_ALL \
}
// member function : this f1 OP1 f2 OP2 FUNC s
......@@ -248,8 +256,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i) FUNC((s)); \
List_END_FOR_ALL \
}
// define high performance macro functions for Field<Type> operations
......@@ -268,9 +277,10 @@ void checkFields
\
/* loop through fields performing f1 OP1 f2 OP2 f3 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP1 List_ELEM(f2, f2P, i) \
OP2 List_ELEM(f3, f3P, i); \
List_END_FOR_ALL \
}
// member operator : this field f1 OP1 s OP2 f2
......@@ -286,8 +296,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 s OP2 f2 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP1 (s) OP2 List_ELEM(f2, f2P, i); \
List_END_FOR_ALL \
}
// member operator : this field f1 OP1 f2 OP2 s
......@@ -303,8 +314,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 s OP2 f2 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP1 List_ELEM(f2, f2P, i) OP2 (s); \
List_END_FOR_ALL \
}
// member operator : this field f1 OP f2
......@@ -321,8 +333,9 @@ void checkFields
\
/* loop through fields performing f1 OP f2 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i); \
List_END_FOR_ALL \
}
// member operator : this field f1 OP1 OP2 f2
......@@ -338,8 +351,9 @@ void checkFields
\
/* loop through fields performing f1 OP1 OP2 f2 */ \
List_FOR_ALL(f1, i) \
{ \
List_ELEM(f1, f1P, i) OP1 OP2 List_ELEM(f2, f2P, i); \
List_END_FOR_ALL \
}
// member operator : this field f OP s
......@@ -351,8 +365,9 @@ void checkFields
\
/* loop through field performing f OP s */ \
List_FOR_ALL(f, i) \
{ \
List_ELEM(f, fP, i) OP (s); \
List_END_FOR_ALL \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -367,8 +382,9 @@ void checkFields
\
/* loop through field performing s OP f */ \
List_FOR_ALL(f, i) \
{ \
(s) OP List_ELEM(f, fP, i); \
List_END_FOR_ALL
}
// friend operator function : s OP1 f1 OP2 f2, allocates storage for s
......@@ -381,8 +397,9 @@ void checkFields
\
/* loop through field performing s OP f */ \
List_FOR_ALL(f1, i) \
{ \
(s) OP1 List_ELEM(f1, f1P, i) OP2 List_ELEM(f2, f2P, i); \
List_END_FOR_ALL
}
// friend operator function : s OP FUNC(f), allocates storage for s
......@@ -394,8 +411,9 @@ void checkFields
\
/* loop through field performing s OP f */ \
List_FOR_ALL(f, i) \
{ \
(s) OP FUNC(List_ELEM(f, fP, i)); \
List_END_FOR_ALL
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -25,12 +25,13 @@ Namespace
stdFoam
Description
Includes some global templates and macros used by OpenFOAM.
Some global templates and macros used by OpenFOAM and some standard
C++ headers.
Some of the templates are defined here correspond to useful
Some of the templates defined here correspond to useful
std templates that are part of future C++ standards, or that
are in a state of change. Defining them here provides some additional
control over which definition are used within the OpenFOAM code-base.
control over which definitions are used within the OpenFOAM code-base.
SeeAlso
- http://en.cppreference.com/w/cpp/iterator/end
......@@ -42,6 +43,7 @@ SeeAlso
#define StdFoam_H
#include <initializer_list>
#include <utility>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -114,12 +116,12 @@ constexpr auto cend(const C& c) -> decltype(c.end())
// }
// \endcode
// \sa forAllConstIters, forAllIter, forAllConstIters
#define forAllIters(container,it) \
#define forAllIters(container,iter) \
for \
( \
auto it = stdFoam::begin(container); \
it != stdFoam::end(container); \
++it \
auto iter = stdFoam::begin(container); \
iter != stdFoam::end(container); \
++iter \
)
......@@ -132,12 +134,12 @@ constexpr auto cend(const C& c) -> decltype(c.end())
// }
// \endcode
// \sa forAllIters, forAllIter, forAllConstIter
#define forAllConstIters(container,cit) \
#define forAllConstIters(container,iter) \
for \
( \
auto cit = stdFoam::cbegin(container); \
cit != stdFoam::cend(container); \
++cit \
auto iter = stdFoam::cbegin(container); \
iter != stdFoam::cend(container); \
++iter \
)
......
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