Robowflex  v0.1
Making MoveIt Easy
robowflex::IO::Handler Class Reference

ROS parameter server handler to handle namespacing and automatic parameter deletion. More...

#include <handler.h>

Public Member Functions

 Handler (const std::string &name)
 Constructor. More...
 
 Handler (Handler const &)=delete
 
void operator= (Handler const &)=delete
 
 Handler (const IO::Handler &handler, const std::string &name="")
 Copy constructor. Handles namespacing. More...
 
 ~Handler ()
 Destructor. Deletes all parameters created through this handler. More...
 
void loadYAMLtoROS (const YAML::Node &node, const std::string &prefix="")
 Loads the contents of a YAML node to the parameter server under a prefix. More...
 
template<typename T >
void setParam (const std::string &key, const T &value)
 Sets a parameter on the parameter server. More...
 
bool hasParam (const std::string &key) const
 Checks if the parameter server has key. More...
 
template<typename T >
bool getParam (const std::string &key, T &value) const
 Gets a parameter from the parameter server. More...
 
const ros::NodeHandle & getHandle () const
 Gets the node handle. More...
 
const std::stringgetName () const
 Gets the name of the handler. More...
 
const std::stringgetNamespace () const
 Gets the namespace of the handler. More...
 

Private Attributes

const std::string name_
 Name of handler. More...
 
const std::string namespace_
 Full namespace of handler. More...
 
ros::NodeHandle nh_
 ROS node handle. More...
 
std::vector< std::stringparams_
 Set parameter keys. More...
 

Static Private Attributes

static const std::string UUID
 UUID of handler. More...
 

Detailed Description

ROS parameter server handler to handle namespacing and automatic parameter deletion.

Definition at line 18 of file handler.h.

Constructor & Destructor Documentation

◆ Handler() [1/3]

IO::Handler::Handler ( const std::string name)

Constructor.

Parameters
[in]nameName for namespace.

Definition at line 512 of file robowflex_library/src/io.cpp.

513  : name_(name), namespace_("robowflex_" + UUID + "/" + name_), nh_(namespace_)
514 {
515 }
const std::string namespace_
Full namespace of handler.
Definition: handler.h:95
ros::NodeHandle nh_
ROS node handle.
Definition: handler.h:96
const std::string name_
Name of handler.
Definition: handler.h:94
static const std::string UUID
UUID of handler.
Definition: handler.h:92

◆ Handler() [2/3]

robowflex::IO::Handler::Handler ( Handler const &  )
delete

◆ Handler() [3/3]

IO::Handler::Handler ( const IO::Handler handler,
const std::string name = "" 
)

Copy constructor. Handles namespacing.

Parameters
[in]handlerParent handler.
[in]nameAdditional namespace to add to parent handler.

Definition at line 517 of file robowflex_library/src/io.cpp.

518  : name_(handler.getName()), namespace_(handler.getNamespace()), nh_(handler.getHandle(), name)
519 {
520 }
const std::string & getName() const
Gets the name of the handler.
const ros::NodeHandle & getHandle() const
Gets the node handle.
const std::string & getNamespace() const
Gets the namespace of the handler.

◆ ~Handler()

IO::Handler::~Handler ( )

Destructor. Deletes all parameters created through this handler.

Definition at line 522 of file robowflex_library/src/io.cpp.

523 {
524  for (const auto &key : params_)
525  nh_.deleteParam(key);
526 }
std::vector< std::string > params_
Set parameter keys.
Definition: handler.h:98

Member Function Documentation

◆ getHandle()

const ros::NodeHandle & IO::Handler::getHandle ( ) const

Gets the node handle.

Returns
The node handle.

Definition at line 556 of file robowflex_library/src/io.cpp.

557 {
558  return nh_;
559 }

◆ getName()

const std::string & IO::Handler::getName ( ) const

Gets the name of the handler.

Returns
The name of the handler.

Definition at line 561 of file robowflex_library/src/io.cpp.

562 {
563  return name_;
564 }

◆ getNamespace()

const std::string & IO::Handler::getNamespace ( ) const

Gets the namespace of the handler.

Returns
The namespace of the handler.

Definition at line 566 of file robowflex_library/src/io.cpp.

567 {
568  return namespace_;
569 }

◆ getParam()

template<typename T >
bool robowflex::IO::Handler::getParam ( const std::string key,
T &  value 
) const
inline

Gets a parameter from the parameter server.

Parameters
[in]keyKey of parameter.
[out]valueValue to store.
Template Parameters
TType of the value.

Definition at line 71 of file handler.h.

72  {
73  return nh_.getParam(key, value);
74  }

◆ hasParam()

bool IO::Handler::hasParam ( const std::string key) const

Checks if the parameter server has key.

Parameters
[in]keyKey to check.
Returns
True if key exists, false otherwise.

Definition at line 551 of file robowflex_library/src/io.cpp.

552 {
553  return nh_.hasParam(key);
554 }

◆ loadYAMLtoROS()

void IO::Handler::loadYAMLtoROS ( const YAML::Node &  node,
const std::string prefix = "" 
)

Loads the contents of a YAML node to the parameter server under a prefix.

Parameters
[in]nodeYAML node to load.
[in]prefixPrefix to put YAML node under.

Definition at line 528 of file robowflex_library/src/io.cpp.

529 {
530  switch (node.Type())
531  {
532  case YAML::NodeType::Map:
533  {
534  const std::string fixed_prefix = (prefix.empty()) ? "" : (prefix + "/");
535  for (YAML::const_iterator it = node.begin(); it != node.end(); ++it)
536  loadYAMLtoROS(it->second, fixed_prefix + it->first.as<std::string>());
537 
538  break;
539  }
540  case YAML::NodeType::Sequence:
541  case YAML::NodeType::Scalar:
542  {
543  setParam(prefix, YAMLToXmlRpc(node));
544  break;
545  }
546  default:
547  throw Exception(1, "Unknown node type in YAML");
548  }
549 }
Exception that contains a message and an error code.
Definition: util.h:15
void setParam(const std::string &key, const T &value)
Sets a parameter on the parameter server.
Definition: handler.h:53
void loadYAMLtoROS(const YAML::Node &node, const std::string &prefix="")
Loads the contents of a YAML node to the parameter server under a prefix.
T empty(T... args)

◆ operator=()

void robowflex::IO::Handler::operator= ( Handler const &  )
delete

◆ setParam()

template<typename T >
void robowflex::IO::Handler::setParam ( const std::string key,
const T &  value 
)
inline

Sets a parameter on the parameter server.

Parameters
[in]keyKey to store parameter under.
[in]valueValue to store.
Template Parameters
TType of the value.

Definition at line 53 of file handler.h.

54  {
55  nh_.setParam(key, value);
56  params_.emplace_back(key);
57  }
T emplace_back(T... args)

Member Data Documentation

◆ name_

const std::string robowflex::IO::Handler::name_
private

Name of handler.

Definition at line 94 of file handler.h.

◆ namespace_

const std::string robowflex::IO::Handler::namespace_
private

Full namespace of handler.

Definition at line 95 of file handler.h.

◆ nh_

ros::NodeHandle robowflex::IO::Handler::nh_
private

ROS node handle.

Definition at line 96 of file handler.h.

◆ params_

std::vector<std::string> robowflex::IO::Handler::params_
private

Set parameter keys.

Definition at line 98 of file handler.h.

◆ UUID

const std::string IO::Handler::UUID
staticprivate

UUID of handler.

IO::Handler

Definition at line 92 of file handler.h.


The documentation for this class was generated from the following files: