The GridSlamProcessor class already had a member variable std::ostream& m_infoStream; which is used in some places to write console output for logs and general info. This stream can be set through the class' constructor, so users have some control over the output from the class. However, many functions in this class were writing directly to std::cerr instead, which cannot be controlled without modifying the code itself.
Description
This PR generalizes uses of cerr in gridslamprocessor.cpp to use m_infoStream or a new member variable m_errStream. Most of the cerr statements seemed more informative than error-based, so most have been changed to use the former.
The class constructor now accepts two optional arguments, infoStr and errStr, which default to std::cout and std::cerr respectively. I have combined the existing two constructors into this new one by using optional arguments.
Finally, I have introduced a new utility file nullstream.h, containing a class definition and a global/static variable g_null_stream. When constructing the class, a user can pass this argument for infoStr and/or errStr to effectively suppress console output from GridSlamProcessor.
(I would be fine reverting the nullstream addition if y'all would prefer to merge the previously mentioned ostream generalizations on their own. This was just kind of annoying to get working, so I figured I'd add it for others to use too.)
Testing
This change should have no effect on the performance itself, and other than some things printing to cout instead of cerr by default, the console output will not change by default. New behavior is only achieved by a runner class modifying its constructor call.
I have tested this on our usage of the GridSlamProcessor in our own code, and see all the usual console outputs when constructing the class with
Motivation
The
GridSlamProcessor
class already had a member variablestd::ostream& m_infoStream;
which is used in some places to write console output for logs and general info. This stream can be set through the class' constructor, so users have some control over the output from the class. However, many functions in this class were writing directly tostd::cerr
instead, which cannot be controlled without modifying the code itself.Description
This PR generalizes uses of
cerr
ingridslamprocessor.cpp
to usem_infoStream
or a new member variablem_errStream
. Most of thecerr
statements seemed more informative than error-based, so most have been changed to use the former.The class constructor now accepts two optional arguments,
infoStr
anderrStr
, which default tostd::cout
andstd::cerr
respectively. I have combined the existing two constructors into this new one by using optional arguments.Finally, I have introduced a new utility file
nullstream.h
, containing a class definition and a global/static variableg_null_stream
. When constructing the class, a user can pass this argument forinfoStr
and/orerrStr
to effectively suppress console output fromGridSlamProcessor
. (I would be fine reverting the nullstream addition if y'all would prefer to merge the previously mentioned ostream generalizations on their own. This was just kind of annoying to get working, so I figured I'd add it for others to use too.)Testing
This change should have no effect on the performance itself, and other than some things printing to
cout
instead ofcerr
by default, the console output will not change by default. New behavior is only achieved by a runner class modifying its constructor call.I have tested this on our usage of the
GridSlamProcessor
in our own code, and see all the usual console outputs when constructing the class withor
and am able to run it just the same, but without any console outputs, with