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

Names with spaces: add string serializer #244

Merged
merged 4 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Ignition Gazebo 4.0.0 (20XX-XX-XX)

1. Names with spaces: add string serializer
* [pull request 244](https://github.com/ignitionrobotics/ign-gazebo/pull/244)

1. Filter mesh collision based on `collide_bitmask` property
* [pull request 160](https://github.com/ignitionrobotics/ign-gazebo/pull/160)

Expand Down
4 changes: 4 additions & 0 deletions examples/worlds/fuel.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@

<!-- Included model without meshes -->
<include>
<name>Double pendulum</name>
<pose>-3 0 0 0 0 0</pose>
<uri>https://fuel.ignitionrobotics.org/1.0/nate/models/double_pendulum_with_base/2</uri>
</include>
Expand All @@ -134,12 +135,15 @@

<!-- Included model with meshes using relative paths -->
<include>
<name>Gazebo (relative paths)</name>
<pose>2 5 0 0 0 0</pose>
<uri>https://fuel.ignitionrobotics.org/1.0/chapulina/models/Gazebo - relative paths</uri>
</include>

<!-- Included actor with meshes using relative paths -->
<include>
<name>Actor Test</name>
<pose>0 0 0 0 0 0</pose>
<uri>https://fuel.ignitionrobotics.org/1.0/chapulina/models/actor - relative paths</uri>
</include>

Expand Down
3 changes: 2 additions & 1 deletion include/ignition/gazebo/components/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace components
AnimationTime)

/// \brief Name of animation being currently played.
using AnimationName = Component<std::string, class AnimationNameTag>;
using AnimationName = Component<std::string, class AnimationNameTag,
serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.AnimationName",
AnimationName)
}
Expand Down
6 changes: 4 additions & 2 deletions include/ignition/gazebo/components/ChildLinkName.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#define IGNITION_GAZEBO_COMPONENTS_CHILDLINKNAME_HH_

#include <string>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
Expand All @@ -32,7 +33,8 @@ namespace components
{
/// \brief A component used to indicate that a model is childlinkname (i.e.
/// not moveable).
using ChildLinkName = Component<std::string, class ChildLinkNameTag>;
using ChildLinkName = Component<std::string, class ChildLinkNameTag,
serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.ChildLinkName", ChildLinkName)
}
Expand Down
14 changes: 8 additions & 6 deletions include/ignition/gazebo/components/LevelEntityNames.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ namespace serializers
public: static std::ostream &Serialize(std::ostream &_out,
const std::set<std::string> &_set)
{
// Character to separate level names. It's the "Unit separator".
const char sep = 31;

for (const auto &entity : _set)
{
_out << entity << " ";
_out << entity << sep;
}
return _out;
}
Expand All @@ -57,14 +60,13 @@ namespace serializers
public: static std::istream &Deserialize(std::istream &_in,
std::set<std::string> &_set)
{
_in.setf(std::ios_base::skipws);

_set.clear();

for (auto it = std::istream_iterator<std::string>(_in);
it != std::istream_iterator<std::string>(); ++it)
const char sep = 31;
std::string level;
while (std::getline(_in, level, sep))
{
_set.insert(*it);
_set.insert(level);
}
return _in;
}
Expand Down
4 changes: 3 additions & 1 deletion include/ignition/gazebo/components/Name.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
Expand All @@ -32,7 +33,8 @@ namespace components
{
/// \brief This component holds an entity's name. The component has no concept
/// of scoped names nor does it care about uniqueness.
using Name = Component<std::string, class NameTag>;
using Name = Component<std::string, class NameTag,
serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.Name", Name)
}
}
Expand Down
6 changes: 4 additions & 2 deletions include/ignition/gazebo/components/ParentLinkName.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#define IGNITION_GAZEBO_COMPONENTS_PARENTLINKNAME_HH_

#include <string>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
Expand All @@ -31,7 +32,8 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace components
{
/// \brief Holds the name of the entity's parent link.
using ParentLinkName = Component<std::string, class ParentLinkNameTag>;
using ParentLinkName = Component<std::string, class ParentLinkNameTag,
serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.ParentLinkName", ParentLinkName)
}
Expand Down
6 changes: 4 additions & 2 deletions include/ignition/gazebo/components/PerformerAffinity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>

#include "ignition/gazebo/components/Factory.hh"
#include "ignition/gazebo/components/Component.hh"
#include "ignition/gazebo/components/Factory.hh"
#include "ignition/gazebo/components/Serialization.hh"

namespace ignition
{
Expand All @@ -35,7 +36,8 @@ namespace components
{
/// \brief This component holds the address of the distributed secondary that
/// this performer is associated with.
using PerformerAffinity = Component<std::string, class PerformerAffinityTag>;
using PerformerAffinity = Component<std::string, class PerformerAffinityTag,
serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.PerformerAffinity",
PerformerAffinity)
}
Expand Down
3 changes: 2 additions & 1 deletion include/ignition/gazebo/components/PhysicsEnginePlugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
Expand All @@ -32,7 +33,7 @@ namespace components
{
/// \brief Holds the physics engine shared library.
using PhysicsEnginePlugin = Component<std::string,
class PhysicsEnginePluginTag>;
class PhysicsEnginePluginTag, serializers::StringSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.PhysicsEnginePlugin",
PhysicsEnginePlugin)
}
Expand Down
27 changes: 27 additions & 0 deletions include/ignition/gazebo/components/Serialization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <google/protobuf/message_lite.h>
#include <ignition/msgs/double_v.pb.h>

#include <string>
#include <vector>
#include <sdf/Sensor.hh>

Expand Down Expand Up @@ -156,6 +157,32 @@ namespace serializers
return _in;
}
};

/// \brief Serializer for components that hold std::string.
class StringSerializer
{
/// \brief Serialization
/// \param[in] _out Output stream.
/// \param[in] _data Data to serialize.
/// \return The stream.
public: static std::ostream &Serialize(std::ostream &_out,
const std::string &_data)
{
_out << _data;
return _out;
}

/// \brief Deserialization
/// \param[in] _in Input stream.
/// \param[in] _data Data to populate.
/// \return The stream.
public: static std::istream &Deserialize(std::istream &_in,
std::string &_data)
{
_data = std::string(std::istreambuf_iterator<char>(_in), {});
return _in;
}
};
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion include/ignition/gazebo/components/SourceFilePath.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
Expand All @@ -33,7 +34,8 @@ namespace components
/// \brief This component holds the filepath to the source from which an
/// entity is created. For example, it can be used to store the file path of a
/// model's SDFormat file.
using SourceFilePath = Component<std::string, class SourceFilePathTag>;
using SourceFilePath = Component<std::string, class SourceFilePathTag,
serializers::StringSerializer>;

IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.SourceFilePath",
SourceFilePath)
Expand Down
Loading