ArmarXDataPath Class Reference

#include <ArmarXCore/core/system/ArmarXDataPath.h>

Static Public Member Functions

static void addDataPath (const std::string &dataPath)
 
static void addDataPaths (const std::string &dataPathList)
 
static void addDataPaths (const std::vector< std::string > &dataPathList)
 
static std::string cleanPath (const std::string &filepathStr)
 
static bool FindPackageAndAddDataPath (const std::string &packageName)
 Search for the package and add its data path if it was found. More...
 
static std::string getAbsolutePath (const std::string &relativeFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
 
static bool getAbsolutePath (const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
 
static std::string GetCachePath ()
 The base Cache directory of ArmarX. More...
 
static std::vector< std::string > getDataPaths ()
 
static std::string GetDefaultUserConfigPath ()
 The user config directory of ArmarX. More...
 
static std::string getHomePath ()
 
static std::string getProject (const std::vector< std::string > &projects, const std::string &relativeFilename)
 
static std::string getRelativeArmarXPath (const std::string &absolutePathString)
 This method tries to morph a given absolute path into a relative path to a ArmarXDataPath. More...
 
static void initDataPaths (const std::string &dataPathList)
 
static bool mergePaths (std::string path, std::string subPath, std::string &result)
 
static std::string relativeTo (const std::string &from, const std::string &to)
 Transform an absolute filepath into a relative path of the other absolute filepath. More...
 
static bool ReplaceEnvVars (std::string &string)
 ReplaceEnvVars replaces environment variables in a string with their values, if the env. More...
 
static void ReplaceVar (std::string &string, const std::string varName, const std::string &varValue)
 Replaces all occurences of variables in bash notation, e.g. More...
 
static void ResolveHomePath (std::string &path)
 Resolves a path like ~/myfile.txt or $HOME/myfile.txt to /home/user/myfile.txt. More...
 
static std::string resolvePath (const std::string &path, bool verbose=true)
 Resolves environment variables and home paths and tries to make path absolute. More...
 
static bool SearchReadableFile (const std::string &querryFileName, std::string &resultFileName, bool verbose=true)
 

Detailed Description

The ArmarXDataPath class provides static methods to handle ArmarX data directories.

Data paths can be defined via the environment variable ArmarXData_DIRS (semicolon separated list). Additionally ArmarX Properties (ArmarX.DataPath) can be used either by command line or by config files.

The search order is as follows

  1. Environment variable
  2. Properties

Usually, the paths are initialized by the framework automatically (see Application).

To convert a filename given relatively to one of the data directories use the following syntax

std::string relativeFilename("robot/ArmarIII/ArmarIII.xml");
std::string absoluteFilename;
bool fileFound = ArmarXDataPath::getAbsolutePath(relativeFilename, absoluteFilename);
if (fileFound)
load(absoluteFilename);

Definition at line 57 of file ArmarXDataPath.h.

Member Function Documentation

◆ addDataPath()

void addDataPath ( const std::string &  dataPath)
static

Definition at line 576 of file ArmarXDataPath.cpp.

◆ addDataPaths() [1/2]

void addDataPaths ( const std::string &  dataPathList)
static

Add data paths to the internal search list. Multiple paths are separated by a semicolon ";" and environment variables specified with "${}" inside the paths are expanded. The latest additions have the highest precedence, when solving relative paths.

addDataPaths("/root;/usr");
addDataPaths("/home;/var");

This would result in the following precedence order: home, var, root, usr.

Parameters
dataPathListA semicolon separated list of absolute paths. Each path is checked for existance and in case it is not present it is silently ignored.

Definition at line 559 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ addDataPaths() [2/2]

void addDataPaths ( const std::vector< std::string > &  dataPathList)
static

Definition at line 566 of file ArmarXDataPath.cpp.

◆ cleanPath()

std::string cleanPath ( const std::string &  filepathStr)
static

Definition at line 331 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ FindPackageAndAddDataPath()

bool FindPackageAndAddDataPath ( const std::string &  packageName)
static

Search for the package and add its data path if it was found.

Returns
returns whether the package was found

Definition at line 829 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAbsolutePath() [1/2]

std::string getAbsolutePath ( const std::string &  relativeFilename,
const std::vector< std::string > &  additionalSearchPaths = {},
bool  verbose = true 
)
static

This method searches all data paths for a valid file. The precedence of the datapaths is in the insertion order. The datapaths given to this function have the highest precedence.

Parameters
relativeFilenameThe file relatively to one of the data paths
additionalSearchPathsAdditional search paths that are not in the globally registered variable.
verboseIf set to true, the function will print all available paths and the requested file to the console on failure.
Returns
In case a valid absolute filename can be found, it is returned (otherwise an empty string is returned).

Definition at line 208 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:

◆ getAbsolutePath() [2/2]

bool getAbsolutePath ( const std::string &  relativeFilename,
std::string &  storeAbsoluteFilename,
const std::vector< std::string > &  additionalSearchPaths = {},
bool  verbose = true 
)
static

This method searches all data paths for a valid file. The precedence of the datapaths is in the insertion order. The datapaths given to this function have the highest precedence.

Parameters
relativeFilenameThe file relatively to one of the data paths
storeAbsoluteFilenameIn case a valid absolute filename can be found, it is stored here.
additionalSearchPathsAdditional search paths that are not in the globally registered variable.
verboseIf set to true, the function will print all available paths and the requested file to the console on failure.
Returns
true on success.

Definition at line 111 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:

◆ GetCachePath()

std::string GetCachePath ( )
static

The base Cache directory of ArmarX.

Returns
returns the cache path of ArmarX or an empty String if there is no valid Application instance

Definition at line 734 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDataPaths()

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

Returns all absolute data paths.

Definition at line 620 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ GetDefaultUserConfigPath()

std::string GetDefaultUserConfigPath ( )
static

The user config directory of ArmarX.

Returns
returns the default path of ArmarX (usually $ARMARX_WORKSPACE/armarx_config) or the user set path via $ARMARX_CONFIG_DIR

Definition at line 782 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ getHomePath()

std::string getHomePath ( )
static

The base directory of ArmarX. Checks the environment variables for ArmarXHome_DIR and returns the entry.

Definition at line 583 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getProject()

std::string getProject ( const std::vector< std::string > &  projects,
const std::string &  relativeFilename 
)
static

Search all project data paths and reports within which project the file can be located. First hit is reported. If none of the project's data paths contains the file, an empty string is returned.

Parameters
projectsList of ArmarXProjects
relativeFilenameFilename relative to a project's data directory.
Returns
The armarx project that contains the given file in its data directory.

Definition at line 301 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelativeArmarXPath()

std::string getRelativeArmarXPath ( const std::string &  absolutePathString)
static

This method tries to morph a given absolute path into a relative path to a ArmarXDataPath.

Parameters
absolutePathStringString of an absolute (file)path
Returns
The relative path to the given absolute (file)path, if possible. Otherwise the given absolute path.
See also
addDataPaths()

Definition at line 382 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:

◆ initDataPaths()

void initDataPaths ( const std::string &  dataPathList)
static

Initializes data paths. Automatically called by an Application.

Definition at line 477 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mergePaths()

bool mergePaths ( std::string  path,
std::string  subPath,
std::string &  result 
)
static

Definition at line 456 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ relativeTo()

std::string relativeTo ( const std::string &  from,
const std::string &  to 
)
static

Transform an absolute filepath into a relative path of the other absolute filepath.

For example:

std::string path = "projects/armarx/trunk/Core";
std::string subPath = "projects/armarx/trunk/Core/data/elem.xml";
std::string result = ArmarXDataPath::relativeTo(path, subPath);
BOOST_CHECK_EQUAL("data/elem.xml", result);
Parameters
fromBase path, to which the path should be made relative
toPath that should be made relative
Returns
Relative path
Exceptions
LocalException

Definition at line 410 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ ReplaceEnvVars()

bool ReplaceEnvVars ( std::string &  string)
static

ReplaceEnvVars replaces environment variables in a string with their values, if the env.

variable is set. E.g. "${HOME}/.armarx/default.cfg"

Parameters
stringString in which the environment variables are to be replaced
Returns
returns true if atleast one replacement has been done.

Definition at line 483 of file ArmarXDataPath.cpp.

+ Here is the caller graph for this function:

◆ ReplaceVar()

void ReplaceVar ( std::string &  string,
const std::string  varName,
const std::string &  varValue 
)
static

Replaces all occurences of variables in bash notation, e.g.

${HOME}, with the given value in the string.

Parameters
stringString to be modified
varNameName of the variable
varValueValue to be inserted in place of varName occurrences

Definition at line 513 of file ArmarXDataPath.cpp.

◆ ResolveHomePath()

void ResolveHomePath ( std::string &  path)
static

Resolves a path like ~/myfile.txt or $HOME/myfile.txt to /home/user/myfile.txt.

Parameters
string

Definition at line 521 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolvePath()

std::string resolvePath ( const std::string &  path,
bool  verbose = true 
)
static

Resolves environment variables and home paths and tries to make path absolute.

Parameters
pathThe path, may contain env. variables and be a relative data path.
verbosePassed to getAbsolutePath().
Returns
The resolved path.

Definition at line 542 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SearchReadableFile()

bool SearchReadableFile ( const std::string &  querryFileName,
std::string &  resultFileName,
bool  verbose = true 
)
static

Definition at line 218 of file ArmarXDataPath.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files:
armarx::ArmarXDataPath::relativeTo
static std::string relativeTo(const std::string &from, const std::string &to)
Transform an absolute filepath into a relative path of the other absolute filepath.
Definition: ArmarXDataPath.cpp:410
armarx::ArmarXDataPath::addDataPaths
static void addDataPaths(const std::string &dataPathList)
Definition: ArmarXDataPath.cpp:559
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:111
armarx::armem::server::ltm::mongodb::util::load
void load(const mongocxx::database &db, armem::wm::Memory &m)
Definition: operations.cpp:40