Commit 1071d413 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add ROOTGREAT constants (symmetry with ROOTSMALL)

ENH: add some scalar constants for .org compatibility (#1881)

Although it can very much be a moving target, it can prove partly
useful to have some compatibility constants/methods.

- The wholesale change of 'GREAT' -> 'great' etc (JAN-2018), makes
  user coding for multiple versions problematic. When
  COMPAT_OPENFOAM_ORG is defined, now define constants (aliases) named
  as per the openfoam.org version. Values, however, remain identical.

- For type-safe dictionary value retrieval, we have the templated
  get<> methods added around NOV-2018 and deprecated the lookupType
  method.

  The .org version followed suit in NOV-2019, but opted for renaming
  the templated lookupType method as a templated 'lookup' method.

  Using this is discouraged, but allowed when COMPAT_OPENFOAM_ORG is
  defined.
parent cb47decb
......@@ -410,6 +410,30 @@ int main(int argc, char *argv[])
// try_getScalar(dict2.findEntry("bad"), "bad");
try_getScalar(dict2.findEntry("empty"), "empty");
}
#ifdef COMPAT_OPENFOAM_ORG
{
Info<< nl
<< "Test openfoam.org compatibility" << nl;
dictionary mydict
(
IStringStream
(
"scalar 3.14159;\n"
"label 10;\n"
)()
);
Info<<"get<scalar> : " << mydict.get<scalar>("scalar") << nl;
Info<<"get<label> : " << mydict.get<label>("label") << nl;
Info<<"lookup<scalar> : " << mydict.lookup<scalar>("scalar") << nl;
Info<<"lookup<label> : " << mydict.lookup<label>("label") << nl;
}
#else
Info<< "No openfoam.org compatibility methods" << nl;
#endif
}
......
EXE_INC = \
-DCOMPAT_OPENFOAM_ORG \
-I$(LIB_SRC)/fileFormats/lnInclude
EXE_LIBS = \
......
......@@ -69,7 +69,7 @@ inline Switch readSwitch(const std::string& str)
void printInfo(const Switch& sw)
{
Info<<"Switch " << sw.c_str() << " (enum=" << label(sw.type()) << ")\n";
Info<< "Switch " << sw.c_str() << " (enum=" << label(sw.type()) << ")\n";
}
......@@ -86,6 +86,13 @@ Ostream& toString(Ostream& os, const UList<char>& list)
}
template<class T1, class T2>
void printValPair(const char* desc, const T1& val1, const T2& val2)
{
Info<< desc << ' ' << val1 << ' ' << val2 << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T>
......@@ -360,6 +367,21 @@ int main(int argc, char *argv[])
<< "Read " << flatOutput(dstList) << nl;
}
#ifdef COMPAT_OPENFOAM_ORG
Info<< nl << "compatibility sizes" << nl
<< "name com org" << nl
<< "---- --- ---" << nl;
printValPair("SMALL", SMALL, small);
printValPair("GREAT", GREAT, great);
printValPair("VSMALL", VSMALL, vSmall);
printValPair("VGREAT", VGREAT, vGreat);
printValPair("ROOTSMALL", ROOTSMALL, rootSmall);
printValPair("ROOTGREAT", ROOTGREAT, rootGreat);
#else
Info<< nl << "no compatibility sizes" << nl;
#endif
if (nFail)
{
Info<< nl << "failed " << nFail << " tests" << nl;
......
......@@ -1297,20 +1297,6 @@ public:
return lookup(keyword);
}
//- Deprecated(2018-10) find and return a T.
// \deprecated(2018-10) - use get() method
template<class T>
FOAM_DEPRECATED_FOR(2018-10, "get() method")
T lookupType
(
const word& keyword,
bool recursive = false,
bool patternMatch = true
) const
{
return get<T>(keyword, matchOpt(recursive, patternMatch));
}
//- Deprecated(2018-10)
// \deprecated(2018-10) - use keyType::option version
FOAM_DEPRECATED_FOR(2018-10, "found(keyType::option)")
......@@ -1461,6 +1447,39 @@ public:
}
// More compatibility
//- Deprecated(2018-10) find and return a T.
// \deprecated(2018-10) - use get() method
template<class T>
FOAM_DEPRECATED_FOR(2018-10, "get() method")
T lookupType
(
const word& keyword,
bool recursive = false,
bool patternMatch = true
) const
{
return get<T>(keyword, matchOpt(recursive, patternMatch));
}
#ifdef COMPAT_OPENFOAM_ORG
//! \cond compat_openfoam_org
// Accommodate name changes from 2019-11
template<class T>
FOAM_DEPRECATED_FOR(2019-11, "get(). openfoam.org compatibility")
T lookup
(
const word& keyword,
bool recursive = false,
bool patternMatch = true
) const
{
return get<T>(keyword, matchOpt(recursive, patternMatch));
}
#endif
// Shortcuts - when a templated classes also inherits from a dictionary
#undef defineDictionaryGetter
......
......@@ -55,6 +55,7 @@ namespace Foam
// Largest and smallest scalar values allowed in certain parts of the code.
// See std::numeric_limits max(), min(), epsilon()
constexpr doubleScalar doubleScalarGREAT = 1.0e+15;
constexpr doubleScalar doubleScalarROOTGREAT = 3.0e+8;
constexpr doubleScalar doubleScalarVGREAT = 1.0e+300;
constexpr doubleScalar doubleScalarROOTVGREAT = 1.0e+150;
constexpr doubleScalar doubleScalarSMALL = 1.0e-15;
......
......@@ -55,6 +55,7 @@ namespace Foam
// Largest and smallest scalar values allowed in certain parts of the code.
// See std::numeric_limits max(), min(), epsilon()
constexpr floatScalar floatScalarGREAT = 1.0e+6;
constexpr floatScalar floatScalarROOTGREAT = 1.0e+3;
constexpr floatScalar floatScalarVGREAT = 1.0e+37;
constexpr floatScalar floatScalarROOTVGREAT = 1.0e+18;
constexpr floatScalar floatScalarSMALL = 1.0e-6;
......
......@@ -53,6 +53,7 @@ SourceFiles
namespace Foam
{
constexpr scalar GREAT = floatScalarGREAT;
constexpr scalar ROOTGREAT = floatScalarROOTGREAT;
constexpr scalar VGREAT = floatScalarVGREAT;
constexpr scalar ROOTVGREAT = floatScalarROOTVGREAT;
constexpr scalar SMALL = floatScalarSMALL;
......@@ -60,21 +61,40 @@ namespace Foam
constexpr scalar VSMALL = floatScalarVSMALL;
constexpr scalar ROOTVSMALL = floatScalarROOTVSMALL;
#ifdef COMPAT_OPENFOAM_ORG
//! \cond compat_openfoam_org
// Accommodate name changes from 2018-01
constexpr scalar great = floatScalarGREAT;
constexpr scalar rootGreat = floatScalarROOTGREAT;
constexpr scalar vGreat = floatScalarVGREAT;
constexpr scalar rootVGreat = floatScalarROOTVGREAT;
constexpr scalar small = floatScalarSMALL;
constexpr scalar rootSmall = floatScalarROOTSMALL;
constexpr scalar vSmall = floatScalarVSMALL;
constexpr scalar rootVSmall = floatScalarROOTVSMALL;
//! \endcond
#endif
//- Read scalar from c-string and return value
inline scalar readScalar(const char* buf)
{
return readFloat(buf);
}
//- Read scalar from c-string into argument. Return true on success.
inline bool readScalar(const char* buf, scalar& val)
{
return readFloat(buf, val);
}
//- Read scalar from string and return value
inline scalar readScalar(const std::string& str)
{
return readFloat(str);
}
//- Read scalar from string into argument. Return true on success.
inline bool readScalar(const std::string& str, scalar& val)
{
return readFloat(str, val);
......@@ -101,6 +121,7 @@ namespace Foam
namespace Foam
{
constexpr scalar GREAT = doubleScalarGREAT;
constexpr scalar ROOTGREAT = doubleScalarROOTGREAT;
constexpr scalar VGREAT = doubleScalarVGREAT;
constexpr scalar ROOTVGREAT = doubleScalarROOTVGREAT;
constexpr scalar SMALL = doubleScalarSMALL;
......@@ -108,21 +129,40 @@ namespace Foam
constexpr scalar VSMALL = doubleScalarVSMALL;
constexpr scalar ROOTVSMALL = doubleScalarROOTVSMALL;
#ifdef COMPAT_OPENFOAM_ORG
//! \cond compat_openfoam_org
// Accommodate name changes from 2018-01
constexpr scalar great = doubleScalarGREAT;
constexpr scalar rootGreat = doubleScalarROOTGREAT;
constexpr scalar vGreat = doubleScalarVGREAT;
constexpr scalar rootVGreat = doubleScalarROOTVGREAT;
constexpr scalar small = doubleScalarSMALL;
constexpr scalar rootSmall = doubleScalarROOTSMALL;
constexpr scalar vSmall = doubleScalarVSMALL;
constexpr scalar rootVSmall = doubleScalarROOTVSMALL;
//! \endcond
#endif
//- Read scalar from c-string and return value
inline scalar readScalar(const char* buf)
{
return readDouble(buf);
}
//- Read scalar from c-string into argument. Return true on success.
inline bool readScalar(const char* buf, scalar& val)
{
return readDouble(buf, val);
}
//- Read scalar from string and return value
inline scalar readScalar(const std::string& str)
{
return readDouble(str);
}
//- Read scalar from string into argument. Return true on success.
inline bool readScalar(const std::string& str, scalar& val)
{
return readDouble(str, val);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment