YARP  2.3.68+225-20170329.5+gitb0d3289
Yet Another Robot Platform
yarp::os::Value Class Reference

A single value (typically within a Bottle). More...

#include <yarp/os/Value.h>

+ Inheritance diagram for yarp::os::Value:

Public Member Functions

 Value ()
 Construct a list Value. More...
 
 Value (int x, bool isVocab=false)
 Construct an integer Value. More...
 
 Value (double x)
 Construct a floating point Value. More...
 
 Value (const ConstString &str, bool isVocab=false)
 Construct a string Value. More...
 
 Value (void *data, int length)
 Construct a binary data Value. More...
 
 Value (const Value &alt)
 Copy constructor. More...
 
const Valueoperator= (const Value &alt)
 Assignment operator. More...
 
virtual ~Value ()
 Destructor. More...
 
virtual bool isBool () const
 Checks if value is a boolean. More...
 
virtual bool isInt () const
 Checks if value is an integer (32 bit or smaller). More...
 
virtual bool isInt64 () const
 Checks if value is a 64-bit integer or smaller. More...
 
virtual bool isString () const
 Checks if value is a string. More...
 
virtual bool isDouble () const
 Checks if value is a floating point number. More...
 
virtual bool isList () const
 Checks if value is a list. More...
 
virtual bool isDict () const
 Checks if value is a dictionary. More...
 
virtual bool isVocab () const
 Checks if value is a vocabulary identifier. More...
 
virtual bool isBlob () const
 Checks if value is a binary object. More...
 
virtual bool asBool () const
 Get boolean value. More...
 
virtual int asInt () const
 Get integer value. More...
 
virtual YARP_INT64 asInt64 () const
 Get 64-bit integer value. More...
 
virtual int asVocab () const
 Get vocabulary identifier as an integer. More...
 
virtual double asDouble () const
 Get floating point value. More...
 
virtual ConstString asString () const
 Get string value. More...
 
virtual BottleasList () const
 Get list value. More...
 
virtual PropertyasDict () const
 Get dictionary (hash table) value. More...
 
virtual SearchableasSearchable () const
 Get dictionary or list value. More...
 
virtual const char * asBlob () const
 Get binary data value. More...
 
virtual size_t asBlobLength () const
 Get binary data length. More...
 
virtual bool read (ConnectionReader &connection)
 Read this object from a network connection. More...
 
virtual bool write (ConnectionWriter &connection)
 Write this object to a network connection. More...
 
virtual bool check (const ConstString &key) const
 Check if there exists a property of the given name. More...
 
virtual Valuefind (const ConstString &key) const
 Gets a value corresponding to a given keyword. More...
 
virtual BottlefindGroup (const ConstString &key) const
 Gets a list corresponding to a given keyword. More...
 
bool operator== (const Value &alt) const
 Equality test. More...
 
bool operator!= (const Value &alt) const
 Inequality test. More...
 
bool operator== (const char *alt) const
 
bool operator!= (const char *alt) const
 
void fromString (const char *str)
 Set value to correspond to a textual representation. More...
 
ConstString toString () const
 Return a standard text representation of the content of the object. More...
 
virtual Valuecreate () const
 Create a new value of the same type. More...
 
virtual Valueclone () const
 Create a copy of the value. More...
 
virtual int getCode () const
 Get standard type code of value. More...
 
virtual bool isNull () const
 Checks if the object is invalid. More...
 
virtual bool isLeaf () const
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType ()
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType ()
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion ()
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement ()
 This is called when the port is about to begin writing operations. More...
 
virtual Type getWriteType ()
 
- Public Member Functions inherited from yarp::os::Searchable
 Searchable ()
 Default constructor. More...
 
virtual ~Searchable ()
 Destructor. More...
 
virtual bool check (const ConstString &key, const ConstString &comment) const
 Check if there exists a property of the given name. 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...
 

Static Public Member Functions

static ValuemakeInt (int x)
 Create an integer Value. More...
 
static ValuemakeDouble (double x)
 Create a floating point Value. More...
 
static ValuemakeString (const ConstString &str)
 Create a string Value. More...
 
