13 #include <boost/lexical_cast.hpp>
22 namespace ns_ros2param
32 using NodeBase::NodeBase;
54 case rclcpp::ParameterType::PARAMETER_BYTE_ARRAY:
57 case rclcpp::ParameterType::PARAMETER_BOOL_ARRAY:
60 case rclcpp::ParameterType::PARAMETER_INTEGER_ARRAY:
63 case rclcpp::ParameterType::PARAMETER_DOUBLE_ARRAY:
66 case rclcpp::ParameterType::PARAMETER_STRING_ARRAY:
80 case rclcpp::ParameterType::PARAMETER_BYTE_ARRAY:
83 case rclcpp::ParameterType::PARAMETER_INTEGER_ARRAY:
99 case rclcpp::ParameterType::PARAMETER_DOUBLE_ARRAY:
115 case rclcpp::ParameterType::PARAMETER_STRING_ARRAY:
131 case rclcpp::ParameterType::PARAMETER_BOOL_ARRAY:
148 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr
nh_;
156 explicit Reader(
const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
167 return (
nh_->get_parameter(
back().node_, parameter));
175 if (
back().node_ == name)
187 parameter_names_ = std::move(
nh_->list_parameters({}, std::numeric_limits<uint64_t>::max()).names);
191 [[nodiscard]]
static bool isPrefix(
const std::string &prefix,
const std::string &name)
198 if (prefix.size() <= name.size())
200 if (name.substr(0, prefix.size()) == prefix)
202 if (prefix.size() == name.size())
207 if (
'.' == name[prefix.size()])
220 std::size_t substr_start = 0;
224 substr_start =
back().node_.size() + 1;
227 std::set<std::string> names;
232 const std::size_t substr_end = name.find(
'.', substr_start);
233 names.insert(name.substr(substr_start, substr_end - substr_start));
252 template <
int t_expected_parameter_type,
class t_Element>
256 if (not
back().tryReadArray(element))
258 rclcpp::Parameter parameter;
260 CPPUT_ASSERT(t_expected_parameter_type == parameter.get_type(),
"Unexpected parameter type.");
261 element = parameter.get_value<t_Element>();
272 namespace ns_ros2param
274 Reader::Reader(
const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &nh)
295 impl_->emplace(child_name);
299 CPPUT_ASSERT(not
impl_->back().isBuiltinArray(),
"Unexpected parent type (builtin array).");
301 impl_->concatWithNodeAndEmplace(
impl_->separator_, child_name);
304 return (
impl_->hasParameterPrefix());
317 const std::size_t min,
318 const std::size_t max)
322 std::set<std::string> name_list =
impl_->listParameters();
324 checkSize(limit_type, name_list.size(), min, max);
326 impl_->emplace(
impl_->back().node_, std::move(name_list));
333 if (
impl_->back().isCompleted())
338 entry_name =
impl_->back().getChildName();
339 impl_->concatWithNodeAndEmplace(
impl_->separator_, entry_name);
347 ++(
impl_->back().index_);
353 CPPUT_ASSERT(
impl_->back().isCompleted(),
"End of iterated map has not been reached.");
362 if (not
impl_->empty() and
impl_->isParameter())
364 rclcpp::Parameter values;
365 impl_->getParameter(values);
366 impl_->emplace(std::move(values));
370 impl_->emplace(
impl_->back().node_, 0,
impl_->listParameters().size());
373 return (
impl_->back().size_);
380 CPPUT_ASSERT(not
impl_->back().isCompleted(),
"Internal error: array has more elements than expected.");
381 if (
impl_->back().isNonBuiltinArray())
383 impl_->concatWithNodeAndEmplace(
384 impl_->separator_, boost::lexical_cast<std::string>(
impl_->back().index_));
391 if (not
impl_->back().isBuiltinArray())
406 #define ARILES2_BASIC_TYPE(type) \
407 void Reader::readElement(type &element) \
410 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
412 tmp_value <= std::numeric_limits<type>::max() && tmp_value >= std::numeric_limits<type>::min(), \
413 "Value is out of range."); \
414 element = static_cast<type>(tmp_value); \
419 #undef ARILES2_BASIC_TYPE
422 #define ARILES2_BASIC_TYPE(type) \
423 void Reader::readElement(type &element) \
425 CPPUT_TRACE_FUNCTION; \
427 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
428 CPPUT_ASSERT(tmp_value >= 0, "Expected positive value."); \
429 CPPUT_ASSERT(static_cast<uint64_t>(tmp_value) <= std::numeric_limits<type>::max(), "Value is too large."); \
430 element = static_cast<type>(tmp_value); \
435 #undef ARILES2_BASIC_TYPE
438 #define ARILES2_BASIC_TYPE(type) \
439 void Reader::readElement(type &element) \
441 CPPUT_TRACE_FUNCTION; \
443 impl_->readElement<rclcpp::ParameterType::PARAMETER_DOUBLE>(tmp_value); \
444 element = static_cast<type>(tmp_value); \
449 #undef ARILES2_BASIC_TYPE
455 impl_->readElement<rclcpp::ParameterType::PARAMETER_STRING>(element);
462 impl_->readElement<rclcpp::ParameterType::PARAMETER_BOOL>(element);
bool isBuiltinArray() const
bool tryReadArray(std::string &value)
std::set< std::string > childs_
ReaderNodeWrapper(const std::string &name, std::set< std::string > childs)
bool tryReadArray(double &value)
const rclcpp::Parameter parameter_
const std::string & getChildName()
std::set< std::string >::const_iterator childs_iterator_
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_
static bool isPrefix(const std::string &prefix, const std::string &name)
std::set< std::string > listParameters() const
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
CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_SIGNED_INTEGER_TYPES_LIST) CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_UNSIGNED_INTEGER_TYPES_LIST) CPPUT_MACRO_SUBSTITUTE(ARILES2_BASIC_REAL_TYPES_LIST) void Reader
#define CPPUT_TRACE_FUNCTION
#define CPPUT_TRACE_VALUE(value)