AWViz-ROS
Loading...
Searching...
No Matches
property.hpp
Go to the documentation of this file.
1// Copyright 2024 Kotaro Uetake.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef AWVIZ_COMMON__PROPERTY_HPP_
16#define AWVIZ_COMMON__PROPERTY_HPP_
17
18#include <memory>
19#include <optional>
20#include <string>
21#include <unordered_map>
22
23namespace awviz_common
24{
29{
30public:
31 RosTopicProperty() = default;
32
40 const std::string & type, const std::string & topic,
41 const std::shared_ptr<std::unordered_map<std::string, std::string>> entity_roots)
42 : type_(type), topic_(topic), entity_roots_(entity_roots)
43 {
44 }
45
50 void set_type(const std::string & type) { type_ = type; }
51
56 void set_topic(const std::string & topic) { topic_ = topic; }
57
63 const std::shared_ptr<std::unordered_map<std::string, std::string>> entity_roots)
64 {
65 entity_roots_ = entity_roots;
66 }
67
72 const std::string & type() const noexcept { return type_; }
73
78 const std::string & topic() const noexcept { return topic_; }
79
84 const std::string & entity() const noexcept { return topic_; }
85
93 std::optional<std::string> entity(const std::string & frame_id) const noexcept
94 {
95 if (entity_roots_ && entity_roots_->count(frame_id) > 0) {
96 return entity_roots_->at(frame_id) + topic_;
97 } else {
98 return std::nullopt;
99 }
100 }
101
109 std::optional<std::string> entity_without_topic(const std::string & frame_id) const noexcept
110 {
111 if (entity_roots_ && entity_roots_->count(frame_id) > 0) {
112 return entity_roots_->at(frame_id);
113 } else {
114 return std::nullopt;
115 }
116 }
117
118 bool is_initialized() const { return !type_.empty() && !topic_.empty() && entity_roots_; }
119
120private:
121 std::string type_;
122 std::string topic_;
123 std::shared_ptr<std::unordered_map<std::string, std::string>>
124 entity_roots_;
125};
126} // namespace awviz_common
127
128#endif // AWVIZ_COMMON__PROPERTY_HPP_
Struct representing a property of ROS msg display instance.
Definition: property.hpp:29
const std::string & type() const noexcept
Get ROS message type.
Definition: property.hpp:72
RosTopicProperty(const std::string &type, const std::string &topic, const std::shared_ptr< std::unordered_map< std::string, std::string > > entity_roots)
Construct instance.
Definition: property.hpp:39
const std::string & topic() const noexcept
Get ROS topic name.
Definition: property.hpp:78
const std::string & entity() const noexcept
Return the entity path using topic name.
Definition: property.hpp:84
std::optional< std::string > entity(const std::string &frame_id) const noexcept
Return the entity path using the corresponding root and its frame ID with its topic.
Definition: property.hpp:93
void set_entity_roots(const std::shared_ptr< std::unordered_map< std::string, std::string > > entity_roots)
Set entity path of record.
Definition: property.hpp:62
void set_type(const std::string &type)
Set ROS message type name.
Definition: property.hpp:50
std::optional< std::string > entity_without_topic(const std::string &frame_id) const noexcept
Return the entity path using the corresponding root and its frame ID without its topic.
Definition: property.hpp:109
bool is_initialized() const
Definition: property.hpp:118
void set_topic(const std::string &topic)
Set ROS topic name.
Definition: property.hpp:56
Definition: display.hpp:30