YARP  2.3.70
Yet Another Robot Platform
yarp::os::Vocab Class Reference

Short readable codes. More...

#include <yarp/os/Vocab.h>

Static Public Member Functions

static NetInt32 encode (const ConstString &str)
 Convert a string into a vocabulary identifier. More...
 
static ConstString decode (NetInt32 code)
 Convert a vocabulary identifier into a string. More...
 

Detailed Description

Short readable codes.

They are integers, for efficient switching, but have a readable (and writable) string representation. Codes are limited to 4 characters long (to fit in a standard network integer, NetInt32). This is a compromise to allow the creation of messages that can be parsed very efficiently by machine but nevertheless are human readable and writable. When switching on a Vocab code, we suggest you use the VOCABn macro defined in yarp/os/Vocab.h.

switch(code) {
case VOCAB3('s','e','t'): // switch on "set"
...
break;
case VOCAB4('s','t','o','p'): // switch on "stop"
...
break;
}

Your program will be efficient, and the codes used if they traverse the network will be human readable/writable.

Definition at line 52 of file Vocab.h.

Member Function Documentation

◆ decode()

ConstString Vocab::decode ( NetInt32  code)
static

Convert a vocabulary identifier into a string.

Parameters
codethe vocabulary identifier to convert
Returns
the string equivalent of the integer form of the identifier
Examples:
os/browse_bottle.cpp.

Definition at line 33 of file Vocab.cpp.

◆ encode()

NetInt32 Vocab::encode ( const ConstString str)
static

Convert a string into a vocabulary identifier.

If the string is longer than four characters, only the first four characters are used.

Parameters
strthe string to convert
Returns
the integer equivalent of the string form of the identifier
Examples:
os/database.cpp.

Definition at line 12 of file Vocab.cpp.


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