Simox  2.3.74.0
VirtualRobot::RuntimeEnvironment Class Reference

Static Public Member Functions

static EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::vector< std::string > getDataPaths ()
 Return vector of all data paths. More...
 
static void setCaption (const std::string &caption)
 Set the runtime environment caption. More...
 
static bool addDataPath (const std::string &path, bool quiet=false)
 
static void considerKey (const std::string &key, const std::string &description="")
 Enable the command line search for given key. Only keys that are enabled can later be accessed with the getValue() method. More...
 
static void considerFlag (const std::string &flag, const std::string &description="")
 Enable the command line search for given flag. A flag does not take an argument but is either present or not. More...
 
static bool getDataFileAbsolute (std::string &fileName)
 
static void processCommandLine (int argc, char *argv[])
 
static void addKeyValuePair (const std::string &key, const std::string &value)
 Manually add a key/value pair. More...
 
static std::string getValue (const std::string &key, const std::string &defaultValue="")
 Return the corresponding vale to key. If key cannot be found, defaultValue is returned. More...
 
static bool hasValue (const std::string &key)
 
static bool hasFlag (const std::string &flag)
 Indicate whether the given flag was specified. More...
 
static bool hasHelpFlag ()
 Indicate whether the 'help' flag was specified. More...
 
static std::map< std::string, std::string > getKeyValuePairs ()
 Return all key value pairs. More...
 
static std::vector< std::string > getUnrecognizedOptions ()
 Return all unrecognized options. More...
 
static bool toVector3f (const std::string &s, Eigen::Vector3f &storeResult)
 Convert strings as '(a,b,c)' to a 3 dimensional vector. More...
 
static float toFloat (const std::string &s)
 Get the given string as float. More...
 
static int toInt (const std::string &s)
 Get the given string as int. More...
 
static std::string checkValidFileParameter (const std::string &key, const std::string &standardFilename)
 
static std::string checkParameter (const std::string &key, const std::string &standardValue="")
 
static void print ()
 Print status. More...
 
static void printOptions (std::ostream &os=std::cout)
 Print the command line options (as printed by boost::program_options) to os. More...
 
static void cleanup ()
 Free all resources. Usually not not needed, since on application exit all resources are freed automatically. More...
 

Protected Member Functions

 RuntimeEnvironment ()
 
virtual ~RuntimeEnvironment ()
 

Static Protected Member Functions

static void init ()
 

Detailed Description

The runtime environment holds data paths and program arguments. Data files can be located by the getDataFileAbsolute method. Here, the environment variable SIMOX_DATA_PATH and VIRTUAL_ROBOT_DATA_PATH are considered. In addition, the install data directory is added at the end of the list of data paths for convenient access.

Constructor & Destructor Documentation

◆ RuntimeEnvironment()

VirtualRobot::RuntimeEnvironment::RuntimeEnvironment ( )
inlineprotected

◆ ~RuntimeEnvironment()

virtual VirtualRobot::RuntimeEnvironment::~RuntimeEnvironment ( )
inlineprotectedvirtual

Member Function Documentation

◆ addDataPath()

bool VirtualRobot::RuntimeEnvironment::addDataPath ( const std::string &  path,
bool  quiet = false 
)
static

Add a path to global data path vector. These paths are searched within the getDataFileAbsolute() method. Only valid paths are processed.

Parameters
pathThe path to add.
quietIf set, invalid paths are quietly ignored. Otherwise an error is printed.
Returns
true on success (path has to be a directory or a symlink).

◆ addKeyValuePair()

void VirtualRobot::RuntimeEnvironment::addKeyValuePair ( const std::string &  key,
const std::string &  value 
)
static

Manually add a key/value pair.

◆ checkParameter()

std::string VirtualRobot::RuntimeEnvironment::checkParameter ( const std::string &  key,
const std::string &  standardValue = "" 
)
static

Checks command line arguments for parameter key. If present the corresponding value is returned, otherwise standardValue will be returned.

◆ checkValidFileParameter()

std::string VirtualRobot::RuntimeEnvironment::checkValidFileParameter ( const std::string &  key,
const std::string &  standardFilename 
)
static

Check if command line parameters specify a valid filename and in case the key is not present in the command line arguments or the file was not found, the standardFilename is used. Additionally the absolute filenames are considered by calling getDataFileAbsolute().

