ENH: add clear/append method to Enum and std::ostream output

- allows use of Enum in more situations where a tiny Map/HashTable
  replacement is desirable. The new methods can be combined with
  null constructed for to have a simple low-weight caching system
  for words/integers instead of fitting in a HashTable.
This commit is contained in:
Mark Olesen
2019-11-25 18:15:31 +01:00
committed by Andrew Heather
parent daac96f165
commit 6dd3cd0e51
4 changed files with 148 additions and 6 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -73,7 +73,7 @@ const Foam::Enum<int> otherNames1
// Can use for integers as well, but not scalar etc.
const Foam::Enum<int> otherNames2
Foam::Enum<int> otherNames2
({
{ 0, "a" },
{ 2, "b" },
@ -110,6 +110,34 @@ int main(int argc, char *argv[])
<< " values: " << flatOutput(otherNames2.values())
<< nl << nl;
otherNames2.append
({
{ 15, "fifteen"},
{ 16, "sixteen"}
});
Info<<"Other Enum (appended)" << nl
<< " names: " << otherNames2 << nl
<< " values: " << flatOutput(otherNames2.values())
<< nl << nl;
std::cout
<<"stdout: "<< otherNames2
<< nl << nl;
otherNames2.clear();
otherNames2.append
({
{ 1, "one"},
{ 2, "two"}
});
Info<<"After clear and append:" << nl
<< otherNames2 << nl
<< otherNames2.values() << nl
<< nl;
dictionary testDict;
testDict.add("lookup1", "c");