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

Add the ability to use raw pointers in Subscriber #14

Merged
merged 2 commits into from Nov 19, 2018

Conversation

Projects
None yet
2 participants
@mjcarroll
Copy link
Contributor

commented Nov 16, 2018

Using only SharedPtr was causing an issue in objects that are subclassed from Node.

If you want to create a message_filter::Subscriber as part of the subclass constructor, there was no way to get a shared pointer to the node instance itself to pass in. shared_from_this is not allowed in constructors for reasons listed here: https://en.cppreference.com/w/cpp/memory/enable_shared_from_this

As a workaround, I added an additional API where users can create a Subscriber using a raw pointer. The only downside to this is that the user is fully responsible for mananging the lifetime of the message_filter::Subscriber to ensure that it doesn't outlive the Node. In the case where it is a member of a Node subclass, this is not an issue.

@wjwwood
Copy link
Member

left a comment

lgtm, other than some small comments.

Show resolved Hide resolved include/message_filters/subscriber.h
Show resolved Hide resolved include/message_filters/subscriber.h Outdated
Show resolved Hide resolved test/test_subscriber.cpp Outdated

@mjcarroll mjcarroll merged commit 9b55fe3 into master Nov 19, 2018

@mjcarroll mjcarroll deleted the pointer_api_updates branch Nov 19, 2018

@mjcarroll mjcarroll removed the in review label Nov 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.