RcsPySim
A robot control and simulation library
Rcs::PropertySourceDict Class Reference

#include <PropertySourceDict.h>

Inheritance diagram for Rcs::PropertySourceDict:
Collaboration diagram for Rcs::PropertySourceDict:

Public Member Functions

 PropertySourceDict (pybind11::dict dict)
 
virtual ~PropertySourceDict ()
 
virtual bool exists ()
 
virtual bool getProperty (std::string &out, const char *property)
 
virtual bool getProperty (std::vector< std::string > &out, const char *property)
 
virtual bool getProperty (double &out, const char *property)
 
virtual bool getProperty (int &out, const char *property)
 
virtual bool getProperty (MatNd *&out, const char *property)
 
virtual bool getPropertyBool (const char *property, bool def=false)
 
virtual PropertySinkgetChild (const char *prefix)
 
virtual const std::vector< PropertySource * > & getChildList (const char *prefix)
 
virtual void setProperty (const char *property, const std::string &value)
 
virtual void setProperty (const char *property, bool value)
 
virtual void setProperty (const char *property, int value)
 
virtual void setProperty (const char *property, double value)
 
virtual void setProperty (const char *property, MatNd *value)
 
virtual PropertySinkclone () const
 
virtual void saveXML (const char *fileName, const char *rootNodeName)
 
- Public Member Functions inherited from Rcs::PropertySink
 PropertySink ()
 
virtual ~PropertySink ()
 
- Public Member Functions inherited from Rcs::PropertySource
 PropertySource ()
 
virtual ~PropertySource ()
 

Protected Member Functions

void onWrite ()
 
void appendPrefix (std::ostream &)
 

Private Member Functions

 PropertySourceDict (pybind11::dict dict, PropertySourceDict *parent, const char *prefix, bool exists)
 

Private Attributes

pybind11::dict dict
 
std::map< std::string, PropertySourceDict * > children
 
std::map< std::string, std::vector< PropertySource * > > listChildren
 
PropertySourceDictparent
 
const char * prefix
 
bool _exists
 

Additional Inherited Members

- Static Public Member Functions inherited from Rcs::PropertySource
static PropertySourceempty ()
 

Detailed Description

PropertySource/Sink backed by a C++ dict.

Definition at line 47 of file PropertySourceDict.h.

Constructor & Destructor Documentation

◆ PropertySourceDict() [1/2]

Rcs::PropertySourceDict::PropertySourceDict ( pybind11::dict  dict,
PropertySourceDict parent,
const char *  prefix,
bool  exists 
)
private

Definition at line 42 of file PropertySourceDict.cpp.

◆ PropertySourceDict() [2/2]

Rcs::PropertySourceDict::PropertySourceDict ( pybind11::dict  dict)

Definition at line 50 of file PropertySourceDict.cpp.

◆ ~PropertySourceDict()

Rcs::PropertySourceDict::~PropertySourceDict ( )
virtual

Definition at line 56 of file PropertySourceDict.cpp.

Member Function Documentation

◆ appendPrefix()

void Rcs::PropertySourceDict::appendPrefix ( std::ostream &  os)
protected

Definition at line 215 of file PropertySourceDict.cpp.

◆ clone()

PropertySink * Rcs::PropertySourceDict::clone ( ) const
virtual

Create an independent copy of this property source.

Returns
a copy of this property source. Must take ownership.

Implements Rcs::PropertySink.

Definition at line 337 of file PropertySourceDict.cpp.

◆ exists()

bool Rcs::PropertySourceDict::exists ( )
virtual

Check if this property source exists in the underlying storage.

Implements Rcs::PropertySource.

Definition at line 71 of file PropertySourceDict.cpp.

◆ getChild()

PropertySink * Rcs::PropertySourceDict::getChild ( const char *  prefix)
virtual

Obtain a child property sink.

This only adapts the return type from the PropertySource definition.

Implements Rcs::PropertySink.

Definition at line 182 of file PropertySourceDict.cpp.

◆ getChildList()

const std::vector< PropertySource * > & Rcs::PropertySourceDict::getChildList ( const char *  prefix)
virtual

Obtain a list of child property sources. The exact meaning of this depends on the implementation. For an Xml document, it could be child elements with the same tag name. For a python dict, it could be a list of dicts.

The returned objects are owned by the parent.

Implements Rcs::PropertySource.

Definition at line 276 of file PropertySourceDict.cpp.

◆ getProperty() [1/5]

bool Rcs::PropertySourceDict::getProperty ( std::string &  out,
const char *  property 
)
virtual

Read a string value.

Parameters
[out]outstorage for read value
[in]propertyname of property to read
Returns
true if the property was read successfully
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 76 of file PropertySourceDict.cpp.

◆ getProperty() [2/5]

bool Rcs::PropertySourceDict::getProperty ( std::vector< std::string > &  out,
const char *  property 
)
virtual

Read a string list value.

