-
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
Added convenience constructor to plugin #911
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f94339
Added convenience constructor to plugin
7dab7b9
Merge branch 'sdf12' into plugin_constructor
nkoenig 8170c6a
Merge branch 'sdf12' into plugin_constructor
nkoenig 5d574a4
Merge branch 'sdf12' into plugin_constructor
nkoenig 4e73bcb
Updated requirement of ign-common
e6fc820
use sdf::trim
4306703
Merge branch 'sdf12' into plugin_constructor
nkoenig b8e2d3b
Merge branch 'sdf12' into plugin_constructor
nkoenig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* | ||
*/ | ||
|
||
#include <ignition/common/Util.hh> | ||
#include "sdf/Plugin.hh" | ||
#include "sdf/parser.hh" | ||
#include "Utils.hh" | ||
|
@@ -42,6 +43,18 @@ Plugin::Plugin() | |
{ | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Plugin::Plugin(const std::string &_filename, const std::string &_name, | ||
const std::string &_xmlContent) | ||
: dataPtr(std::make_unique<sdf::PluginPrivate>()) | ||
{ | ||
this->SetFilename(_filename); | ||
this->SetName(_name); | ||
std::string trimmed = ignition::common::trimmed(_xmlContent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are only using ignition::common here, can you remove this dependency here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in e6fc820 |
||
if (!trimmed.empty()) | ||
this->InsertContent(trimmed); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Plugin::~Plugin() = default; | ||
|
||
|
@@ -175,6 +188,50 @@ void Plugin::InsertContent(const sdf::ElementPtr _elem) | |
this->dataPtr->contents.push_back(_elem->Clone()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
bool Plugin::InsertContent(const std::string _content) | ||
{ | ||
// Read the XML content | ||
auto xmlDoc = tinyxml2::XMLDocument(true, tinyxml2::COLLAPSE_WHITESPACE);; | ||
xmlDoc.Parse(_content.c_str()); | ||
if (xmlDoc.Error()) | ||
{ | ||
sdferr << "Error parsing XML from string: " << xmlDoc.ErrorStr() << '\n'; | ||
return false; | ||
} | ||
|
||
// Insert each XML element | ||
for (tinyxml2::XMLElement *xml = xmlDoc.FirstChildElement(); xml; | ||
xml = xml->NextSiblingElement()) | ||
{ | ||
sdf::ElementPtr element(new sdf::Element); | ||
|
||
// Copy the name | ||
element->SetName(xml->Name()); | ||
|
||
// Copy attributes | ||
for (const tinyxml2::XMLAttribute *attribute = xml->FirstAttribute(); | ||
attribute; attribute = attribute->Next()) | ||
{ | ||
element->AddAttribute(attribute->Name(), "string", "", 1, ""); | ||
element->GetAttribute(attribute->Name())->SetFromString( | ||
attribute->Value()); | ||
} | ||
|
||
// Copy the value | ||
if (xml->GetText() != nullptr) | ||
element->AddValue("string", xml->GetText(), true); | ||
|
||
// Copy all children | ||
copyChildren(element, xml, false); | ||
|
||
// Add the element to this plugin | ||
this->InsertContent(element); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Plugin &Plugin::operator=(const Plugin &_plugin) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we added
ignition::common
for USD I'm not really sure that you can use this dependency hereThere 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.
The dependency doesn't seem bad to me. Here is the code I'd duplicate, which I could trim (haha) down:
Utilizing existing code rather than duplicating it seems like something we should do internally. Otherwise, we should be telling users to copy our code, and not use the libraries.
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.
I don't think we should add a dependency in a stable version. We already have
sdf::trim
that can be used instead.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.
Good point, this is a stable version.
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.
Done in e6fc820
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.
Adding
ign-common
as a dependency to the core of SDF is something we should think carefully about. That brings a lot of dependencies. An alternative to consider would be to move some of this functionality toign-utils
.