-
Notifications
You must be signed in to change notification settings - Fork 100
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
Get the world name #1027
Get the world name #1027
Conversation
Signed-off-by: ahcorde <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #1027 +/- ##
=======================================
Coverage 83.11% 83.12%
=======================================
Files 154 154
Lines 18685 18702 +17
=======================================
+ Hits 15530 15546 +16
- Misses 3155 3156 +1
Continue to review full report at Codecov.
|
if(pworld) | ||
{ | ||
_worldName = pworld->Attribute("name"); | ||
} |
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.
Error on else
?
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.
Is this resolved?
src/Root_TEST.cc
Outdated
@@ -65,6 +66,16 @@ TEST(DOMRoot, MoveAssignmentOperator) | |||
EXPECT_EQ("test_root", root2.Version()); | |||
} | |||
|
|||
TEST(DOMRoot, GetWorldName) |
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.
It would be interesting to test some failure cases
Signed-off-by: ahcorde <[email protected]>
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.
In general, I have reservations about this approach because it doesn't go through the normal error checking process of the parser. It also results in loading the file into TinyXML twice, the second time when sdf::Root::Load
is called.
Here are some other ideas to consider:
- Avoid the need for a world name in the first place. Maybe we can just use the global topic namespace for single worlds and have world-specific namespaces when we add support for multiple worlds. BTW, this implementation of
WorldName
doesn't return all the world names in a file. What would be our plan when we want to add support for multiple worlds? - Generate a unique topic namespace for a given world during load (eg.
/world/UUID/topic/name
) and then have some sort of topic and service remapping function in ign transport that maps/world/<world name>
to/world/UUID
once the world name is obtained from the fully loaded world. - Implement a partial parser in SDFormat where
include
files are not processed. This would still suffer from the error checking issue I mentioned, but it wouldn't load the file twice.
include/sdf/Root.hh
Outdated
/// \param[in] _filename Name of the SDF file to parse. | ||
/// \param[out] _worldName The name of the world | ||
/// \return Errors, which is a vector of Error objects. Each Error includes | ||
/// an error code and message. An empty vector indicates no error. | ||
public: Errors GetWorldName(const std::string &_filename, | ||
std::string &_worldName); | ||
public: Errors WorldName(const std::string &_filename, |
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.
Please rename this to WorldNameFromFile
or something to indicate that this isn't returning a fully loaded world.
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.
Signed-off-by: ahcorde <[email protected]>
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.
Approving with my reservation stated above.
if(pworld) | ||
{ | ||
_worldName = pworld->Attribute("name"); | ||
} |
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.
Is this resolved?
…rmat into ahcorde/root/worldname
Signed-off-by: ahcorde <[email protected]>
…rmat into ahcorde/root/worldname
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.
LGTM with green CI
Signed-off-by: ahcorde [email protected]
🎉 New feature
Summary
Get just the world name instead of reading the whole file. This is required by this other PR gazebosim/gz-sim#1484
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.