add easy ToString / ostream output for adios2 enums and cxx11 interface classes
Created by: germasch
Since I guess #1328 become rather complicated, which I suppose may be why it's been sitting out there, I figured I'll redo just the major part of it. For detailed discussion, #1328 might still provide a useful reference.
I've had this sitting around for a while, and let me start by saying that I don't have strong feelings about it. It adds a somewhat neat feature making it easier to give human-readable output for some enums, but it could also be considered rarely needed bloat.
Essentially, the PR adds adios::tostring
and overloads for the ostream operator<<
for enum classes. It allows you to do, e.g.,
std::cout << variable.ShapeID() << std::endl;
and get human readable output. It gets picked up by googletest, so on an (intentionally failing) test, instead of
../testing/adios2/engine/bp/TestBPWriteReadADIOS2.cpp:186: Failure
Expected equality of these values:
var_i8.ShapeID()
Which is: 4-byte object <02-00 00-00>
adios2::ShapeID::LocalArray
Which is: 4-byte object <05-00 00-00>
you get
../testing/adios2/engine/bp/TestBPWriteReadADIOS2.cpp:186: Failure
Expected equality of these values:
var_i8.ShapeID()
Which is: ShapeID::GlobalArray
adios2::ShapeID::LocalArray
Which is: ShapeID::LocalArray
It also adds support for printing the man cxx11 interface classes (Variable, Attribute, IO, Engine, Operator). So you can now do std::cout << variable
to do something akin to Python's __str__
method, which might be useful for debugging.
Following @chuckatkins comments, I amended the original code to avoid one SFINAE overcomplication and used switch/case instead of maps for mapping enums to strings. I also added tests and some docs, and rebased onto current master.