Skip to content

Commit e3914f7

Browse files
committed
Reduce/Eliminate sdf::Model and sdf::World serialization warnings
- Reduces serialization warnings on `sdf::Model` so it only occurs when the `relative_to` attribute is set. This was the intended behavior originally, but there was a bug in the code. - Eliminate `sdf::World` warnings by specializing the `DefaultSerializer` for `sdf::World`. Signed-off-by: Addisu Z. Taddese <[email protected]>
1 parent 06e16bc commit e3914f7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

include/gz/sim/components/Model.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace serializers
5454
if (modelElem->HasElement("pose"))
5555
{
5656
sdf::ElementPtr poseElem = modelElem->GetElement("pose");
57-
if (poseElem->HasAttribute("relative_to"))
57+
if (poseElem->GetAttribute("relative_to")->GetSet())
5858
{
5959
// Skip serializing models with //pose/@relative_to attribute
6060
// since deserialization will fail. This could be a nested model.

include/gz/sim/components/World.hh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ namespace sim
2929
{
3030
// Inline bracket to help doxygen filtering.
3131
inline namespace GZ_SIM_VERSION_NAMESPACE {
32+
33+
namespace serializers
34+
{
35+
/// \brief Specialize the DefaultSerializer on sdf::World so we can
36+
/// skip serialization
37+
/// TODO(azeey) Do we ever want to serialize this component?
38+
template <>
39+
class DefaultSerializer<sdf::World>
40+
{
41+
public:
42+
static std::ostream &Serialize(std::ostream &_out, const sdf::World &)
43+
{
44+
return _out;
45+
}
46+
47+
public:
48+
static std::istream &Deserialize(std::istream &_in, sdf::World &)
49+
{
50+
return _in;
51+
}
52+
};
53+
}
54+
3255
namespace components
3356
{
3457
/// \brief A component that identifies an entity as being a world.

0 commit comments

Comments
 (0)