Gazebo Sim

API Reference

8.10.0
SemanticTags.hh
Go to the documentation of this file.
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 
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 namespace serializers
38 {
40 {
41  public:
43  const std::vector<std::string> &_tags)
44  {
45  msgs::StringMsg_V msg;
46  for (const auto &tag : _tags)
47  {
48  msg.add_data(tag);
49  }
50  msg.SerializeToOstream(&_out);
51  return _out;
52  }
53 
54  public:
57  {
58  msgs::StringMsg_V msg;
59  msg.ParsePartialFromIstream(&_in);
60  _tags.clear();
61  for (const auto &item : msg.data())
62  {
63  _tags.push_back(item);
64  }
65  return _in;
66  }
67 };
68 } // namespace serializers
69 //
70 namespace components
71 {
72 
77 using SemanticTags = Component<std::vector<std::string>, class SemanticTagsTag,
78  serializers::SemanticTagsSerializer>;
79 GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticTags", SemanticTags)
80 } // namespace components
81 } // namespace GZ_SIM_VERSION_NAMESPACE
82 } // namespace sim
83 } // namespace gz
84 #endif