Parameters
keyThe key which is checked for a filename. It is checked if the key is present and if so, it is tried to construct a valid filename with getDataFileAbsolute().
standardFilenameIn case a valid file could not be determined, this file will be returned (additionally it is made absolute by calling getDataFileAbsolute(). Hence, a filename with a relative path can be passed and all datapaths are searched for it.
Returns
A valid filename if it can be found, otherwise the standardFilename is returned.

◆ cleanup()

void VirtualRobot::RuntimeEnvironment::cleanup ( )
static

Free all resources. Usually not not needed, since on application exit all resources are freed automatically.

◆ considerFlag()

void VirtualRobot::RuntimeEnvironment::considerFlag ( const std::string &  flag,
const std::string &  description = "" 
)
static

Enable the command line search for given flag. A flag does not take an argument but is either present or not.

◆ considerKey()

void VirtualRobot::RuntimeEnvironment::considerKey ( const std::string &  key,
const std::string &  description = "" 
)
static

Enable the command line search for given key. Only keys that are enabled can later be accessed with the getValue() method.

◆ getDataFileAbsolute()

bool VirtualRobot::RuntimeEnvironment::getDataFileAbsolute ( std::string &  fileName)
static

Tries to find a file with name fileName. Therefore the working directory followed by all data paths are checked if the file can be found.

Parameters
fileNameCould be a filename or a relative path. In case the file could be located, the absolute path is stored in place.
Returns
True when the file could be located (the result will be stored in fileName).

◆ getDataPaths()

std::vector< std::string > VirtualRobot::RuntimeEnvironment::getDataPaths ( )
static

Return vector of all data paths.

◆ getKeyValuePairs()

std::map< std::string, std::string > VirtualRobot::RuntimeEnvironment::getKeyValuePairs ( )
static

Return all key value pairs.

◆ getUnrecognizedOptions()

std::vector< std::string > VirtualRobot::RuntimeEnvironment::getUnrecognizedOptions ( )
static

Return all unrecognized options.

◆ getValue()

std::string VirtualRobot::RuntimeEnvironment::getValue ( const std::string &  key,
const std::string &  defaultValue = "" 
)
static

Return the corresponding vale to key. If key cannot be found, defaultValue is returned.

◆ hasFlag()

bool VirtualRobot::RuntimeEnvironment::hasFlag ( const std::string &  flag)
static

Indicate whether the given flag was specified.

◆ hasHelpFlag()

bool VirtualRobot::RuntimeEnvironment::hasHelpFlag ( )
static

Indicate whether the 'help' flag was specified.

◆ hasValue()

bool VirtualRobot::RuntimeEnvironment::hasValue ( const std::string &  key)
static

◆ init()

void VirtualRobot::RuntimeEnvironment::init ( )
staticprotected

◆ print()

void VirtualRobot::RuntimeEnvironment::print ( )
static

Print status.

◆ printOptions()

void VirtualRobot::RuntimeEnvironment::printOptions ( std::ostream &  os = std::cout)
static

Print the command line options (as printed by boost::program_options) to os.

◆ processCommandLine()

void VirtualRobot::RuntimeEnvironment::processCommandLine ( int  argc,
char *  argv[] 
)
static

The command line parameters can be passed in order to generate a map of key/value pairs. All "--key value" pairs for which the key was enabled with the allowCommandLineOption() method are processed and stored as std::strings in a std::map. In addition, all "--data-path <path>" entries are extracted and the according data paths are stored. All unrecognized options are also stored.

◆ setCaption()

void VirtualRobot::RuntimeEnvironment::setCaption ( const std::string &  caption)
static

Set the runtime environment caption.

◆ toFloat()

float VirtualRobot::RuntimeEnvironment::toFloat ( const std::string &  s)
static

Get the given string as float.

◆ toInt()

int VirtualRobot::RuntimeEnvironment::toInt ( const std::string &  s)
static

Get the given string as int.

◆ toVector3f()

bool VirtualRobot::RuntimeEnvironment::toVector3f ( const std::string &  s,
Eigen::Vector3f &  storeResult 
)
static

Convert strings as '(a,b,c)' to a 3 dimensional vector.