YARP  2.3.68+283-20170530.4+git10f9853
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:

Public Member Functions

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

Private Attributes

SearchMonitor * monitor
 
ConstString monitorContext
 

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.cpp, dev/file_grabber.cpp, and os/image_process_module.cpp.

Definition at line 56 of file Searchable.h.

Constructor & Destructor Documentation

◆ Searchable()

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

Default constructor.

Definition at line 27 of file Searchable.cpp.

◆ ~Searchable()

yarp::os::Searchable::~Searchable ( )
virtual

Destructor.

Definition at line 31 of file Searchable.cpp.

Member Function Documentation

◆ check() [1/4]

virtual bool yarp::os::Searchable::check ( const ConstString 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::Bottle, yarp::os::ResourceFinder, yarp::os::Value, yarp::os::impl::Storable, and yarp::os::Property.

Examples:
dev/file_grabber.cpp.

◆ check() [2/4]

bool yarp::os::Searchable::check ( const ConstString key,
const ConstString 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 77 of file Searchable.cpp.

◆ check() [3/4]

bool yarp::os::Searchable::check ( const ConstString key,
Value *&  result,
const ConstString 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->asInt() 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 34 of file Searchable.cpp.

◆ check() [4/4]

yarp::os::Value yarp::os::Searchable::check ( const ConstString key,
const Value fallback,
const ConstString 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 52 of file Searchable.cpp.

◆ find()

virtual Value& yarp::os::Searchable::find ( const ConstString 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.asInt(), result.asString(), etc. as appropriate.

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

◆ findGroup() [1/2]

virtual Bottle& yarp::os::Searchable::findGroup ( const ConstString 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::impl::StoreDict, yarp::os::impl::StoreList, yarp::os::Bottle, yarp::os::ResourceFinder, yarp::os::Value, yarp::os::Property, and yarp::os::impl::Storable.

◆ findGroup() [2/2]

yarp::os::Bottle & yarp::os::Searchable::findGroup ( const ConstString key,
const ConstString 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 89 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::Bottle, yarp::os::ResourceFinder, yarp::os::impl::StoreNull, yarp::os::impl::Storable, and NullBottle.

Definition at line 101 of file Searchable.cpp.

◆ toString()

virtual ConstString yarp::os::Searchable::toString ( ) const
pure virtual

Return a standard text representation of the content of the object.

The representation is readable by the Bottle and Property classes.

Returns
A standard text representation of the content of the object.

Implemented in yarp::os::Property, yarp::os::impl::StoreDict, yarp::os::impl::StoreList, yarp::os::impl::StoreDouble, yarp::os::impl::StoreBlob, yarp::os::Value, yarp::os::ResourceFinder, yarp::os::impl::StoreString, yarp::os::Bottle, yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, yarp::os::impl::StoreNull, and yarp::os::impl::Storable.

Member Data Documentation

◆ monitor

SearchMonitor* yarp::os::Searchable::monitor
private

Definition at line 58 of file Searchable.h.

◆ monitorContext

ConstString yarp::os::Searchable::monitorContext
private

Definition at line 59 of file Searchable.h.


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