static ValuemakeVocab (int v)
 Create a vocabulary identifier Value. More...
 
static ValuemakeVocab (const ConstString &str)
 Create a vocabulary identifier Value. More...
 
static ValuemakeBlob (void *data, int length)
 Create a Value containing binary data. More...
 
static ValuemakeList ()
 Create a list Value. More...
 
static ValuemakeList (const char *txt)
 Create a list Value and initialize it. More...
 
static ValuemakeValue (const ConstString &txt)
 Create a Value from a text description. More...
 
static ValuegetNullValue ()
 Return an invalid, "null" Value. More...
 
- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 

Private Member Functions

void setProxy (yarp::os::impl::Storable *proxy)
 
void ok () const
 

Private Attributes

yarp::os::impl::Storableproxy
 

Detailed Description

A single value (typically within a Bottle).

Values can be integers, strings, doubles (floating-point numbers), lists, vocabulary, or blobs (unformatted binary data). This set is carefully chosen to have good text and binary representations both for network transmission and human viewing/generation. Lists are represented as a nested Bottle object. Value objects are Searchable - but you won't find anything in them unless they are actually a list.

Examples:
bottle/main.cpp, dev/file_grabber.cpp, dev/motortest.cpp, framerate/main.cpp, os/browse_bottle.cpp, os/database.cpp, os/image_process.cpp, and os/image_source.cpp.

Definition at line 36 of file Value.h.

Constructor & Destructor Documentation

◆ Value() [1/6]

Value::Value ( )

Construct a list Value.

Definition at line 17 of file Value.cpp.

◆ Value() [2/6]

Value::Value ( int  x,
bool  isVocab = false 
)

Construct an integer Value.

Parameters
xthe integer
isVocabset this to true if the integer should be interpreted as a vocabulary identifier

Definition at line 23 of file Value.cpp.

◆ Value() [3/6]

Value::Value ( double  x)

Construct a floating point Value.

Parameters
xthe number

Definition at line 35 of file Value.cpp.

◆ Value() [4/6]

Value::Value ( const ConstString str,
bool  isVocab = false 
)
explicit

Construct a string Value.

Parameters
strthe string
isVocabset this to true if the string should be interpreted as a vocabulary identifier

Definition at line 43 of file Value.cpp.

◆ Value() [5/6]

Value::Value ( void *  data,
int  length 
)

Construct a binary data Value.

Parameters
datathe data to copy
lengththe size of the data in bytes

Definition at line 55 of file Value.cpp.

◆ Value() [6/6]

Value::Value ( const Value alt)

Copy constructor.

Parameters
altthe value to copy

Definition at line 63 of file Value.cpp.

◆ ~Value()

Value::~Value ( )
virtual

Destructor.

Definition at line 104 of file Value.cpp.

Member Function Documentation

◆ asBlob()

const char * Value::asBlob ( ) const
virtual

Get binary data value.

Returns
pointer to binary data if value is indeed binary data. Otherwise returns YARP_NULLPTR

Reimplemented in yarp::os::impl::StoreBlob, and yarp::os::impl::Storable.

Definition at line 221 of file Value.cpp.

◆ asBlobLength()

size_t Value::asBlobLength ( ) const
virtual

Get binary data length.

Returns
length of binary data if value is indeed binary data. Otherwise returns 0

Reimplemented in yarp::os::impl::StoreBlob, and yarp::os::impl::Storable.

Examples:
os/browse_bottle.cpp.

Definition at line 227 of file Value.cpp.

◆ asBool()

bool Value::asBool ( ) const
virtual

Get boolean value.

Returns
boolean value if value is indeed a boolean. If it is another type, the appropriate cast value is returned. Otherwise returns false.

Reimplemented in yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Definition at line 166 of file Value.cpp.

◆ asDict()

Property * Value::asDict ( ) const
virtual

Get dictionary (hash table) value.

Returns
pointer to dictionary if value is indeed of the right type. Otherwise returns YARP_NULLPTR

Reimplemented in yarp::os::impl::StoreDict, and yarp::os::impl::Storable.

