ENH: define nameOp<>, typeOp<>, sizeOp<> functors (issue #1013)

This commit is contained in:
Mark Olesen
2018-09-19 15:32:04 +02:00
parent 47519b2e04
commit 12c903bba8
15 changed files with 149 additions and 44 deletions

View File

@ -617,6 +617,7 @@ int main(int argc, char *argv[])
fileName pathName(wrdList);
Info<< "pathName = " << pathName << nl
<< "nameOp = " << nameOp<fileName>()(pathName) << nl
<< "pathName.name() = >" << pathName.name() << "<\n"
<< "pathName.path() = " << pathName.path() << nl
<< "pathName.ext() = >" << pathName.ext() << "<\n"

View File

@ -271,32 +271,31 @@ int main(int argc, char *argv[])
Info<< "hash: = " << word::printf("0x%012X", string::hash()(s2)) << endl;
// test formatting on int
// Test formatting on int
{
label val = 25;
Info<<"val: " << val << "\n";
Info<< "int " << val << " as word >"
<< Foam::name(val) << "< or "
<< word::printf("formatted >%08d<", val) << "\n";
Info<< "int " << val << " nameOp='"
<< nameOp<label>()(val) << "', name='"
<< Foam::name(val) << "' or "
<< word::printf("formatted '%08d'", val) << "\n";
}
// test formatting on scalar
// Test formatting on scalar
{
scalar val = 3.1415926535897931;
Info<< "scalar " << val << " as word >"
<< Foam::name(val) << "< or "
<< word::printf("formatted >%.9f<", val) << "\n";
Info<< "scalar " << val << " nameOp='"
<< nameOp<scalar>()(val) << "', name='"
<< Foam::name(val) << "' or "
<< word::printf("formatted '%.9f'", val) << "\n";
}
// test formatting on uint
// Test formatting on uint
{
uint64_t val = 25000000ul;
Info<<"val: " << val << "\n";
Info<< "uint64 " << val << " as word >"
<< Foam::name(val) << "< or "
<< word::printf("formatted >%08d<", val) << "\n";
Info<< "uint64 " << val << " nameOp='"
<< nameOp<uint64_t>()(val) << "', name='"
<< Foam::name(val) << "' or "
<< word::printf("formatted '%08d'", val) << "\n";
}
// test startsWith, endsWith methods

View File

@ -87,12 +87,12 @@ static const Enum<restoreMethod> methodEndings
// Files in given directory at time instant
wordList getFiles(const fileName& dir, const word& instance)
inline wordList getFiles(const fileName& dir, const word& instance)
{
return ListOps::create<word>
(
Foam::readDir(dir/instance, fileName::FILE),
[](const fileName& f){ return f.name(); }
nameOp<fileName>()
);
}