CARMA C++
carma::util::RuntimeDirs Class Reference

This class is a collection of static methods to return specific directories for a standard carma tree. More...

#include <carma/util/RuntimeDirs.h>

Static Public Member Functions

static std::string getConfDir (const std::string &programName)
 Get the configuration directory - assumes standard carma tree. More...
 
static std::string getConfFile (const std::string &programName, const std::string &confFilename)
 Get the absolute path of a configuration file. More...
 
static std::string getExecutable (const std::string &programName)
 Get absolute full path of executable, including program executable. More...
 
static std::string getExecutableDir (const std::string &programName)
 Get the directory where this program executable lives. More...
 
static std::string getRootDir (const std::string &programName)
 Get the root build or install directory - assumes standard carma tree. More...
 

Detailed Description

This class is a collection of static methods to return specific directories for a standard carma tree.

The standard carma tree is assumed to be of the form

              carmaRoot
                  |
     --------------------------- 
    /        |         |        \ 
  bin       lib      carma      conf 
                       |
                  -------------
                /       |       \
              Xpgk    Ypkg     Zpkg 
                |       |        |
              Test    Test     Test   

These routines start by getting the full path of the executable using the "which" shell command for the program name (usually passed in as arg[0] to the program) . We assume that the these are carma programs and are run from one of two locations:

  • carmaRoot/bin
  • carmaRoot/carma/...
    which is usually a Test sub-directory

If the program has been run from a "bin" directory, then its parent is selected as carmaRoot, otherwise the tree is ascended until "carma" is found and then its parent is selected as carmaRoot. If neither of these directories is found then an exception is thrown. All filenames are canonicalized, removing symbolic links and redundant slashes.

Definition at line 59 of file RuntimeDirs.h.

Member Function Documentation

static std::string carma::util::RuntimeDirs::getConfDir ( const std::string &  programName)
static

Get the configuration directory - assumes standard carma tree.

The conf directory is assumed to be /carmaRoot/conf/. This string is an absolute path that ends with a slash character (/).

Parameters
programNameas invoked (e.g. arg0)
See Also
getConfFile
getRootDir
Exceptions
ErrorExceptionif getRootDir() or canonicalize() has problems
static std::string carma::util::RuntimeDirs::getConfFile ( const std::string &  programName,
const std::string &  confFilename 
)
static

Get the absolute path of a configuration file.

If the filename begins with a slash then it is assumed to be an absolute path and is left untouched. If the filename begins with a dash then it is assumed to be a path local to the current working directory and the dash is removed with no further processing. All other filenames are appended to the conf directory and the conf directory canonicalized if requested.

Parameters
programNameas invoked (e.g. arg0)
confFilename
See Also
getConfDir
getRootDir
Exceptions
ErrorExceptionif getRootDir() or canonicalize() has problems
static std::string carma::util::RuntimeDirs::getExecutable ( const std::string &  programName)
static

Get absolute full path of executable, including program executable.

The bash builtin "which" command is used to obtain this path.

Parameters
programNameas invoked (e.g. arg0)
Exceptions
ErrorExceptionunder numerous conditions associated with fork/exec of the bash which command
static std::string carma::util::RuntimeDirs::getExecutableDir ( const std::string &  programName)
static

Get the directory where this program executable lives.

This string is an absolute path that ends with a slash character (/).

Parameters
programNameas invoked (e.g. arg0)
Exceptions
ErrorExceptionif get Excecutable or canonicalize() has problems
static std::string carma::util::RuntimeDirs::getRootDir ( const std::string &  programName)
static

Get the root build or install directory - assumes standard carma tree.

This string is an absolute path that ends with a slash character (/).

Parameters
programNameas invoked (e.g. arg0)
See Also
getConfDir
getConfFile
Exceptions
ErrorExceptionif the directory from which the program was run has no parent, or is not part of a standard carma tree, or if cannot get filename of executable

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