ENH: additional read guards for dimensionedType. input consistency (#762, #1148)

- provide a lookupOrDefault constructor form, since this is a fairly
  commonly used requirement and simplifies the calling sequence.

  Before

      dimensionedScalar rhoMax
      (
          dimensionedScalar::lookupOrDefault
          (
              "rhoMax",
              pimple.dict(),
              dimDensity,
              GREAT
          )
     );

  After

      dimensionedScalar rhoMax("rhoMax", dimDensity, GREAT, pimple.dict());

- read, readIfPresent methods with alternative lookup names.

- Mark the Istream related constructors with compile-time deprecated
  warnings.

BUG: read, readIfPresent methods not handling optional dimensions (#1148)
This commit is contained in:
Mark Olesen
2019-01-03 13:34:11 +01:00
parent af310075a0
commit 6a448016aa
58 changed files with 443 additions and 688 deletions

View File

@ -108,6 +108,7 @@ int main(int argc, char *argv[])
dict.add("test1", scalar(10));
dict.add("test2a", scalar(21));
dict.add("test5", dimensionedScalar("", 50));
dict.add("carp1", dimensionedScalar("test1", 11));
// This will fail to tokenize:
// dict.add("test5", dimensionedScalar(50));
}
@ -126,6 +127,36 @@ int main(int argc, char *argv[])
Info<< "test5 : "
<< dimensionedScalar::lookupOrAddToDict("test5", dict, -50) << nl;
// Deprecated
Info<< "Deprecated constructors" << nl;
Info<< "carp : "
<< dimensionedScalar(dict.lookup("carp1")) << nl;
Info<< "carp : "
<< dimensionedScalar("other", dict.lookup("test5")) << nl;
Info<< "carp : "
<< dimensionedScalar("carp", dimless, dict.lookup("carp1")) << nl;
Info<< "alt : "
<< dimensionedScalar("myName", dimless, dict, "carp1") << nl;
Info<< "alt : "
<< dimensionedScalar("myName", dimless, dict, "test5") << nl;
{
dimensionedScalar scalar1("myName", dimless, Zero);
scalar1.read("test5", dict);
Info<< "read in : " << scalar1 << nl;
scalar1.readIfPresent("test4", dict);
Info<< "read in : " << scalar1 << nl;
scalar1.readIfPresent("test5", dict);
Info<< "read in : " << scalar1 << nl;
}
Info<< nl << "Dictionary is now: " << dict << nl;
Info<< "End\n" << endl;