15#ifndef AWVIZ_COMMON__TF_TREE_HPP_
16#define AWVIZ_COMMON__TF_TREE_HPP_
23#include <unordered_map>
50 explicit TfFrame(
const std::string &
id) : id_(
id), parent_(
"") {}
57 const std::string &
id()
const {
return id_; }
64 const std::string &
parent()
const {
return parent_; }
71 bool is_root()
const {
return parent_.empty(); }
79 bool is_static()
const {
return std::strcmp(parent_.c_str(),
TF_ROOT) != 0 || parent_.empty(); }
89 return id_ == other.
id() && parent_ == other.
parent();
124 const std::unordered_map<std::string, TfFrame> &
get_frames()
const {
return frames_; }
132 std::optional<TfFrame>
get_frame(
const std::string &
id)
const
134 return contains(
id) ? std::make_optional(frames_.at(
id)) : std::nullopt;
143 std::optional<TfFrame>
get_parent(
const std::string &
id)
const
146 return frame ?
get_frame(frame->parent()) : std::nullopt;
155 bool contains(
const std::string &
id)
const {
return frames_.count(
id) > 0; }
166 return contains(frame.
id()) && frame == frames_.at(frame.
id());
179 auto current = std::make_optional<TfFrame>(frame);
180 std::string entity =
"/" + current->id();
181 while (current && !current->is_root()) {
184 entity =
"/" + current->id() + entity;
201 auto current = std::make_optional<TfFrame>(frame);
202 while (current && !current->is_root()) {
205 return current->id() == id;
209 std::unordered_map<std::string, TfFrame> frames_;
A class to represent a TF frame information.
Definition: tf_tree.hpp:35
bool is_root() const
Indicate whether the frame is root by checking if parent_ is empty.
Definition: tf_tree.hpp:71
const std::string & parent() const
Return the parent frame ID.
Definition: tf_tree.hpp:64
bool operator==(const TfFrame &other) const
Compare with an another object.
Definition: tf_tree.hpp:87
bool is_static() const
Return whether the tf frame is static or not.
Definition: tf_tree.hpp:79
TfFrame(const std::string &id, const std::string &parent)
Construct a new object.
Definition: tf_tree.hpp:43
TfFrame(const std::string &id)
Construct a new object with empty string for parent.
Definition: tf_tree.hpp:50
const std::string & id() const
Return own frame ID.
Definition: tf_tree.hpp:57
Definition: tf_tree.hpp:98
TfTree()
Construct a object setting TF_ROOT as root.
Definition: tf_tree.hpp:103
void emplace(const TfFrame &frame)
Add a new tf frame to the tree.
Definition: tf_tree.hpp:110
std::optional< TfFrame > get_parent(const std::string &id) const
Get the parent TfFrame object.
Definition: tf_tree.hpp:143
bool contains(const std::string &id) const
Whether to the specified frame ID is contained as a node of tree.
Definition: tf_tree.hpp:155
const std::unordered_map< std::string, TfFrame > & get_frames() const
Return map of all frames.
Definition: tf_tree.hpp:124
bool can_link_to(const TfFrame &frame, const std::string &id) const
Check whether the input frame is linked to the input id.
Definition: tf_tree.hpp:199
std::string entity_path(const TfFrame &frame) const
Return entity path of the specified frame. The entity path will be in the format "/<Parent0>/<Parent1...
Definition: tf_tree.hpp:177
std::optional< TfFrame > get_frame(const std::string &id) const
Get the TfFrame object.
Definition: tf_tree.hpp:132
bool contains(const TfFrame &frame) const
Whether to the specified frame is contained in the tree checking both key and value.
Definition: tf_tree.hpp:164
Definition: display.hpp:30
constexpr const char * TF_ROOT
Root transformation frame.
Definition: tf_tree.hpp:29