Definition at line 208 of file Value.cpp.

◆ asDouble()

double Value::asDouble ( ) const
virtual

Get floating point value.

Returns
floating point value if value is indeed a floating point. If it is another numeric type, the appropriate cast value is returned. Otherwise returns 0.

Reimplemented in yarp::os::impl::StoreDouble, yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Examples:
os/browse_bottle.cpp, and os/summer.cpp.

Definition at line 190 of file Value.cpp.

◆ asInt()

int Value::asInt ( ) const
virtual

Get integer value.

Returns
integer value if value is indeed an integer. If it is another numeric type, the appropriate cast value is returned. Otherwise returns 0.

Reimplemented in yarp::os::impl::StoreDouble, yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Examples:
os/bottle_add.cpp, os/browse_bottle.cpp, os/view_count.cpp, and property/main.cpp.

Definition at line 172 of file Value.cpp.

◆ asInt64()

YARP_INT64 Value::asInt64 ( ) const
virtual

Get 64-bit integer value.

Returns
64-bit integer value if value is indeed an integer. If it is another numeric type, the appropriate cast value is returned. Otherwise returns 0.

Reimplemented in yarp::os::impl::StoreDouble, yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Definition at line 178 of file Value.cpp.

◆ asList()

Bottle * Value::asList ( ) const
virtual

Get list value.

Returns
pointer to list if value is indeed a list. Otherwise returns YARP_NULLPTR

Reimplemented in yarp::os::impl::StoreList, and yarp::os::impl::Storable.

Examples:
os/browse_bottle.cpp.

Definition at line 202 of file Value.cpp.

◆ asSearchable()

Searchable * Value::asSearchable ( ) const
virtual

Get dictionary or list value.

Returns
pointer to dictionary or list value if present. Otherwise returns YARP_NULLPTR

Reimplemented in yarp::os::impl::Storable.

Definition at line 214 of file Value.cpp.

◆ asString()

ConstString Value::asString ( ) const
virtual

Get string value.

Returns
string value if value is indeed a string. Otherwise returns empty string.

Reimplemented in yarp::os::impl::StoreString, yarp::os::impl::StoreVocab, and yarp::os::impl::Storable.

Examples:
framerate/main.cpp, os/browse_bottle.cpp, and property/main.cpp.

Definition at line 196 of file Value.cpp.

◆ asVocab()

int Value::asVocab ( ) const
virtual

Get vocabulary identifier as an integer.

Returns
integer value of vocabulary identifier.

Reimplemented in yarp::os::impl::StoreString, yarp::os::impl::StoreVocab, yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Examples:
os/browse_bottle.cpp.

Definition at line 184 of file Value.cpp.

◆ check()

bool Value::check ( const ConstString key) const
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

Implements yarp::os::Searchable.

Reimplemented in yarp::os::impl::Storable.

Definition at line 269 of file Value.cpp.

◆ clone()

Value * Value::clone ( ) const
virtual

Create a copy of the value.

Returns
the new value, which will equal this.

Reimplemented in yarp::os::impl::Storable.

Definition at line 315 of file Value.cpp.

◆ create()

Value * Value::create ( ) const
virtual

Create a new value of the same type.

Returns
the new value.

Reimplemented in yarp::os::impl::Storable.

Definition at line 309 of file Value.cpp.

◆ find()

Value & Value::find ( const ConstString key) const
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.

Implements yarp::os::Searchable.

Reimplemented in yarp::os::impl::StoreDict, yarp::os::impl::StoreList, and yarp::os::impl::Storable.

Definition at line 275 of file Value.cpp.

◆ findGroup()

Bottle & Value::findGroup ( const ConstString key) const
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.

Implements yarp::os::Searchable.

Reimplemented in yarp::os::impl::StoreDict, yarp::os::impl::StoreList, and yarp::os::impl::Storable.

Definition at line 281 of file Value.cpp.

◆ fromString()

void Value::fromString ( const char *  str)

Set value to correspond to a textual representation.

For example if str="10" then the value will be an integer, if str="(1 2 3)" the value will be a list.

