mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: several improvements for linked-lists
- support move construct/assignment for linked-lists themselves and when moving into a 'normal' list - better consistency with begin/end signatures and the various iterators. - for indirect linked-lists, provide iterator access to the underlying data element address: iter.get() vs &(iter()) - add standard '->' indirection for iterators (as per normal STL definitions)
This commit is contained in:
@ -28,20 +28,39 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "DLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const DLList<List<T>>& sll)
|
||||
{
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DLList<scalar> myList;
|
||||
|
||||
Info<< "DLList<scalar>" << nl;
|
||||
DLList<scalar> myList{2.1, 3.4};
|
||||
myList = {2.1, 3.4, 4.3};
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
@ -51,58 +70,165 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
forAllConstIters(myList, iter)
|
||||
Info<< "DLList<scalar>" << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << val << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using the same STL iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
forAllConstIters(myList, iter)
|
||||
{
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
// Test bi-directional movement
|
||||
{
|
||||
const label n2 = myList.size()/2;
|
||||
|
||||
Info<< nl << "test movement through " << flatOutput(myList) << nl;
|
||||
|
||||
DLList<scalar>::const_iterator citer = myList.begin();
|
||||
|
||||
for (label i=0; i<n2; ++i)
|
||||
{
|
||||
Info<< " forward " << i << " " << *citer << nl;
|
||||
++citer;
|
||||
}
|
||||
|
||||
for (label i=0; i<n2; ++i)
|
||||
{
|
||||
Info<< " backward " << i << " " << *citer << nl;
|
||||
--citer;
|
||||
}
|
||||
|
||||
// Verify - does not compile since it uses a delete method (good!)
|
||||
DLList<scalar>::iterator iter = myList.begin();
|
||||
++iter;
|
||||
++iter;
|
||||
++iter;
|
||||
|
||||
Info<<" now with " << *iter << nl;
|
||||
myList.remove(iter);
|
||||
Info<<" after remove " << *iter << nl;
|
||||
++iter;
|
||||
Info<<" after incr " << *iter << nl;
|
||||
--iter;
|
||||
--iter;
|
||||
|
||||
Info<<" after 2x decr " << *iter << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "const_reverse_iterator:" << nl;
|
||||
|
||||
forAllConstReverseIters(myList, iter)
|
||||
{
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Remove elements:" << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
{
|
||||
Info<< "Removing " << myList.remove(iter) << endl;
|
||||
Info<< " remove " << *iter;
|
||||
myList.remove(iter);
|
||||
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
myList.append(500.3);
|
||||
myList.append(200.3);
|
||||
myList.append(100.3);
|
||||
|
||||
Info<< nl << "Using range-based for: " << nl << endl;
|
||||
for (auto val : myList)
|
||||
Info<< nl << "Testing swapUp and swapDown:" << nl;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
myList.swapUp(myList.DLListBase::first());
|
||||
myList.swapUp(myList.DLListBase::last());
|
||||
|
||||
Info<< nl << "swapUp => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "Testing swapUp and swapDown: " << endl;
|
||||
|
||||
Info<< nl << "swapUp" << endl;
|
||||
|
||||
myList.swapUp(myList.DLListBase::first());
|
||||
myList.swapUp(myList.DLListBase::last());
|
||||
|
||||
for (auto val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
myList.swapDown(myList.DLListBase::first());
|
||||
myList.swapDown(myList.DLListBase::last());
|
||||
|
||||
Info<< nl << "swapDown => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "swapDown" << endl;
|
||||
|
||||
myList.swapDown(myList.DLListBase::first());
|
||||
myList.swapDown(myList.DLListBase::last());
|
||||
|
||||
for (auto val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << nl
|
||||
<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
DLList<scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << nl;
|
||||
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
DLList<scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Try delete data recovery
|
||||
{
|
||||
DLList<List<label>> labList;
|
||||
|
||||
for (int i = 0; i<5; i++)
|
||||
{
|
||||
labList.append(identity(6));
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "DLList<labelList> : " << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
|
||||
auto elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
List<label> content1 = identity(10);
|
||||
|
||||
Info<< nl
|
||||
<< " move append ";
|
||||
printAddress(content1);
|
||||
|
||||
labList.append(std::move(content1));
|
||||
|
||||
Info<< " content " << flatOutput(content1) << nl
|
||||
<< " list" << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
// labList.append(content1);
|
||||
}
|
||||
|
||||
Info<< nl << "Done." << endl;
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,9 +28,12 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "ISLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -66,7 +69,7 @@ public:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ISLList<Scalar> myList;
|
||||
ISLList<Scalar> myList(new Scalar(0));
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
@ -76,31 +79,74 @@ int main(int argc, char *argv[])
|
||||
myList.append(new Scalar(100.3));
|
||||
myList.append(new Scalar(500.3));
|
||||
|
||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||
Info<< "ISLList<scalar>" << myList << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << val << nl;
|
||||
// Info<<" is " << typeid(val).name() << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
const ISLList<Scalar>& const_myList = myList;
|
||||
|
||||
forAllConstIters(const_myList, iter)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
{
|
||||
Info<< nl << "Remove element:" << nl;
|
||||
|
||||
Scalar *iter = myList.removeHead();
|
||||
|
||||
Info<< " remove " << *iter;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
|
||||
delete iter;
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << endl;
|
||||
Info<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
ISLList<Scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
myList.swap(newList);
|
||||
|
||||
Info<< nl << "swap: " << nl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
myList.swap(newList);
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
ISLList<Scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl << "move assign: " << nl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(list2) << nl
|
||||
<< "target: " << flatOutput(newList) << endl;
|
||||
|
||||
|
||||
Info<< nl << "Bye." << endl;
|
||||
return 0;
|
||||
|
||||
3
applications/test/List3/Make/files
Normal file
3
applications/test/List3/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-List3.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-List3
|
||||
0
applications/test/List3/Make/options
Normal file
0
applications/test/List3/Make/options
Normal file
155
applications/test/List3/Test-List3.C
Normal file
155
applications/test/List3/Test-List3.C
Normal file
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-List3
|
||||
|
||||
Description
|
||||
Test list construction
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "FixedList.H"
|
||||
#include "labelList.H"
|
||||
#include "vectorList.H"
|
||||
#include "ListOps.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "cpuTime.H"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddress(const SLList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: ???" << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const List<List<T>>& list)
|
||||
{
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const SLList<List<T>>& list)
|
||||
{
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addBoolOption("labelListList");
|
||||
|
||||
argList args(argc, argv, false);
|
||||
|
||||
if (args.options().empty())
|
||||
{
|
||||
Info<< nl << "Specify an option! " << nl << endl;
|
||||
}
|
||||
|
||||
if (args.optionFound("labelListList"))
|
||||
{
|
||||
for (label argi=1; argi < args.size(); ++argi)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
IFstream is(args[argi]);
|
||||
|
||||
Info<< nl << nl
|
||||
<< "read from " << is.name() << nl << endl;
|
||||
|
||||
SLList<List<label>> sll(is);
|
||||
Info<< "read " << sll.size() << " entries" << nl;
|
||||
|
||||
Info<< "sll" << nl;
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
|
||||
|
||||
// List<List<label>> list(std::move(sll));
|
||||
List<List<label>> list;
|
||||
Info<< "move to List" << nl;
|
||||
list = std::move(sll);
|
||||
|
||||
Info<< "sll" << nl;
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
Info<< "list" << nl;
|
||||
printAddresses(list);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
IFstream is(args[argi]);
|
||||
|
||||
Info<< nl << nl
|
||||
<< "read from " << is.name() << nl << endl;
|
||||
|
||||
List<List<label>> list(is);
|
||||
|
||||
Info<< "list" << nl;
|
||||
for (const auto& elem : list)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Info<< nl << "Done" << nl << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
8
applications/test/List3/list1
Normal file
8
applications/test/List3/list1
Normal file
@ -0,0 +1,8 @@
|
||||
// List of labelList
|
||||
|
||||
(
|
||||
(1 2 3 4)
|
||||
(5 6 7 8)
|
||||
(15 16 17 18)
|
||||
)
|
||||
|
||||
@ -32,6 +32,8 @@ Description
|
||||
#include "scalar.H"
|
||||
#include "IOstreams.H"
|
||||
#include "PtrList.H"
|
||||
#include "DLPtrList.H"
|
||||
#include "SLPtrList.H"
|
||||
#include "plane.H"
|
||||
#include "DynamicList.H"
|
||||
|
||||
@ -80,6 +82,36 @@ int main(int argc, char *argv[])
|
||||
PtrList<Scalar> list2(15);
|
||||
PtrList<Scalar> listApp;
|
||||
|
||||
{
|
||||
DLPtrList<Scalar> llist1;
|
||||
llist1.insert(new Scalar(100));
|
||||
llist1.insert(new Scalar(200));
|
||||
llist1.insert(new Scalar(300));
|
||||
|
||||
DLPtrList<Scalar>::const_iterator citer = llist1.begin();
|
||||
|
||||
Info<< *citer << endl;
|
||||
Info<< typeid(*citer).name() << endl;
|
||||
|
||||
++citer;
|
||||
++citer;
|
||||
|
||||
--citer;
|
||||
|
||||
Info<< typeid(llist1.begin()).name() << endl;
|
||||
|
||||
forAllIters(llist1, it)
|
||||
{
|
||||
Info<< typeid(*it).name() << endl;
|
||||
Info<< "reversed: " << *it << endl;
|
||||
}
|
||||
for (const auto& it : llist1)
|
||||
{
|
||||
Info<< typeid(it).name() << endl;
|
||||
Info<< "for-: " << it << endl;
|
||||
}
|
||||
}
|
||||
|
||||
forAll(list1, i)
|
||||
{
|
||||
list1.set(i, new Scalar(1.3*i));
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,12 +28,32 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
|
||||
#include "IOstreams.H"
|
||||
#include "SLList.H"
|
||||
#include "List.H"
|
||||
#include "FlatOutput.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printAddress(const UList<T>& list)
|
||||
{
|
||||
Info<< "list addr: " << long(&list)
|
||||
<< " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void printAddresses(const SLList<List<T>>& sll)
|
||||
{
|
||||
for (const auto& elem : sll)
|
||||
{
|
||||
printAddress(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
@ -50,34 +70,34 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
Info<< nl << "And again using STL iterator: " << nl << endl;
|
||||
Info<< "SLList<scalar>" << myList << nl;
|
||||
Info<< nl << "flat-output: " << flatOutput(myList) << nl;
|
||||
|
||||
Info<< nl << "range-for:" << nl;
|
||||
for (const auto& val : myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
Info<< " " << val << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "And again using STL const_iterator: " << nl << endl;
|
||||
Info<< nl << "const_iterator:" << nl;
|
||||
|
||||
const SLList<scalar>& const_myList = myList;
|
||||
|
||||
forAllConstIters(const_myList, iter)
|
||||
{
|
||||
Info<< "element:" << *iter << endl;
|
||||
Info<< " " << *iter << endl;
|
||||
}
|
||||
|
||||
Info<< nl << "Remove elements:" << nl;
|
||||
|
||||
forAllIters(myList, iter)
|
||||
{
|
||||
Info<< "Removing element:" << *iter << endl;
|
||||
Info<< " remove " << *iter;
|
||||
myList.remove(iter);
|
||||
}
|
||||
|
||||
for (const auto& val : const_myList)
|
||||
{
|
||||
Info<< "element:" << val << endl;
|
||||
Info<< " => " << flatOutput(myList) << nl;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i<10; i++)
|
||||
{
|
||||
myList.append(1.3*i);
|
||||
@ -86,15 +106,72 @@ int main(int argc, char *argv[])
|
||||
myList.append(100.3);
|
||||
myList.append(500.3);
|
||||
|
||||
Info<< nl << "Testing transfer: " << nl << endl;
|
||||
Info<< "original: " << myList << endl;
|
||||
Info<< nl << "Transfer: " << nl;
|
||||
Info<< "original: " << flatOutput(myList) << endl;
|
||||
|
||||
SLList<scalar> newList;
|
||||
newList.transfer(myList);
|
||||
|
||||
Info<< nl << "source: " << myList << nl
|
||||
<< nl << "target: " << newList << endl;
|
||||
Info<< nl
|
||||
<< "source: " << flatOutput(myList) << nl
|
||||
<< "target: " << flatOutput(newList) << nl;
|
||||
|
||||
Info<< nl << "Move Construct: " << nl;
|
||||
|
||||
SLList<scalar> list2(std::move(newList));
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
// Move back
|
||||
Info<< nl << "Move Assignment: " << nl;
|
||||
|
||||
newList = std::move(list2);
|
||||
|
||||
Info<< nl
|
||||
<< "in : " << flatOutput(newList) << nl
|
||||
<< "out: " << flatOutput(list2) << nl;
|
||||
|
||||
|
||||
// Try delete data recovery
|
||||
{
|
||||
SLList<List<label>> labList;
|
||||
|
||||
for (int i = 0; i<5; i++)
|
||||
{
|
||||
labList.append(identity(6));
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "SLList<labelList> : " << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
|
||||
auto elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
elem = labList.removeHead();
|
||||
|
||||
Info<< " removed head" << nl;
|
||||
printAddress(elem);
|
||||
|
||||
List<label> content1 = identity(10);
|
||||
|
||||
Info<< nl
|
||||
<< " move append ";
|
||||
printAddress(content1);
|
||||
|
||||
labList.append(std::move(content1));
|
||||
|
||||
Info<< " content " << flatOutput(content1) << nl
|
||||
<< " list" << labList << nl;
|
||||
|
||||
printAddresses(labList);
|
||||
// labList.append(content1);
|
||||
}
|
||||
|
||||
Info<< nl << "Done." << endl;
|
||||
return 0;
|
||||
|
||||
3
applications/test/UList/Make/files
Normal file
3
applications/test/UList/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-UList.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-UList
|
||||
0
applications/test/UList/Make/options
Normal file
0
applications/test/UList/Make/options
Normal file
119
applications/test/UList/Test-UList.C
Normal file
119
applications/test/UList/Test-UList.C
Normal file
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-UList
|
||||
|
||||
Description
|
||||
Simple tests for UList constructors
|
||||
|
||||
See also
|
||||
Foam::List
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSspecific.H"
|
||||
#include "IOstreams.H"
|
||||
#include "StringStream.H"
|
||||
|
||||
#include "labelList.H"
|
||||
#include "ListOps.H"
|
||||
#include "SubList.H"
|
||||
#include "FlatOutput.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class ListType>
|
||||
void print(const ListType& list)
|
||||
{
|
||||
Info << flatOutput(list) << " data addr: " << long(list.cdata()) << nl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
List<label> source = identity(7);
|
||||
List<label> other = identity(7);
|
||||
|
||||
// Text for reading as a SLList"
|
||||
string inputSLList("(10 20 30 40 50 60 70)");
|
||||
|
||||
// Text for reading as a SLList"
|
||||
string inputCompound("List<label> (-1 -2 -3 -4 -5 -6 -7)");
|
||||
|
||||
reverse(other);
|
||||
|
||||
UList<label> ulist(source.data(), source.size());
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
|
||||
{
|
||||
Info<<"shallow copy" << nl;
|
||||
ulist.shallowCopy(other);
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
{
|
||||
Info<<"deep copy" << nl;
|
||||
ulist.deepCopy(source);
|
||||
|
||||
Info<<"source: "; print(source);
|
||||
Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
{
|
||||
Info<<"Read from " << inputSLList << nl;
|
||||
|
||||
IStringStream is(inputSLList);
|
||||
is >> ulist;
|
||||
|
||||
// Info<<"source: "; print(source);
|
||||
// Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
Info<<"Read from " << inputCompound << nl;
|
||||
|
||||
IStringStream is(inputCompound);
|
||||
is >> ulist;
|
||||
|
||||
// Info<<"source: "; print(source);
|
||||
// Info<<"other: "; print(other);
|
||||
Info<<"UList: "; print(ulist);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user