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 const bool result =
impl_->hasParameterPrefix();
326 const std::size_t min,
327 const std::size_t max)
331 std::vector<std::string> name_list =
impl_->listParameters();
333 checkSize(limit_type, name_list.size(), min, max);
335 impl_->emplace(
impl_->back().node_, std::move(name_list));
342 if (
impl_->back().isCompleted())
347 entry_name =
impl_->back().getChildName();
348 impl_->concatWithNodeAndEmplace(
impl_->separator_, entry_name);
356 ++(
impl_->back().index_);
362 CPPUT_ASSERT(
impl_->back().isCompleted(),
"End of iterated map has not been reached.");
371 if (not
impl_->empty() and
impl_->isParameter())
373 rclcpp::Parameter values;
374 impl_->getParameter(values);
375 impl_->emplace(std::move(values));
379 impl_->emplace(
impl_->back().node_, 0,
impl_->listParameters().size());
382 return (
impl_->back().size_);
389 CPPUT_ASSERT(not
impl_->back().isCompleted(),
"Internal error: array has more elements than expected.");
390 if (
impl_->back().isNonBuiltinArray())
392 impl_->concatWithNodeAndEmplace(
393 impl_->separator_, boost::lexical_cast<std::string>(
impl_->back().index_));
400 if (not
impl_->back().isBuiltinArray())
415#define ARILES2_BASIC_TYPE(type) \
416 void Reader::readElement(type &element) \
419 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
421 tmp_value <= std::numeric_limits<type>::max() && tmp_value >= std::numeric_limits<type>::min(), \
422 "Value is out of range."); \
423 element = static_cast<type>(tmp_value); \
428#undef ARILES2_BASIC_TYPE
431#define ARILES2_BASIC_TYPE(type) \
432 void Reader::readElement(type &element) \
434 CPPUT_TRACE_FUNCTION; \
436 impl_->readElement<rclcpp::ParameterType::PARAMETER_INTEGER>(tmp_value); \
437 CPPUT_ASSERT(tmp_value >= 0, "Expected positive value."); \
438 CPPUT_ASSERT(static_cast<uint64_t>(tmp_value) <= std::numeric_limits<type>::max(), "Value is too large."); \
439 element = static_cast<type>(tmp_value); \
444#undef ARILES2_BASIC_TYPE
447#define ARILES2_BASIC_TYPE(type) \
448 void Reader::readElement(type &element) \
450 CPPUT_TRACE_FUNCTION; \
452 impl_->readElement<rclcpp::ParameterType::PARAMETER_DOUBLE>(tmp_value); \
453 element = static_cast<type>(tmp_value); \
458#undef ARILES2_BASIC_TYPE
464 impl_->readElement<rclcpp::ParameterType::PARAMETER_STRING>(element);
471 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)