Parameters
strthe textual representation.

Definition at line 299 of file Value.cpp.

◆ getCode()

int Value::getCode ( ) const
virtual

◆ getNullValue()

Value & Value::getNullValue ( )
static

Return an invalid, "null" Value.

Returns
an invalid "null" Value

Definition at line 401 of file Value.cpp.

◆ isBlob()

bool Value::isBlob ( ) const
virtual

Checks if value is a binary object.

If so, asBlob() and asBlobLength() will return it.

Returns
true iff value is a binary object.

Reimplemented in yarp::os::impl::StoreBlob, and yarp::os::impl::Storable.

Definition at line 160 of file Value.cpp.

◆ isBool()

bool Value::isBool ( ) const
virtual

Checks if value is a boolean.

If so, asBool() will return that boolean.

Returns
true iff value is a boolean

Reimplemented in yarp::os::impl::StoreVocab, and yarp::os::impl::Storable.

Definition at line 112 of file Value.cpp.

◆ isDict()

bool Value::isDict ( ) const
virtual

Checks if value is a dictionary.

If so, asDict() will return that dictionary.

Returns
true iff value is a dictionary

Reimplemented in yarp::os::impl::StoreDict, and yarp::os::impl::Storable.

Definition at line 148 of file Value.cpp.

◆ isDouble()

bool Value::isDouble ( ) const
virtual

Checks if value is a floating point number.

If so, asDouble() will return that number.

Returns
true iff value is a floating point number

Reimplemented in yarp::os::impl::StoreDouble, and yarp::os::impl::Storable.

Definition at line 136 of file Value.cpp.

◆ isInt()

bool Value::isInt ( ) const
virtual

Checks if value is an integer (32 bit or smaller).

If so, asInt() will return that integer.

Returns
true iff value is an integer

Reimplemented in yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Definition at line 118 of file Value.cpp.

◆ isInt64()

bool Value::isInt64 ( ) const
virtual

Checks if value is a 64-bit integer or smaller.

If so, asInt64() will return that integer.

Returns
true iff value is a 64-bit integer or smaller

Reimplemented in yarp::os::impl::StoreInt64, yarp::os::impl::StoreInt, and yarp::os::impl::Storable.

Definition at line 124 of file Value.cpp.

◆ isLeaf()

bool Value::isLeaf ( ) const
virtual

Reimplemented in yarp::os::impl::Storable.

Definition at line 333 of file Value.cpp.

◆ isList()

bool Value::isList ( ) const
virtual

Checks if value is a list.

If so, asList() will return that list.

Returns
true iff value is a list

Reimplemented in yarp::os::impl::StoreList, and yarp::os::impl::Storable.

Examples:
os/browse_bottle.cpp.

Definition at line 142 of file Value.cpp.

◆ isNull()

bool Value::isNull ( ) const
virtual

Checks if the object is invalid.

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

Reimplemented from yarp::os::Searchable.

Reimplemented in yarp::os::impl::StoreNull, and yarp::os::impl::Storable.

Examples:
os/database.cpp.

Definition at line 327 of file Value.cpp.

◆ isString()

bool Value::isString ( ) const
virtual

Checks if value is a string.

If so, asString() will return that string.

Returns
true iff value is a string

Reimplemented in yarp::os::impl::StoreString, and yarp::os::impl::Storable.

Definition at line 130 of file Value.cpp.

◆ isVocab()

bool Value::isVocab ( ) const
virtual

Checks if value is a vocabulary identifier.

If so, asVocab() will return it.

Returns
true iff value is a vocabulary identifier

Reimplemented in yarp::os::impl::StoreVocab, and yarp::os::impl::Storable.

Definition at line 154 of file Value.cpp.

◆ makeBlob()

Value * Value::makeBlob ( void *  data,
int  length 
)
static

Create a Value containing binary data.

Parameters
datathe data (will be copied)
lengththe size of the data in bytes
Returns
a Value containing binary data

Definition at line 368 of file Value.cpp.

◆ makeDouble()

Value * Value::makeDouble ( double  x)
static

Create a floating point Value.

