ENH: add IOobjectList append() method for building larger lists

- supports copy append and move append
This commit is contained in:
Mark Olesen
2018-07-27 15:38:32 +02:00
parent fd2b72891c
commit db9cd2bc85
3 changed files with 178 additions and 17 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,6 +23,7 @@ License
Description
Basic tests of IOobjectList
\*---------------------------------------------------------------------------*/
#include "argList.H"
@ -34,13 +35,52 @@ Description
using namespace Foam;
void report(const IOobjectList& objects)
{
Info<< "Names: " << flatOutput(objects.sortedNames()) << nl
<< "Objects: " << objects << nl
<< "----" << nl;
}
void reportDetail(const IOobjectList& objects)
{
Info<<"Details:" << nl;
for (const word& key : objects.sortedNames())
{
IOobject* io = objects.lookup(key);
Info<< key << " (" << io->headerClassName()
<< ") = addr " << long(io) << nl;
}
Info<<"====" << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addOption("re", "wordRes");
argList::addOption
(
"filter",
"wordRes",
"filter keys with names or regexs"
);
argList::addBoolOption
(
"copy-append",
"test move append lists (requires -filter)"
);
argList::addBoolOption
(
"move-append",
"test move append lists (requires -filter)"
);
// timeSelector::addOptions();
timeSelector::addOptions(true, true);
@ -49,11 +89,25 @@ int main(int argc, char *argv[])
#include "createTime.H"
wordRes matcher;
if (args.readListIfPresent<wordRe>("re", matcher))
if (args.readListIfPresent<wordRe>("filter", matcher))
{
Info<<"limit names: " << matcher << nl;
}
if (args.found("copy-append") && matcher.empty())
{
FatalError
<< nl << "The -copy-append test also requires -filter" << nl
<< exit(FatalError);
}
if (args.found("move-append") && matcher.empty())
{
FatalError
<< nl << "The -move-append test also requires -filter" << nl
<< exit(FatalError);
}
const hashedWordList subsetTypes
{
volScalarField::typeName,
@ -79,9 +133,7 @@ int main(int argc, char *argv[])
Info<< "Time: " << runTime.timeName() << nl;
Info<<"Name: " << flatOutput(objects.sortedNames()) << nl
<<"Objects: " << objects << nl
<<"Classes: " << classes << nl;
report(objects);
classes.filterKeys(subsetTypes);
Info<<"only retain: " << flatOutput(subsetTypes) << nl;
@ -91,6 +143,50 @@ int main(int argc, char *argv[])
classes.erase(subsetTypes);
Info<<"remove: " << flatOutput(subsetTypes) << nl;
Info<<"Pruned: " << classes << nl;
// On last time
if (timeI == timeDirs.size()-1)
{
if (args.found("copy-append"))
{
Info<< nl << "Test move append" << nl;
}
else if (args.found("move-append"))
{
Info<< nl << "Test move append" << nl;
}
else
{
continue;
}
IOobjectList other(runTime, runTime.timeName());
Info<< "==original==" << nl; reportDetail(objects);
objects.filterKeys(matcher);
Info<< "==target==" << nl; reportDetail(objects);
Info<< "==source==" << nl; reportDetail(other);
if (args.found("copy-append"))
{
objects.append(other);
Info<< nl << "After copy-append" << nl;
}
else
{
objects.append(std::move(other));
Info<< nl << "After move-append" << nl;
}
Info<< "==target==" << nl; reportDetail(objects);
Info<< "==source==" << nl; reportDetail(other);
Info<< nl;
}
}
Info<< "\nEnd\n" << endl;