11#include <boost/lexical_cast.hpp>
20 namespace ns_ros2param
29 using NodeBase::NodeBase;
50 case rclcpp::ParameterType::PARAMETER_BYTE_ARRAY:
53 case rclcpp::ParameterType::PARAMETER_BOOL_ARRAY:
56 case rclcpp::ParameterType::PARAMETER_INTEGER_ARRAY:
59 case rclcpp::ParameterType::PARAMETER_DOUBLE_ARRAY:
62 case rclcpp::ParameterType::PARAMETER_STRING_ARRAY:
76 case rclcpp::ParameterType::PARAMETER_BYTE_ARRAY:
79 case rclcpp::ParameterType::PARAMETER_INTEGER_ARRAY:
95 case rclcpp::ParameterType::PARAMETER_DOUBLE_ARRAY:
111 case rclcpp::ParameterType::PARAMETER_STRING_ARRAY:
127 case rclcpp::ParameterType::PARAMETER_BOOL_ARRAY:
144 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr
nh_;
152 explicit Reader(
const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
163 return (
nh_->get_parameter(
back().node_, parameter));
171 if (
back().node_ == name)
183 parameter_names_ = std::move(
nh_->list_parameters({}, std::numeric_limits<uint64_t>::max()).names);
187 [[nodiscard]]
static bool isPrefix(
const std::string &prefix,
const std::string &name)
194 if (prefix.size() <= name.size())
196 if (name.substr(0, prefix.size()) == prefix)
198 if (prefix.size() == name.size())
203 if (
'.' == name[prefix.size()])
216 std::size_t substr_start = 0;
220 substr_start =
back().node_.size() + 1;
224 std::vector<std::string> names;
229 const std::size_t substr_end = name.find(
'.', substr_start);
230 std::string name_part = name.substr(substr_start, substr_end - substr_start);
232 const std::vector<std::string>::iterator it =
233 std::lower_bound(names.begin(), names.end(), name_part);
234 if (it == names.end() or *it != name_part)
236 names.insert(it, std::move(name_part));
256 template <
int t_expected_parameter_type,
class t_Element>
260 if (not
back().tryReadArray(element))
262 rclcpp::Parameter parameter;
264 CPPUT_ASSERT(t_expected_parameter_type == parameter.get_type(),
"Unexpected parameter type.");
265 element = parameter.get_value<t_Element>();
276 namespace ns_ros2param
278 Reader::Reader(
const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
299 impl_->emplace(child_name);
303 CPPUT_ASSERT(not
impl_->back().isBuiltinArray(),
"Unexpected parent type (builtin array).");
305 impl_->concatWithNodeAndEmplace(
impl_->separator_, child_name);
308 return (
impl_->hasParameterPrefix());
321 const std::size_t min,
322 const std::size_t max)
326 std::vector<std::string> name_list =
impl_->listParameters();
328 checkSize(limit_type, name_list.size(), min, max);
330 impl_->emplace(
impl_->back().node_, std::move(name_list));
337 if (
impl_->back().isCompleted())
342 entry_name =
impl_->back().getChildName();
343 impl_->concatWithNodeAndEmplace(
impl_->separator_, entry_name);
351 ++(
impl_->back().index_);
357 CPPUT_ASSERT(
impl_->back().isCompleted(),
"End of iterated map has not been reached.");
366 if (not
impl_->empty() and
impl_->isParameter())
368 rclcpp::Parameter values;
369 impl_->getParameter(values);
370 impl_->emplace(std::move(values));
374 impl_->emplace(
impl_->back().node_, 0,
impl_->listParameters().size());
377 return (
impl_->back().size_);
384 CPPUT_ASSERT(not
impl_->back().isCompleted(),
"Internal error: array has more elements than expected.");
385 if (
impl_->back().isNonBuiltinArray())
387 impl_->concatWithNodeAndEmplace(
388 impl_->separator_, boost::lexical_cast<std::string>(
impl_->back().index_));
395 if (not
impl_->back().isBuiltinArray())
410#define ARILES2_BASIC_TYPE(type) \
411 void Reader::readElement(type &element) \
414 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
416 tmp_value <= std::numeric_limits<type>::max() && tmp_value >= std::numeric_limits<type>::min(), \
417 "Value is out of range."); \
418 element = static_cast<type>(tmp_value); \
423#undef ARILES2_BASIC_TYPE
426#define ARILES2_BASIC_TYPE(type) \
427 void Reader::readElement(type &element) \
429 CPPUT_TRACE_FUNCTION; \
431 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
432 CPPUT_ASSERT(tmp_value >= 0, "Expected positive value."); \
433 CPPUT_ASSERT(static_cast<uint64_t>(tmp_value) <= std::numeric_limits<type>::max(), "Value is too large."); \
434 element = static_cast<type>(tmp_value); \
439#undef ARILES2_BASIC_TYPE
442#define ARILES2_BASIC_TYPE(type) \
443 void Reader::readElement(type &element) \
445 CPPUT_TRACE_FUNCTION; \
447 impl_->readElement<rclcpp::ParameterType::PARAMETER_DOUBLE>(tmp_value); \
448 element = static_cast<type>(tmp_value); \
453#undef ARILES2_BASIC_TYPE
459 impl_->readElement<rclcpp::ParameterType::PARAMETER_STRING>(element);
466 impl_->readElement<rclcpp::ParameterType::PARAMETER_BOOL>(element);
bool isBuiltinArray() const
ReaderNodeWrapper(const std::string &name, std::vector< std::string > childs)
bool tryReadArray(std::string &value)
const std::string & getChildName()
std::vector< std::string > childs_
bool tryReadArray(double &value)
const rclcpp::Parameter parameter_
ReaderNodeWrapper(const rclcpp::Parameter &¶meter)
bool tryReadArray(int64_t &value)
bool tryReadArray(bool &value)
bool startIteratedMap(const SizeLimitEnforcementType=SIZE_LIMIT_NONE, const std::size_t=0, const std::size_t=0)
void endMapEntry()
endMapEntry from the current entry to its parent.
bool startIteratedMapElement(std::string &entry_name)
bool startMapEntry(const std::string &child_name)
startMapEntry to the entry with the given name
Reader(const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
Constructor.
void endIteratedMapElement()
bool startRoot(const std::string &name)
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr nh_
Reader(const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
const std::string separator_
bool hasParameterPrefix()
bool getParameter(rclcpp::Parameter ¶meter) const
void readElement(t_Element &element)
std::vector< std::string > parameter_names_
std::vector< std::string > listParameters() const
static bool isPrefix(const std::string &prefix, const std::string &name)
void checkSize(const SizeLimitEnforcementType limit_type, const std::size_t size=0, const std::size_t min=0, const std::size_t max=0) const
virtual bool startRoot(const std::string &name)
void readElement(std::complex< t_Scalar > &entry)
ReaderNodeWrapper & back()
void makeImplPtr(t_Args &&...args)
#define CPPUT_ASSERT(condition,...)
#define ARILES2_BASIC_REAL_TYPES_LIST
#define ARILES2_BASIC_UNSIGNED_INTEGER_TYPES_LIST
#define ARILES2_BASIC_SIGNED_INTEGER_TYPES_LIST
#define CPPUT_MACRO_SUBSTITUTE(macro)
#define CPPUT_TRACE_FUNCTION
#define CPPUT_TRACE_VALUE(value)