Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize ostreams used for console output in GridSlamProcessor #45

Open
wants to merge 3 commits into
base: melodic-devel
Choose a base branch
from

Conversation

kevin-robb
Copy link

Motivation

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

std::unique_ptr<GMapping::GridSlamProcessor> m_gsp = std::make_unique<GMapping::GridSlamProcessor>();

or

std::unique_ptr<GMapping::GridSlamProcessor> m_gsp = std::make_unique<GMapping::GridSlamProcessor>(std::cout, std::cerr);

and am able to run it just the same, but without any console outputs, with

std::unique_ptr<GMapping::GridSlamProcessor> m_gsp = std::make_unique<GMapping::GridSlamProcessor>(GMapping::g_null_stream, GMapping::g_null_stream);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant