Simox  2.3.50
VirtualRobot::RuntimeEnvironment Class Reference

Static Public Member Functions

static EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::vector< std::string > getDataPaths ()
 
static bool addDataPath (const std::string &path, bool quiet=false)
 
static void considerKey (const std::string &key)
 
static bool getDataFileAbsolute (std::string &fileName)
 
static void processCommandLine (int argc, char *argv[])
 
static void addKeyValuePair (const std::string &key, const std::string &value)
 
static std::string getValue (const std::string &key)
 
static bool hasValue (const std::string &key)
 
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)
 
static float toFloat (const std::string &s)
 toFloat Get command line parameter as float More...
 
static int toInt (const std::string &s)
 
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 cleanup ()
 

Protected Member Functions

 RuntimeEnvironment ()
 
virtual ~RuntimeEnvironment ()
 

Static Protected Member Functions

static void init ()
 

Static Protected Attributes

static bool pathInitialized = false
 
static std::vector< std::string > processKeys
 
static std::vector< std::string > dataPaths
 
static std::vector< std::string > unrecognizedOptions
 
static std::map< std::string, std::string > keyValues
 

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

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

Member Function Documentation

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).
void VirtualRobot::RuntimeEnvironment::addKeyValuePair ( const std::string &  key,
const std::string &  value 
)
static

Manually add a key/value pair.

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.

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.
void VirtualRobot::RuntimeEnvironment::cleanup ( )
static

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

void VirtualRobot::RuntimeEnvironment::considerKey ( const std::string &  key)
static

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

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).
std::vector< std::string > VirtualRobot::RuntimeEnvironment::getDataPaths ( )
static

Return vector of all data paths.

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

return all key value pairs

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

return all unrecognized options

std::string VirtualRobot::RuntimeEnvironment::getValue ( const std::string &  key)
static

Return the corresponding vale to key. If key cannot be found, an empty string is returned.

bool VirtualRobot::RuntimeEnvironment::hasValue ( const std::string &  key)
static
void VirtualRobot::RuntimeEnvironment::init ( )
staticprotected
void VirtualRobot::RuntimeEnvironment::print ( )
static

Print status.

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.

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

toFloat Get command line parameter as float

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

Converts strings as '(a,b,c)' to 3dim Vectors.

Field Documentation

std::vector< std::string > VirtualRobot::RuntimeEnvironment::dataPaths
staticprotected
std::map< std::string, std::string > VirtualRobot::RuntimeEnvironment::keyValues
staticprotected
bool VirtualRobot::RuntimeEnvironment::pathInitialized = false
staticprotected
std::vector< std::string > VirtualRobot::RuntimeEnvironment::processKeys
staticprotected
std::vector< std::string > VirtualRobot::RuntimeEnvironment::unrecognizedOptions
staticprotected