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

Get the world name #1027

Merged
merged 16 commits into from
Jul 8, 2022
Merged

Get the world name #1027

merged 16 commits into from
Jul 8, 2022

Conversation

ahcorde
Copy link
Collaborator

@ahcorde ahcorde commented May 23, 2022

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

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

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.

Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde requested a review from azeey as a code owner May 23, 2022 15:21
@ahcorde ahcorde self-assigned this May 23, 2022
@ahcorde ahcorde requested a review from scpeters as a code owner May 23, 2022 15:21
@github-actions github-actions bot added the 🌱 garden Ignition Garden label May 23, 2022
@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #1027 (4cbab2d) into main (1570833) will increase coverage by 0.01%.
The diff coverage is 94.11%.

@@           Coverage Diff           @@
##             main    #1027   +/-   ##
=======================================
  Coverage   83.11%   83.12%           
=======================================
  Files         154      154           
  Lines       18685    18702   +17     
=======================================
+ Hits        15530    15546   +16     
- Misses       3155     3156    +1     
Impacted Files Coverage Δ
src/Root.cc 95.04% <94.11%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1570833...4cbab2d. Read the comment docs.

@chapulina chapulina added the OOBE 📦✨ Out-of-box experience label May 23, 2022
include/sdf/Root.hh Outdated Show resolved Hide resolved
include/sdf/Root.hh Outdated Show resolved Hide resolved
src/Root.cc Outdated Show resolved Hide resolved
src/Root.cc Outdated Show resolved Hide resolved
if(pworld)
{
_worldName = pworld->Attribute("name");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error on else?

Copy link
Collaborator

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)
Copy link
Contributor

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

Copy link
Collaborator

@azeey azeey left a 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 Show resolved Hide resolved
/// \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,
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahcorde ahcorde requested review from azeey and chapulina June 29, 2022 00:06
Copy link
Collaborator

@azeey azeey left a 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");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this resolved?

include/sdf/Root.hh Outdated Show resolved Hide resolved
Copy link
Member

@scpeters scpeters left a 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

@ahcorde ahcorde merged commit fdd9861 into main Jul 8, 2022
@ahcorde ahcorde deleted the ahcorde/root/worldname branch July 8, 2022 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden OOBE 📦✨ Out-of-box experience
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants