UList, FixedList: Correct swap member function

Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1787
This commit is contained in:
Henry Weller 2015-07-15 12:06:27 +01:00
parent e713234c04
commit 98302e5c50
5 changed files with 50 additions and 29 deletions

View file

@ -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-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,9 +22,13 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
FixedListTest
Test-FixedList
Description
Simple tests and examples of use of FixedList
See Also
Foam::FixedList
\*---------------------------------------------------------------------------*/
@ -54,20 +58,18 @@ int main(int argc, char *argv[])
Info<< "list:" << list
<< " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
Info<< "FixedList<label, ..> is contiguous, "
"thus hashing function is irrelevant: with string::hash" << endl;
Info<< "list:" << list
<< " hash:" << FixedList<label, 4>::Hash<string::hash>()(list) << endl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);
Info<< "list:" << list2
Info<< "list2:" << list2
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
// FixedList<label, 3> hmm(Sin);
// Info<< hmm << endl;
Info<< "list: " << list << nl
<< "list2: " << list2 << endl;
list.swap(list2);
Info<< "Swapped via the swap() method" << endl;
Info<< "list: " << list << nl
<< "list2: " << list2 << endl;
if (Pstream::parRun())
{

View file

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,8 +22,13 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-List
Description
Simple tests and examples of use of List
See Also
Foam::List
\*---------------------------------------------------------------------------*/
@ -54,7 +59,7 @@ int main(int argc, char *argv[])
argList::addOption("float", "xx");
argList::addBoolOption("flag");
# include "setRootCase.H"
#include "setRootCase.H"
List<vector> list1(IStringStream("1 ((0 1 2))")());
Info<< "list1: " << list1 << endl;
@ -75,6 +80,14 @@ int main(int argc, char *argv[])
Info<< "list2: " << list2 << nl
<< "list3: " << list3 << endl;
List<vector> list4(IStringStream("((0 1 2) (3 4 5) (6 7 8))")());
List<vector> list5(IStringStream("((5 3 1) (10 2 2) (8 1 0))")());
Info<< "list4: " << list4 << nl
<< "list5: " << list5 << endl;
list4.swap(list5);
Info<< "Swapped via the swap() method" << endl;
Info<< "list4: " << list4 << nl
<< "list5: " << list5 << endl;
// Subset
const labelList map(IStringStream("2 (0 2)")());

View file

@ -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-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,8 +26,6 @@ License
#include "FixedList.H"
#include "ListLoopM.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
template<class T, unsigned Size>
@ -37,8 +35,8 @@ void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a)
List_ACCESS(T, a, ap);
T tmp;
List_FOR_ALL((*this), i)
tmp = List_ELEM((*this), vp, i);
List_ELEM((*this), vp, i) = List_ELEM(a, ap, 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
}

View file

@ -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-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,12 +37,16 @@ Description
// Element access looping using [] for vector machines
#define List_FOR_ALL(f, i) \
register const label _n##i = (f).size();\
for (register label i=0; i<_n##i; i++) \
const label _n##i = (f).size();\
for (label i=0; i<_n##i; i++) \
{
#define List_END_FOR_ALL }
// Provide current element
#define List_CELEM(f, fp, i) (fp[i])
// Provide current element
#define List_ELEM(f, fp, i) (fp[i])
#define List_ACCESS(type, f, fp) \
@ -56,19 +60,23 @@ Description
// Pointer looping for scalar machines
#define List_FOR_ALL(f, i) \
register label i = (f).size(); \
label i = (f).size(); \
while (i--) \
{ \
#define List_END_FOR_ALL }
// Provide current element without incrementing pointer
#define List_CELEM(f, fp, i) (*fp)
// Provide current element and increment pointer
#define List_ELEM(f, fp, i) (*fp++)
#define List_ACCESS(type, f, fp) \
register type* __restrict__ fp = (f).begin()
type* __restrict__ fp = (f).begin()
#define List_CONST_ACCESS(type, f, fp) \
register const type* __restrict__ fp = (f).begin()
const type* __restrict__ fp = (f).begin()
#endif

View file

@ -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-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -46,13 +46,13 @@ void Foam::UList<T>::assign(const UList<T>& a)
if (this->size_)
{
# ifdef USEMEMCPY
#ifdef USEMEMCPY
if (contiguous<T>())
{
memcpy(this->v_, a.v_, this->byteSize());
}
else
# endif
#endif
{
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
@ -93,8 +93,8 @@ void Foam::UList<T>::swap(UList<T>& a)
List_ACCESS(T, a, ap);
T tmp;
List_FOR_ALL((*this), i)
tmp = List_ELEM((*this), vp, i);
List_ELEM((*this), vp, i) = List_ELEM(a, ap, 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
}