From 4d18fea8e1695b0270110f7e676d1ce6141cf4bb Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 18 Nov 2019 09:13:58 +0100 Subject: [PATCH] ENH: add value_type to dimensioned type. Add Switch::name(bool) --- applications/test/autoPtr/Test-autoPtr.C | 8 ++++---- .../dimensionedTypes/dimensionedType/dimensionedType.H | 7 +++++-- src/OpenFOAM/primitives/bools/Switch/Switch.C | 6 ++++++ src/OpenFOAM/primitives/bools/Switch/Switch.H | 6 ++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/applications/test/autoPtr/Test-autoPtr.C b/applications/test/autoPtr/Test-autoPtr.C index 0eb6a082a8..d0b18a0dad 100644 --- a/applications/test/autoPtr/Test-autoPtr.C +++ b/applications/test/autoPtr/Test-autoPtr.C @@ -44,7 +44,7 @@ void testTransfer1(autoPtr ap) // Passed in copy, so automatically removes content // Transfer would be nice, but not actually needed - Info<< "recv " << Switch(ap.valid()).c_str() << nl; + Info<< "recv " << Switch::name(ap.valid()) << nl; } @@ -53,7 +53,7 @@ void testTransfer1(autoPtr ap) void testTransfer2(autoPtr&& ap) { // As rvalue, so this time we actually get to manage content - Info<< "recv " << Switch(ap.valid()).c_str() << nl; + Info<< "recv " << Switch::name(ap.valid()) << nl; } @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) testTransfer2(std::move(list)); - Info<<"now have valid=" << Switch(list.valid()).c_str(); + Info<<"now have valid=" << Switch::name(list.valid()); if (list) { @@ -209,7 +209,7 @@ int main(int argc, char *argv[]) testTransfer2(std::move(list)); - Info<<"now have valid=" << Switch(list.valid()).c_str(); + Info<<"now have valid=" << Switch::name(list.valid()); if (list.valid()) { diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H index b5aac59399..823c255723 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H @@ -114,6 +114,9 @@ class dimensioned public: + //- The underlying data type + typedef Type value_type; + //- Component type typedef typename pTraits::cmptType cmptType; @@ -157,7 +160,7 @@ public: // If the optional dimensions are present, they are read and // used without further verification. // If no dimensions are found, the quantity is dimensionless. - // Fatal if not a primitiveEntry or if the number of tokens is incorrect. + // Fatal if not primitiveEntry or if number of tokens is incorrect. explicit dimensioned(const primitiveEntry& e); //- Construct from primitive entry with given name and dimensions. @@ -168,7 +171,7 @@ public: // If the optional name is found, it is used for renaming. // If the optional dimensions are present, they are read and // verified against the expected dimensions. - // Fatal if not a primitiveEntry or if the number of tokens is incorrect. + // Fatal if not primitiveEntry or if number of tokens is incorrect. explicit dimensioned(const primitiveEntry& e, const dimensionSet& dims); //- Construct from dictionary lookup with a given name. diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 79f53a8cd4..68323e95b4 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -56,6 +56,12 @@ static const char* names[9] = // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // +const char* Foam::Switch::name(const bool b) noexcept +{ + return names[(b ? 0 : 1)]; +} + + Foam::Switch::switchType Foam::Switch::parse ( const std::string& str, diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index 91ea272a6e..b12b1e1abf 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -189,6 +189,12 @@ public: ); + // Static Member Functions + + //- A string representation of bool as "false" / "true" + static const char* name(const bool b) noexcept; + + // Member Functions //- True if the Switch represents a valid enumeration