Parameters
[out]outstorage for read value
[in]propertyname of property to read
Returns
true if the property was read successfully
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 93 of file PropertySourceDict.cpp.

◆ getProperty() [3/5]

bool Rcs::PropertySourceDict::getProperty ( double &  out,
const char *  property 
)
virtual

Read a double value.

Parameters
[out]outstorage for read value
[in]propertyname of property to read
Returns
true if the property was read successfully, false if it doesn't exist
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 124 of file PropertySourceDict.cpp.

◆ getProperty() [4/5]

bool Rcs::PropertySourceDict::getProperty ( int &  out,
const char *  property 
)
virtual

Read an int value.

Parameters
[out]outstorage for read value
[in]propertyname of property to read
Returns
true if the property was read successfully, false if it doesn't exist
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 140 of file PropertySourceDict.cpp.

◆ getProperty() [5/5]

bool Rcs::PropertySourceDict::getProperty ( MatNd *&  out,
const char *  property 
)
virtual

Read a vector/matrix value. The variable out should be a pointer and will be set to a newly created MatNd* on success.

Parameters
[out]outstorage for read value
[in]propertyname of property to read
Returns
true if the property was read successfully, false if it doesn't exist
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 156 of file PropertySourceDict.cpp.

◆ getPropertyBool()

bool Rcs::PropertySourceDict::getPropertyBool ( const char *  property,
bool  def = false 
)
virtual

Read a boolean value, returning a default value if not found. This interface differs from the others to ease usability

Parameters
[in]propertyname of property to read
[in]defvalue to return if property doesn't exist
Returns
true if the property was read successfully
Exceptions
std::exceptionif the property exists, but couldn't be converted

Implements Rcs::PropertySource.

Definition at line 174 of file PropertySourceDict.cpp.

◆ onWrite()

void Rcs::PropertySourceDict::onWrite ( )
protected

Definition at line 262 of file PropertySourceDict.cpp.

◆ saveXML()

void Rcs::PropertySourceDict::saveXML ( const char *  fileName,
const char *  rootNodeName 
)
virtual

Save this property source as xml file.

Parameters
[in]fileNamename of the file to write
[in]rootNodeNamename of the xml root node

Implements Rcs::PropertySource.

Definition at line 420 of file PropertySourceDict.cpp.

◆ setProperty() [1/5]

void Rcs::PropertySourceDict::setProperty ( const char *  property,
const std::string &  value 
)
virtual

Set a property to the given string value.

Parameters
[in]propertyname of property to write.
[in]valuenew property value.

Implements Rcs::PropertySink.

Definition at line 224 of file PropertySourceDict.cpp.

◆ setProperty() [2/5]

void Rcs::PropertySourceDict::setProperty ( const char *  property,
bool  value 
)
virtual

Set a property to the given boolean value.

Parameters
[in]propertyname of property to write.
[in]valuenew property value.

Implements Rcs::PropertySink.

Definition at line 233 of file PropertySourceDict.cpp.

◆ setProperty() [3/5]

void Rcs::PropertySourceDict::setProperty ( const char *  property,
int  value 
)
virtual

Set a property to the given integer value.

Parameters
[in]propertyname of property to write.
[in]valuenew property value.

Implements Rcs::PropertySink.

Definition at line 240 of file PropertySourceDict.cpp.

◆ setProperty() [4/5]

void Rcs::PropertySourceDict::setProperty ( const char *  property,
double  value 
)
virtual

Set a property to the given double value.

Parameters
[in]propertyname of property to write.
[in]valuenew property value.

Implements Rcs::PropertySink.

Definition at line 247 of file PropertySourceDict.cpp.

◆ setProperty() [5/5]

void Rcs::PropertySourceDict::setProperty ( const char *  property,
MatNd *  value 
)
virtual

Set a property to the given vector/matrix value.

If one of the dimensions of the matrix has size 1, it is interpreted as vector.

Parameters
[in]propertyname of property to write.
[in]valuenew property value.

Implements Rcs::PropertySink.

Definition at line 254 of file PropertySourceDict.cpp.

Member Data Documentation

◆ _exists

bool Rcs::PropertySourceDict::_exists
private

Definition at line 58 of file PropertySourceDict.h.

◆ children

std::map<std::string, PropertySourceDict*> Rcs::PropertySourceDict::children
private

Definition at line 52 of file PropertySourceDict.h.

◆ dict

pybind11::dict Rcs::PropertySourceDict::dict
private

Definition at line 50 of file PropertySourceDict.h.

◆ listChildren

std::map<std::string, std::vector<PropertySource*> > Rcs::PropertySourceDict::listChildren
private

Definition at line 53 of file PropertySourceDict.h.

◆ parent

PropertySourceDict* Rcs::PropertySourceDict::parent
private

Definition at line 56 of file PropertySourceDict.h.

◆ prefix

const char* Rcs::PropertySourceDict::prefix
private

Definition at line 57 of file PropertySourceDict.h.


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