YARP
Yet Another Robot Platform
yarp::os::Searchable Class Referenceabstract

A base class for nested structures that can be searched. More...

#include <yarp/os/Searchable.h>

+ Inheritance diagram for yarp::os::Searchable:

Detailed Description

A base class for nested structures that can be searched.

A Searchable object promises that you can look inside it with the find() and findGroup() methods to get values and lists corresponding to keywords.

See also
Property Bottle Value
Examples
dev/fake_motor/fake_motor.cpp, and os/image_process_module/image_process_module.cpp.

Definition at line 68 of file Searchable.h.

Public Member Functions

 Searchable ()
 Default constructor. More...
 
 Searchable (const Searchable &rhs)=default
 Copy constructor. More...
 
 Searchable (Searchable &&rhs) noexcept=default
 Move constructor. More...
 
virtual ~Searchable ()
 Destructor. More...
 
Searchableoperator= (const Searchable &rhs)=default
 Copy assignment operator. More...
 
Searchableoperator= (Searchable &&rhs) noexcept=default
 Move assignment operator. More...
 
virtual bool check (const std::string &key) const =0
 Check if there exists a property of the given name. More...
 
virtual bool check (const std::string &key, const std::string &comment) const
 Check if there exists a property of the given name. More...
 
virtual Valuefind (const std::string &key) const =0
 Gets a value corresponding to a given keyword. More...
 
virtual BottlefindGroup (const std::string &key) const =0
 Gets a list corresponding to a given keyword. More...
 
BottlefindGroup (const std::string &key, const std::string &comment) const
 Gets a list corresponding to a given keyword. More...
 
virtual bool check (const std::string &key, Value *&result, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 
virtual Value check (const std::string &key, const Value &fallback, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 
virtual bool isNull () const
 Checks if the object is invalid. More...
 
virtual std::string toString () const =0
 Return a standard text representation of the content of the object. More...
 

Constructor & Destructor Documentation

◆ Searchable() [1/3]

yarp::os::Searchable::Searchable ( )
explicit

Default constructor.

Definition at line 32 of file Searchable.cpp.

◆ Searchable() [2/3]

yarp::os::Searchable::Searchable ( const Searchable rhs)
default

Copy constructor.

◆ Searchable() [3/3]

yarp::os::Searchable::Searchable ( Searchable &&  rhs)
defaultnoexcept

Move constructor.

◆ ~Searchable()

yarp::os::Searchable::~Searchable ( )
virtualdefault

Destructor.

Member Function Documentation

◆ check() [1/4]

virtual bool yarp::os::Searchable::check ( const std::string &  key) const
pure virtual

Check if there exists a property of the given name.

Parameters
keythe name to check for
Returns
true iff a property of the given name exists, even if it doesn't have a value associated with it

Implemented in yarp::os::Value, yarp::os::ResourceFinder, yarp::os::Property, yarp::os::impl::Storable, and yarp::os::Bottle.

◆ check() [2/4]

bool yarp::os::Searchable::check ( const std::string &  key,
const std::string &  comment 
) const
virtual

Check if there exists a property of the given name.

Parameters
keythe name to check for
commentHuman-readable explanation
Returns
true iff a property of the given name exists, even if it doesn't have a value associated with it

Definition at line 84 of file Searchable.cpp.

◆ check() [3/4]

yarp::os::Value yarp::os::Searchable::check ( const std::string &  key,
const Value fallback,
const std::string &  comment = "" 
) const
virtual

Gets a value corresponding to a given keyword.

Parameters
keyThe keyword to look for
fallbackA default value to return if nothing found
commentOptional human-readable explanation
Returns
A value corresponding to a given keyword, or the default if nothing is found. See the find() method for interpreting the value found.

Definition at line 58 of file Searchable.cpp.

◆ check() [4/4]

bool yarp::os::Searchable::check ( const std::string &  key,
Value *&  result,
const std::string &  comment = "" 
) const
virtual

Gets a value corresponding to a given keyword.

If a property does not exist, this returns false and does not modify the result pointer. If a property exists but does not have a value, this again returns false and does not modify the result pointer.

Property p;
p.fromString("(width 10) (height 15) (help)");
p.check("help") // this is true
p.check("width") // this is true
p.check("foo") // this is false
Value *v;
p.check("help", v) // this is false, there is no value associated
p.check("width", v) // this is true, and v->asInt32() is 10
Parameters
keyThe keyword to look for
resultA pointer to store the address of the result in
commentOptional human-readable explanation
Returns
True if there is a value corresponding to a given keyword, false otherwise. See the find() method for interpreting the value found.

Definition at line 39 of file Searchable.cpp.

◆ find()

virtual Value& yarp::os::Searchable::find ( const std::string &  key) const
pure virtual

Gets a value corresponding to a given keyword.

Parameters
keyThe keyword to look for
Returns
A value corresponding to a given keyword. If there is no such value, then the isNull() method called on the result will be true. Otherwise, the value can be read by calling result.asInt32(), result.asString(), etc. as appropriate.

Implemented in yarp::os::Value, yarp::os::ResourceFinder, yarp::os::Property, yarp::os::impl::StoreDict, yarp::os::impl::StoreList, yarp::os::impl::Storable, and yarp::os::Bottle.

◆ findGroup() [1/2]

virtual Bottle& yarp::os::Searchable::findGroup ( const std::string &  key) const
pure virtual

Gets a list corresponding to a given keyword.

Parameters
keyThe keyword to look for
Returns
A list corresponding to a given keyword. If there is no such list, then the isNull() method called on the result will be true. Otherwise, the elements of the list can be read through result.get(index) where result.get(0) is the keyword, and result.get(i) for i>=1 are the "real" elements of the list.

Implemented in yarp::os::Value, yarp::os::ResourceFinder, yarp::os::Property, yarp::os::impl::StoreDict, yarp::os::impl::StoreList, yarp::os::impl::Storable, and yarp::os::Bottle.

◆ findGroup() [2/2]

yarp::os::Bottle & yarp::os::Searchable::findGroup ( const std::string &  key,
const std::string &  comment 
) const

Gets a list corresponding to a given keyword.

Parameters
keyThe keyword to look for
commentHuman-readable explanation
Returns
A list corresponding to a given keyword. If there is no such list, then the isNull() method called on the result will be true. Otherwise, the elements of the list can be read through result.get(index) where result.get(0) is the keyword, and result.get(i) for i>=1 are the "real" elements of the list.

Definition at line 97 of file Searchable.cpp.

◆ isNull()

bool yarp::os::Searchable::isNull ( ) const
virtual

Checks if the object is invalid.

Returns
True if the object is invalid or "null".

Reimplemented in yarp::os::Value, yarp::os::ResourceFinder, yarp::os::impl::StoreNull, yarp::os::impl::Storable, yarp::os::Bottle, and NullBottle.

Definition at line 110 of file Searchable.cpp.

◆ operator=() [1/2]

Searchable& yarp::os::Searchable::operator= ( const Searchable rhs)
default

Copy assignment operator.

◆ operator=() [2/2]

Searchable& yarp::os::Searchable::operator= ( Searchable &&  rhs)
defaultnoexcept

Move assignment operator.

◆ toString()

virtual std::string yarp::os::Searchable::toString ( ) const
pure virtual

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