ENH: add value_type to dimensioned type. Add Switch::name(bool)

This commit is contained in:
Mark Olesen
2019-11-18 09:13:58 +01:00
committed by Andrew Heather
parent 311f29947d
commit 4d18fea8e1
4 changed files with 21 additions and 6 deletions

View File

@ -44,7 +44,7 @@ void testTransfer1(autoPtr<labelList> ap)
// Passed in copy, so automatically removes content // Passed in copy, so automatically removes content
// Transfer would be nice, but not actually needed // 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<labelList> ap)
void testTransfer2(autoPtr<labelList>&& ap) void testTransfer2(autoPtr<labelList>&& ap)
{ {
// As rvalue, so this time we actually get to manage content // 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)); testTransfer2(std::move(list));
Info<<"now have valid=" << Switch(list.valid()).c_str(); Info<<"now have valid=" << Switch::name(list.valid());
if (list) if (list)
{ {
@ -209,7 +209,7 @@ int main(int argc, char *argv[])
testTransfer2(std::move(list)); testTransfer2(std::move(list));
Info<<"now have valid=" << Switch(list.valid()).c_str(); Info<<"now have valid=" << Switch::name(list.valid());
if (list.valid()) if (list.valid())
{ {

View File

@ -114,6 +114,9 @@ class dimensioned
public: public:
//- The underlying data type
typedef Type value_type;
//- Component type //- Component type
typedef typename pTraits<Type>::cmptType cmptType; typedef typename pTraits<Type>::cmptType cmptType;
@ -157,7 +160,7 @@ public:
// If the optional dimensions are present, they are read and // If the optional dimensions are present, they are read and
// used without further verification. // used without further verification.
// If no dimensions are found, the quantity is dimensionless. // 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); explicit dimensioned(const primitiveEntry& e);
//- Construct from primitive entry with given name and dimensions. //- 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 name is found, it is used for renaming.
// If the optional dimensions are present, they are read and // If the optional dimensions are present, they are read and
// verified against the expected dimensions. // 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); explicit dimensioned(const primitiveEntry& e, const dimensionSet& dims);
//- Construct from dictionary lookup with a given name. //- Construct from dictionary lookup with a given name.

View File

@ -56,6 +56,12 @@ static const char* names[9] =
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
const char* Foam::Switch::name(const bool b) noexcept
{
return names[(b ? 0 : 1)];
}
Foam::Switch::switchType Foam::Switch::parse Foam::Switch::switchType Foam::Switch::parse
( (
const std::string& str, const std::string& str,

View File

@ -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 // Member Functions
//- True if the Switch represents a valid enumeration //- True if the Switch represents a valid enumeration