Commit 542c05ad authored by Henry Weller's avatar Henry Weller
Browse files

UList, FixedList: Correct swap member function

Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1787
parent da8db9ff
......@@ -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())
{
......
......@@ -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
\*---------------------------------------------------------------------------*/
......@@ -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)")());
......
......@@ -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
}
......
......@@ -43,6 +43,10 @@ Description
#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) \
......@@ -62,6 +66,10 @@ Description
#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) \
......
......@@ -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
}
......
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