diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.C index 4074badee4..4b90ab81ab 100644 --- a/applications/test/FixedList/Test-FixedList.C +++ b/applications/test/FixedList/Test-FixedList.C @@ -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 . 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::Hash<>()(list) << endl; - Info<< "FixedList is contiguous, " - "thus hashing function is irrelevant: with string::hash" << endl; - - Info<< "list:" << list - << " hash:" << FixedList::Hash()(list) << endl; - label a[4] = {0, 1, 2, 3}; FixedList list2(a); - Info<< "list:" << list2 + Info<< "list2:" << list2 << " hash:" << FixedList::Hash<>()(list2) << endl; - // FixedList 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()) { diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 2b063ff122..04c12e91b7 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -22,8 +22,13 @@ License along with OpenFOAM. If not, see . 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 list4(IStringStream("((0 1 2) (3 4 5) (6 7 8))")()); + List 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)")()); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C index cd71cf9a8c..6b919cf037 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C @@ -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 @@ -37,8 +35,8 @@ void Foam::FixedList::swap(FixedList& 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 } diff --git a/src/OpenFOAM/containers/Lists/List/ListLoopM.H b/src/OpenFOAM/containers/Lists/List/ListLoopM.H index 5758ba60f0..9e68826205 100644 --- a/src/OpenFOAM/containers/Lists/List/ListLoopM.H +++ b/src/OpenFOAM/containers/Lists/List/ListLoopM.H @@ -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) \ diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index a3d1cbb268..5b99c3c3cd 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -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::assign(const UList& a) if (this->size_) { -# ifdef USEMEMCPY + #ifdef USEMEMCPY if (contiguous()) { 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::swap(UList& 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 }