UList, FixedList: Correct swap member function
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1787
This commit is contained in:
@ -2,7 +2,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 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -22,9 +22,13 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Application
|
Application
|
||||||
FixedListTest
|
Test-FixedList
|
||||||
|
|
||||||
Description
|
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
|
Info<< "list:" << list
|
||||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
|
<< " 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};
|
label a[4] = {0, 1, 2, 3};
|
||||||
FixedList<label, 4> list2(a);
|
FixedList<label, 4> list2(a);
|
||||||
|
|
||||||
Info<< "list:" << list2
|
Info<< "list2:" << list2
|
||||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
|
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
|
||||||
|
|
||||||
// FixedList<label, 3> hmm(Sin);
|
Info<< "list: " << list << nl
|
||||||
// Info<< hmm << endl;
|
<< "list2: " << list2 << endl;
|
||||||
|
list.swap(list2);
|
||||||
|
Info<< "Swapped via the swap() method" << endl;
|
||||||
|
Info<< "list: " << list << nl
|
||||||
|
<< "list2: " << list2 << endl;
|
||||||
|
|
||||||
if (Pstream::parRun())
|
if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -22,8 +22,13 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Application
|
Application
|
||||||
|
Test-List
|
||||||
|
|
||||||
Description
|
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
|
Info<< "list2: " << list2 << nl
|
||||||
<< "list3: " << list3 << endl;
|
<< "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
|
// Subset
|
||||||
const labelList map(IStringStream("2 (0 2)")());
|
const labelList map(IStringStream("2 (0 2)")());
|
||||||
|
|||||||
@ -2,7 +2,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 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -26,8 +26,6 @@ License
|
|||||||
#include "FixedList.H"
|
#include "FixedList.H"
|
||||||
#include "ListLoopM.H"
|
#include "ListLoopM.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, unsigned Size>
|
template<class T, unsigned Size>
|
||||||
@ -37,8 +35,8 @@ void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a)
|
|||||||
List_ACCESS(T, a, ap);
|
List_ACCESS(T, a, ap);
|
||||||
T tmp;
|
T tmp;
|
||||||
List_FOR_ALL((*this), i)
|
List_FOR_ALL((*this), i)
|
||||||
tmp = List_ELEM((*this), vp, i);
|
tmp = List_CELEM((*this), vp, i);
|
||||||
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
|
List_ELEM((*this), vp, i) = List_CELEM(a, ap, i);
|
||||||
List_ELEM(a, ap, i) = tmp;
|
List_ELEM(a, ap, i) = tmp;
|
||||||
List_END_FOR_ALL
|
List_END_FOR_ALL
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,6 +43,10 @@ Description
|
|||||||
|
|
||||||
#define List_END_FOR_ALL }
|
#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_ELEM(f, fp, i) (fp[i])
|
||||||
|
|
||||||
#define List_ACCESS(type, f, fp) \
|
#define List_ACCESS(type, f, fp) \
|
||||||
@ -62,6 +66,10 @@ Description
|
|||||||
|
|
||||||
#define List_END_FOR_ALL }
|
#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_ELEM(f, fp, i) (*fp++)
|
||||||
|
|
||||||
#define List_ACCESS(type, f, fp) \
|
#define List_ACCESS(type, f, fp) \
|
||||||
|
|||||||
@ -2,7 +2,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-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -46,13 +46,13 @@ void Foam::UList<T>::assign(const UList<T>& a)
|
|||||||
|
|
||||||
if (this->size_)
|
if (this->size_)
|
||||||
{
|
{
|
||||||
# ifdef USEMEMCPY
|
#ifdef USEMEMCPY
|
||||||
if (contiguous<T>())
|
if (contiguous<T>())
|
||||||
{
|
{
|
||||||
memcpy(this->v_, a.v_, this->byteSize());
|
memcpy(this->v_, a.v_, this->byteSize());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif
|
#endif
|
||||||
{
|
{
|
||||||
List_ACCESS(T, (*this), vp);
|
List_ACCESS(T, (*this), vp);
|
||||||
List_CONST_ACCESS(T, a, ap);
|
List_CONST_ACCESS(T, a, ap);
|
||||||
@ -93,8 +93,8 @@ void Foam::UList<T>::swap(UList<T>& a)
|
|||||||
List_ACCESS(T, a, ap);
|
List_ACCESS(T, a, ap);
|
||||||
T tmp;
|
T tmp;
|
||||||
List_FOR_ALL((*this), i)
|
List_FOR_ALL((*this), i)
|
||||||
tmp = List_ELEM((*this), vp, i);
|
tmp = List_CELEM((*this), vp, i);
|
||||||
List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
|
List_ELEM((*this), vp, i) = List_CELEM(a, ap, i);
|
||||||
List_ELEM(a, ap, i) = tmp;
|
List_ELEM(a, ap, i) = tmp;
|
||||||
List_END_FOR_ALL
|
List_END_FOR_ALL
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user