Gazebo Sim

API Reference

9.5.0
SemanticDescription.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_DESCRIPTION_HH_
18#define GZ_SIM_COMPONENTS_SEMANTIC_DESCRIPTION_HH_
19
20#include <gz/msgs/stringmsg.pb.h>
21
22#include <istream>
23#include <ostream>
24#include <string>
25
29#include "gz/sim/config.hh"
30
31namespace gz
32{
33namespace sim
34{
35// Inline bracket to help doxygen filtering.
36inline namespace GZ_SIM_VERSION_NAMESPACE
37{
38namespace serializers
39{
41{
42 public:
43 static std::ostream &Serialize(std::ostream &_out, const std::string &_desc)
44 {
45 msgs::StringMsg msg;
46 msg.set_data(_desc);
47 auto result = msg.SerializeToOstream(&_out);
48 (void)result;
49 return _out;
50 }
51
52 public:
54 {
55 msgs::StringMsg msg;
56 if(msg.ParsePartialFromIstream(&_in))
57 {
58 _desc = msg.data();
59 }
60 return _in;
61 }
62};
63} // namespace serializers
64namespace components
65{
70using SemanticDescription = Component<std::string, class SemanticDescriptionTag,
71 serializers::StringSerializer>;
72GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticDescription",
73 SemanticDescription)
74} // namespace components
75} // namespace GZ_SIM_VERSION_NAMESPACE
76} // namespace sim
77} // namespace gz
78#endif