Parameters
xthe value to take on
Returns
a floating point Value

Definition at line 344 of file Value.cpp.

◆ makeInt()

Value * Value::makeInt ( int  x)
static

Create an integer Value.

Parameters
xthe value to take on
Returns
an integer Value

Definition at line 338 of file Value.cpp.

◆ makeList() [1/2]

Value * Value::makeList ( )
static

Create a list Value.

Returns
a list Value
Examples:
bottle/main.cpp.

Definition at line 375 of file Value.cpp.

◆ makeList() [2/2]

Value * Value::makeList ( const char *  txt)
static

Create a list Value and initialize it.

Parameters
txtthe list in text form, e.g. "1 2.0 (4 5) xyz"
Returns
a list Value

Definition at line 381 of file Value.cpp.

◆ makeString()

Value * Value::makeString ( const ConstString str)
static

Create a string Value.

Parameters
strthe value to take on
Returns
a string Value

Definition at line 350 of file Value.cpp.

◆ makeValue()

Value * Value::makeValue ( const ConstString txt)
static

Create a Value from a text description.

Parameters
txtthe description. E.g. "10" will create an integer, "(5 6 7)" will create a list.
Returns
the Value to which the text description corresponds

Definition at line 391 of file Value.cpp.

◆ makeVocab() [1/2]

Value * Value::makeVocab ( int  v)
static

Create a vocabulary identifier Value.

Parameters
vthe value to take on
Returns
a vocabulary identifier Value

Definition at line 356 of file Value.cpp.

◆ makeVocab() [2/2]

Value * Value::makeVocab ( const ConstString str)
static

Create a vocabulary identifier Value.

Parameters
strthe value to take on
Returns
a vocabulary identifier Value

Definition at line 362 of file Value.cpp.

◆ ok()

void Value::ok ( ) const
private

Definition at line 417 of file Value.cpp.

◆ operator!=() [1/2]

bool Value::operator!= ( const Value alt) const

Inequality test.

Parameters
altthe value to compare against
Returns
true iff the values are not equal

Definition at line 294 of file Value.cpp.

◆ operator!=() [2/2]

bool yarp::os::Value::operator!= ( const char *  alt) const
inline

Definition at line 275 of file Value.h.

◆ operator=()

const Value & Value::operator= ( const Value alt)

Assignment operator.

Parameters
altthe value to copy
Returns
this object itself

Definition at line 72 of file Value.cpp.

◆ operator==() [1/2]

bool Value::operator== ( const Value alt) const

Equality test.

Parameters
altthe value to compare against
Returns
true iff the values are equal

Definition at line 287 of file Value.cpp.

◆ operator==() [2/2]

bool yarp::os::Value::operator== ( const char *  alt) const
inline

Definition at line 270 of file Value.h.

◆ read()

bool Value::read ( ConnectionReader reader)
virtual

Read this object from a network connection.

Override this for your particular class.

Parameters
readeran interface to the network connection for reading
Returns
true iff the object is successfully read

Implements yarp::os::Portable.

Reimplemented in yarp::os::impl::Storable.

Definition at line 233 of file Value.cpp.

◆ setProxy()

void Value::setProxy ( yarp::os::impl::Storable proxy)
private

Definition at line 407 of file Value.cpp.

◆ toString()

ConstString Value::toString ( ) const
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.

Implements yarp::os::Searchable.

Examples:
os/database.cpp.

Definition at line 303 of file Value.cpp.

◆ write()

bool Value::write ( ConnectionWriter writer)
virtual

Write this object to a network connection.

Override this for your particular class. Be aware that depending on the nature of the connections a port has, and what protocol they use, and how efficient the YARP implementation is, this method may be called once, twice, or many times, as the result of a single call to Port::write

Parameters
writeran interface to the network connection for writing
Returns
true iff the object is successfully written

Implements yarp::os::Portable.

Reimplemented in yarp::os::impl::Storable.

Definition at line 257 of file Value.cpp.

Member Data Documentation

◆ proxy

yarp::os::impl::Storable* yarp::os::Value::proxy
private

Definition at line 38 of file Value.h.


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