/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . Application Test-List Description Simple tests and examples of use of List See also Foam::List \*---------------------------------------------------------------------------*/ #include "OSspecific.H" #include "argList.H" #include "wordReList.H" #include "IOstreams.H" #include "StringStream.H" #include "scalar.H" #include "vector.H" #include "labelRange.H" #include "scalarList.H" #include "ListOps.H" #include "SubList.H" #include using namespace Foam; template void testFind(const T& val, const ListType& lst) { Info<< nl << "Search for "<< val << " in " << flatOutput(lst) << nl <<" found() = " << lst.found(val) <<" find() = " << lst.find(val) <<" rfind() = " << lst.rfind(val) <<" find(2) = " << lst.find(val, 2) <<" rfind(2) = " << lst.rfind(val, 2) <<" findIndex = " << findIndex(lst, val) << nl << nl; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { argList::noParallel(); argList::addOption("reList", "reList"); argList::addOption("wordList", "wordList"); argList::addOption("stringList", "stringList"); argList::addOption("float", "xx"); argList::addBoolOption("flag"); #include "setRootCase.H" if (false) { labelList intlist(IStringStream("(0 1 2)")()); Info<<"construct from Istream: " << intlist << endl; IStringStream("(3 4 5)")() >> static_cast(intlist); Info<<"is >>: " << intlist << endl; IStringStream("(6 7 8)")() >> intlist; Info<<"is >>: " << intlist << endl; } List list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; List list2 { vector(0, 1, 2), vector(3, 4, 5), vector(6, 7, 8), vector(0, 1, 2), vector(3, 4, 5), vector(6, 7, 8), }; Info<< "list2: " << list2 << endl; Info<< "forAllConstIters(list2): "; forAllConstIters(list2, iter) { Info<< " " << *iter; } Info<< endl; Info<< "forAllReverseConstIters(list2): "; forAllReverseConstIters(list2, iter) { Info<< " " << *iter; } Info<< endl; Info<< "forAllConstIters(list2): "; forAllIters(list2, iter) { *iter *= 2; Info<< " " << *iter; } Info<< endl; Info<< "forAllReverseConstIters(list2): "; forAllReverseIters(list2, iter) { *iter *= 0.5; Info<< " " << *iter; } Info<< endl; list1.append(list2); Info<< "list1.append(list2): " << list1 << endl; for (const vector& val : { vector(3, 4, 5), vector(10,11, 12)} ) { testFind(val, list2); } list2.setSize(10, vector(1, 2, 3)); Info<< "list2: " << list2 << endl; List list3(list2.xfer()); Info<< "Transferred via the xfer() method" << endl; Info<< "list2: " << list2 << nl << "list3: " << list3 << endl; List list4 { vector(0, 1, 2), vector(3, 4, 5), vector(6, 7, 8) }; Info<< "list4: " << list4 << endl; List list5 { {5, 3, 1}, {10, 2, 2}, {8, 1, 0} }; Info<< "list5: " << list5 << endl; list5 = { {8, 1, 0}, {5, 3, 1}, {10, 2, 2} }; Info<< "list5: " << list5 << endl; list4.swap(list5); Info<< "Swapped via the swap() method" << endl; Info<< "list4: " << list4 << nl << "list5: " << list5 << endl; List list6(list4.begin(), list4.end()); Info<< "list6: " << list6 << endl; // Subset const labelList map{0, 2}; List subList3(list3, map); Info<< "Elements " << map << " out of " << list3 << " => " << subList3 << endl; // test flattened output { Info<< nl; labelList longLabelList = identity(15); // This does not work: // scalarList slist = identity(15); // // More writing, but does work: scalarList slist ( labelRange::null.begin(), labelRange::identity(15).end() ); Info<<"scalar identity:" << flatOutput(slist) << endl; Info<< "labels (contiguous=" << contiguous