Generalize ostreams used for console output in GridSlamProcessor #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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