|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | +#ifndef GZ_SIM_COMPONENTS_SEMANTIC_TAGS_HH_ |
| 18 | +#define GZ_SIM_COMPONENTS_SEMANTIC_TAGS_HH_ |
| 19 | + |
| 20 | +#include <gz/msgs/stringmsg_v.pb.h> |
| 21 | + |
| 22 | +#include <istream> |
| 23 | +#include <ostream> |
| 24 | +#include <string> |
| 25 | +#include <vector> |
| 26 | + |
| 27 | +#include "gz/sim/components/Component.hh" |
| 28 | +#include "gz/sim/components/Factory.hh" |
| 29 | +#include "gz/sim/config.hh" |
| 30 | + |
| 31 | +namespace gz |
| 32 | +{ |
| 33 | +namespace sim |
| 34 | +{ |
| 35 | +// Inline bracket to help doxygen filtering. |
| 36 | +inline namespace GZ_SIM_VERSION_NAMESPACE |
| 37 | +{ |
| 38 | +namespace serializers |
| 39 | +{ |
| 40 | +class SemanticTagsSerializer |
| 41 | +{ |
| 42 | + public: |
| 43 | + static std::ostream &Serialize(std::ostream &_out, |
| 44 | + const std::vector<std::string> &_tags) |
| 45 | + { |
| 46 | + msgs::StringMsg_V msg; |
| 47 | + for (const auto &tag : _tags) |
| 48 | + { |
| 49 | + msg.add_data(tag); |
| 50 | + } |
| 51 | + msg.SerializeToOstream(&_out); |
| 52 | + return _out; |
| 53 | + } |
| 54 | + |
| 55 | + public: |
| 56 | + static std::istream &Deserialize(std::istream &_in, |
| 57 | + std::vector<std::string> &_tags) |
| 58 | + { |
| 59 | + msgs::StringMsg_V msg; |
| 60 | + msg.ParsePartialFromIstream(&_in); |
| 61 | + _tags.clear(); |
| 62 | + for (const auto &item : msg.data()) |
| 63 | + { |
| 64 | + _tags.push_back(item); |
| 65 | + } |
| 66 | + return _in; |
| 67 | + } |
| 68 | +}; |
| 69 | +} // namespace serializers |
| 70 | +// |
| 71 | +namespace components |
| 72 | +{ |
| 73 | + |
| 74 | +/// \brief A component that holds the semantic tag of an entity. This is |
| 75 | +/// meant to be used by systems such as EntitySemantics to assign tags to |
| 76 | +/// entities. See |
| 77 | +/// https://github.com/ros-simulation/simulation_interfaces/blob/1.0.0/msg/TagsFilter.msg |
| 78 | +using SemanticTags = Component<std::vector<std::string>, class SemanticTagsTag, |
| 79 | + serializers::SemanticTagsSerializer>; |
| 80 | +GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticTags", SemanticTags) |
| 81 | +} // namespace components |
| 82 | +} // namespace GZ_SIM_VERSION_NAMESPACE |
| 83 | +} // namespace sim |
| 84 | +} // namespace gz |
| 85 | +#endif |
0 commit comments