.. _program_listing_file_include_parameter_tree.hpp: Program Listing for File parameter_tree.hpp =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/parameter_tree.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef RIG_RECONFIGURE_PARAMETER_TREE_HPP #define RIG_RECONFIGURE_PARAMETER_TREE_HPP #include #include #include #include #include "responses.hpp" struct TreeElement { TreeElement(const ROSParameter ¶meter_, std::string fullParameterPath_, std::optional patternStart_ = std::nullopt, std::optional patternEnd_ = std::nullopt) : name(parameter_.name), description(parameter_.description), fullPath(std::move(fullParameterPath_)), value(parameter_.value), searchPatternStart(patternStart_), searchPatternEnd(patternEnd_) {}; TreeElement(std::string name_, const rcl_interfaces::msg::ParameterDescriptor &description_, std::string fullParameterPath_, ROSParameterVariant value_, std::optional patternStart_ = std::nullopt, std::optional patternEnd_ = std::nullopt) : name(std::move(name_)), description(description_), fullPath(std::move(fullParameterPath_)), value(std::move(value_)), searchPatternStart(patternStart_), searchPatternEnd(patternEnd_) {}; std::string name; // parameter name without prefixes rcl_interfaces::msg::ParameterDescriptor description; // in addition to the name we store the full path of the parameter in the leaf nodes of the tree in order to be // able to support the mixing of different separators std::string fullPath; ROSParameterVariant value; // in case this parameter is part of a filtered parameter tree the following two members store the intermediate // information where in the name (not the fullPath!) the applied search pattern is located std::optional searchPatternStart; std::optional searchPatternEnd; }; struct ParameterGroup { explicit ParameterGroup(std::string prefix_ = "") : prefix(std::move(prefix_)) {}; std::string prefix; std::optional prefixSearchPatternStart; std::optional prefixSearchPatternEnd; std::vector parameters; std::vector> subgroups; }; class ParameterTree { public: ParameterTree(); void add(const ROSParameter ¶meter); void clear(); [[nodiscard]] std::shared_ptr getRoot(); [[nodiscard]] std::size_t getMaxParamNameLength() const; [[nodiscard]] std::string getAppliedFilter() const; [[nodiscard]] ParameterTree filter(const std::string &filterString) const; void removeEmptySubgroups(); private: void add(const std::shared_ptr &curNode, const TreeElement ¶meter); void filter(const std::shared_ptr &destinationNode, const std::shared_ptr &sourceNode, const std::string &filterString) const; std::shared_ptr root = nullptr; // bookkeeping for a nicer visualization std::size_t maxParamNameLength = 0; std::string appliedFilter; }; #endif // RIG_RECONFIGURE_PARAMETER_TREE_HPP