ENH: minor adjustments to Switch

- assignment operators return a value, for consistency with bool.

- partial revert of DEFAULT_TRUE, DEFAULT_FALSE, to reduce complexity.
This commit is contained in:
Mark Olesen
2019-01-29 09:38:09 +01:00
parent 73705d8290
commit 3316055267
3 changed files with 33 additions and 39 deletions

View File

@ -61,6 +61,12 @@ inline Switch readSwitch(const std::string& str)
}
void printInfo(const Switch& sw)
{
Info<<"Switch " << sw.c_str() << " (enum=" << label(sw.type()) << ")\n";
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T>
@ -162,19 +168,22 @@ int main(int argc, char *argv[])
}
);
Info<< nl << "Test Switch defaults:" << nl;
dictionary dict;
dict.add("key1" , "true");
dict.add("key2" , "off");
for (const word& k : { "key", "key1", "key2" })
{
Switch sw("key", dict, Switch::DEFAULT_ON);
Info<<"got: " << sw << " type is DEFAULT_ON? "
<< (sw.type() == Switch::DEFAULT_ON) << nl;
}
Switch sw1(k, dict, Switch::YES);
Switch sw2(k, dict, Switch::NO);
{
Switch sw("key1", dict, Switch::DEFAULT_ON);
Info<<"got: " << sw << " type is DEFAULT_ON? "
<< (sw.type() == Switch::DEFAULT_ON) << nl;
bool sw3(Switch(k, dict, Switch::YES));
printInfo(sw1);
printInfo(sw2);
Info<<"bool " << sw3 << nl;
}
}