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
[SofaCore] Add virtual getPathName function in Base #1455
[SofaCore] Add virtual getPathName function in Base #1455
Conversation
Both BaseObject and BaseNode have a getPathName function, but those can't be called from a Base ptr without dereferencing with toBaseNode / toBaseObject
@@ -180,6 +180,9 @@ class SOFA_CORE_API Base | |||
std::initializer_list<BaseData*> outputs); | |||
void addOutputsToCallback(const std::string& name, std::initializer_list<BaseData*> outputs); | |||
|
|||
|
|||
virtual std::string getPathName() const { return ""; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly, I don't like it much but I can't put a virtual pure here since BaseContext also inherits Base, which means more than 1 final overrider for Node (inherits BaseNode & BaseContext...)
@@ -224,7 +224,7 @@ class SOFA_CORE_API BaseData : public DDGNode | |||
/// @} | |||
|
|||
/// If we use the Data as a link and not as value directly | |||
std::string getLinkPath() const { return parentBaseData.getPath(); } | |||
virtual std::string getLinkPath() const { return parentBaseData.getPath(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with the PR, but I need this to be overridable for custom Data in SofaQtQuick
Hello @marques-bruno My assumption is that, initially, Base was supposed to be more the Base class for "everything" and not only for scenegraph entries. This is why the initial design was that there is no "path" concept at this level. My current approach to handle this kind of scenario was to implement an easing function like that: std::string sofa::helper::objectmodel::getPathName(Base* o)
{
BaseNode *node = dynamic_cast<BaseNode>(o);
if(node)
return node->getPathName();
BaseObject *object = dynamic_cast<BaseNode>(o);
if(object)
return object->getPathName();
...
} To avoid having if/else and dynamic cast at every call and thus easing the readability on the caller's. |
Let's get rid of BaseContext! ;) I would not bet too much on performance improvement without making small benchmark. But in a function that basically returns strings build by concatenating ... I would say this is probably very small. In addition it has to be noted that using a getPathName() explingn function with if/else has a linear complexity in the amount of possible types (number of if/else) while a virtual getPathName in Base has a constant cost. But again...the calling costs is probably very small compared to what the function actually do :) |
[ci-build] |
Both BaseObject and BaseNode have a getPathName function, but those can't be called from a Base ptr without dereferencing with toBaseNode / toBaseObject.
This PR:
Reviewers will merge only if all these checks are true.