Helper class for finding config files and other external resources. More...
#include <yarp/os/ResourceFinder.h>
Classes | |
class | Private |
Public Member Functions | |
ResourceFinder () | |
ResourceFinder (const ResourceFinder &alt) | |
virtual | ~ResourceFinder () |
const ResourceFinder & | operator= (const ResourceFinder &alt) |
bool | setVerbose (bool verbose=true) |
Request that information be printed to the console on how resources are being found. More... | |
bool | setQuiet (bool quiet=true) |
Request that information be suppressed from the console. More... | |
bool | configure (int argc, char *argv[], bool skipFirstArgument=true) |
Sets up the ResourceFinder. More... | |
bool | setDefaultContext (const std::string &contextName) |
Sets the context for the current ResourceFinder object. More... | |
bool | setDefault (const std::string &key, const std::string &val) |
Provide a default value for a given key. More... | |
bool | setDefault (const std::string &key, std::int32_t val) |
Provide a default value for a given key. More... | |
bool | setDefault (const std::string &key, yarp::conf::float64_t val) |
Provide a default value for a given key. More... | |
bool | setDefault (const std::string &key, const yarp::os::Value &val) |
Provide a default value for a given key. More... | |
bool | setDefaultConfigFile (const std::string &fname) |
Provide a default value for the configuration file (can be overridden from command line with the –from argument) More... | |
std::string | findFile (const std::string &name) |
Find the full path to a file. More... | |
std::string | findFileByName (const std::string &name) |
Find the full path to a file. More... | |
std::string | findPath (const std::string &name) |
Expand a partial path to a full path. More... | |
yarp::os::Bottle | findPaths (const std::string &name) |
Expand a partial path to a list of paths. More... | |
std::string | findPath () |
Find the first existing directory in the search path. More... | |
std::string | getContext () |
Return the default "context" or "application name" used in searching for configuration files. More... | |
yarp::os::Bottle | getContexts () |
Return the full stack of contexts used in searching for configuration files. More... | |
bool | check (const std::string &key) const override |
Check if there exists a property of the given name. More... | |
Value & | find (const std::string &key) const override |
Gets a value corresponding to a given keyword. More... | |
Bottle & | findGroup (const std::string &key) const override |
Gets a list corresponding to a given keyword. More... | |
bool | isNull () const override |
Checks if the object is invalid. More... | |
std::string | toString () const override |
Return a standard text representation of the content of the object. More... | |
virtual ResourceFinder | findNestedResourceFinder (const std::string &key) |
Gets a section as a ResourceFinder object, retaining the context and configuration of the current ResourceFinder. More... | |
bool | isConfigured () const |
std::string | getHomeContextPath () |
Return the path to the "user" context directory for the current context. More... | |
std::string | getHomeRobotPath () |
Return the path to the "user" robot directory. More... | |
yarp::os::Bottle | findPaths (const std::string &name, const ResourceFinderOptions &options) |
std::string | findPath (const std::string &name, const ResourceFinderOptions &options) |
std::string | findFile (const std::string &name, const ResourceFinderOptions &options) |
std::string | findFileByName (const std::string &name, const ResourceFinderOptions &options) |
bool | readConfig (Property &config, const std::string &key, const ResourceFinderOptions &options) |
virtual bool | check (const std::string &key) const=0 |
Check if there exists a property of the given name. More... | |
virtual bool | check (const std::string &key, const std::string &comment) const |
Check if there exists a property of the given name. More... | |
virtual bool | check (const std::string &key, Value *&result, const std::string &comment="") const |
Gets a value corresponding to a given keyword. More... | |
virtual Value | check (const std::string &key, const Value &fallback, const std::string &comment="") const |
Gets a value corresponding to a given keyword. More... | |
virtual Bottle & | findGroup (const std::string &key) const=0 |
Gets a list corresponding to a given keyword. More... | |
Bottle & | findGroup (const std::string &key, const std::string &comment) const |
Gets a list corresponding to a given keyword. More... | |
Public Member Functions inherited from yarp::os::Searchable | |
Searchable () | |
Default constructor. More... | |
Searchable (const Searchable &rhs)=default | |
Copy constructor. More... | |
Searchable (Searchable &&rhs) noexcept=default | |
Move constructor. More... | |
virtual | ~Searchable () |
Destructor. More... | |
Searchable & | operator= (const Searchable &rhs)=default |
Copy assignment operator. More... | |
Searchable & | operator= (Searchable &&rhs) noexcept=default |
Move assignment operator. More... | |
virtual bool | check (const std::string &key, const std::string &comment) const |
Check if there exists a property of the given name. More... | |
Bottle & | findGroup (const std::string &key, const std::string &comment) const |
Gets a list corresponding to a given keyword. More... | |
virtual bool | check (const std::string &key, Value *&result, const std::string &comment="") const |
Gets a value corresponding to a given keyword. More... | |
virtual Value | check (const std::string &key, const Value &fallback, const std::string &comment="") const |
Gets a value corresponding to a given keyword. More... | |
Static Public Member Functions | |
static ResourceFinder & | getResourceFinderSingleton () |
Access a ResourceFinder singleton whose lifetime will match that of the YARP library. More... | |
static std::string | getDataHome () |
Location where user data files are stored. More... | |
static std::string | getDataHomeNoCreate () |
Variant of getDataHome that will never create the directory returned. More... | |
static std::string | getConfigHome () |
Location where user config files are stored. More... | |
static std::string | getConfigHomeNoCreate () |
Variant of getConfigHome that will never create the directory returned. More... | |
static Bottle | getDataDirs () |
Locations where packaged data and config files are stored. More... | |
static Bottle | getConfigDirs () |
Locations where system administrator data and config files are stored. More... | |
Helper class for finding config files and other external resources.
More details on this class behaviour can be found in ResourceFinder Tutorials and Specification.
Definition at line 32 of file ResourceFinder.h.
ResourceFinder::ResourceFinder | ( | ) |
Definition at line 747 of file ResourceFinder.cpp.
ResourceFinder::ResourceFinder | ( | const ResourceFinder & | alt | ) |
Definition at line 758 of file ResourceFinder.cpp.
|
virtual |
Definition at line 784 of file ResourceFinder.cpp.
|
overridevirtual |
Check if there exists a property of the given name.
key | the name to check for |
Implements yarp::os::Searchable.
Definition at line 920 of file ResourceFinder.cpp.
virtual bool yarp::os::Searchable::check |
Check if there exists a property of the given name.
key | the name to check for |
bool yarp::os::Searchable::check |
Check if there exists a property of the given name.
key | the name to check for |
comment | Human-readable explanation |
Definition at line 121 of file Searchable.cpp.
yarp::os::Value yarp::os::Searchable::check |
Gets a value corresponding to a given keyword.
key | The keyword to look for |
fallback | A default value to return if nothing found |
comment | Optional human-readable explanation |
Definition at line 198 of file Searchable.cpp.
bool yarp::os::Searchable::check |
Gets a value corresponding to a given keyword.
If a property does not exist, this returns false and does not modify the result pointer. If a property exists but does not have a value, this again returns false and does not modify the result pointer.
key | The keyword to look for |
result | A pointer to store the address of the result in |
comment | Optional human-readable explanation |
Definition at line 184 of file Searchable.cpp.
bool ResourceFinder::configure | ( | int | argc, |
char * | argv[], | ||
bool | skipFirstArgument = true |
||
) |
Sets up the ResourceFinder.
Definition at line 803 of file ResourceFinder.cpp.
|
overridevirtual |
Gets a value corresponding to a given keyword.
key | The keyword to look for |
Implements yarp::os::Searchable.
Definition at line 926 of file ResourceFinder.cpp.
std::string ResourceFinder::findFile | ( | const std::string & | name | ) |
Find the full path to a file.
The file is specified by the name of a key. The value of the key should be set up either on the command line, through a loaded config file, or by a call to setDefault.
If all else fails, findFile will try interpreting key as a file name - this is for backwards compatibility and is behavior that will probably go away - don't depend on it!
The file is searched in a hierarchy of paths as defined in ResourceFinder Tutorials and Specification.
Definition at line 847 of file ResourceFinder.cpp.
std::string ResourceFinder::findFile | ( | const std::string & | name, |
const ResourceFinderOptions & | options | ||
) |
Definition at line 853 of file ResourceFinder.cpp.
std::string ResourceFinder::findFileByName | ( | const std::string & | name | ) |
Find the full path to a file.
The name of the file is provided explicitly.
The file is searched in a hierarchy of paths as defined in ResourceFinder Tutorials and Specification.
Definition at line 860 of file ResourceFinder.cpp.
std::string ResourceFinder::findFileByName | ( | const std::string & | name, |
const ResourceFinderOptions & | options | ||
) |
Definition at line 866 of file ResourceFinder.cpp.
|
overridevirtual |
Gets a list corresponding to a given keyword.
key | The keyword to look for |
Implements yarp::os::Searchable.
Definition at line 932 of file ResourceFinder.cpp.
virtual Bottle& yarp::os::Searchable::findGroup |
Gets a list corresponding to a given keyword.
key | The keyword to look for |
yarp::os::Bottle & yarp::os::Searchable::findGroup |
Gets a list corresponding to a given keyword.
key | The keyword to look for |
comment | Human-readable explanation |
Definition at line 157 of file Searchable.cpp.
|
virtual |
Gets a section as a ResourceFinder object, retaining the context and configuration of the current ResourceFinder.
This is a thin wrapper around the Searchable::findGroup method.
key | The section to look for |
Definition at line 970 of file ResourceFinder.cpp.
std::string ResourceFinder::findPath | ( | ) |
Find the first existing directory in the search path.
Definition at line 900 of file ResourceFinder.cpp.
std::string ResourceFinder::findPath | ( | const std::string & | name | ) |
Expand a partial path to a full path.
The path is specified by the name of a key. The value of the key should be set up either on the command line, through a loaded config file, or by a call to setDefault.
If all else fails, findPath will try interpreting key as a path - this is for backwards compatibility and is behavior that will probably go away - don't depend on it!
The path is searched in a hierarchy of paths as defined in ResourceFinder Tutorials and Specification.
Definition at line 874 of file ResourceFinder.cpp.
std::string ResourceFinder::findPath | ( | const std::string & | name, |
const ResourceFinderOptions & | options | ||
) |
Definition at line 880 of file ResourceFinder.cpp.
yarp::os::Bottle ResourceFinder::findPaths | ( | const std::string & | name | ) |
Expand a partial path to a list of paths.
Like findPath(key), but continues on to find all instances of the path.
so findPaths("app") would return ["/foo/app", "/bar/app", ...] depending on the search path in effect. The first path is the list comes from the highest-priority location, and would be the path returned by findPath("app")
The path is searched in a hierarchy of paths as defined in ResourceFinder Tutorials and Specification.
Definition at line 887 of file ResourceFinder.cpp.
yarp::os::Bottle ResourceFinder::findPaths | ( | const std::string & | name, |
const ResourceFinderOptions & | options | ||
) |
Definition at line 893 of file ResourceFinder.cpp.
|
static |
Locations where system administrator data and config files are stored.
If $YARP_CONFIG_DIRS is set, that is returned. Otherwise: If $XDG_CONFIG_DIRS is set, "/yarp" or "\yarp" as appropriate is appended to each path and the result returned. Otherwise: On Windows ALLUSERSPROFILE%\yarp On Linux and all others: /etc/yarp is returned. (an OSX-specific case remains to be defined)
Definition at line 1105 of file ResourceFinder.cpp.
|
inlinestatic |
Location where user config files are stored.
If $YARP_CONFIG_HOME is set, that is returned. Otherwise: If $XDG_CONFIG_HOME is set, "yarp" is appended to it after the OS-appropriate directory separator, and the result returned. Otherwise: On Windows APPDATA%\yarp\config is returned. On Linux and all others: $HOME/.config/yarp is returned. (an OSX-specific case remains to be defined)
Definition at line 314 of file ResourceFinder.h.
|
inlinestatic |
Variant of getConfigHome that will never create the directory returned.
Definition at line 325 of file ResourceFinder.h.
std::string ResourceFinder::getContext | ( | ) |
Return the default "context" or "application name" used in searching for configuration files.
The context is a keyword that is converted into a search path in a policy-specific way.
Definition at line 949 of file ResourceFinder.cpp.
Bottle ResourceFinder::getContexts | ( | ) |
Return the full stack of contexts used in searching for configuration files.
Definition at line 964 of file ResourceFinder.cpp.
|
static |
Locations where packaged data and config files are stored.
If $YARP_DATA_DIRS is set, that is returned. Otherwise: If $XDG_DATA_DIRS is set, "/yarp" or "\yarp" as appropriate is appended to each path and the result returned. Otherwise: On Windows YARP_DIR%\share\yarp On Linux and all others: /usr/local/share/yarp:/usr/share/yarp is returned. (an OSX-specific case remains to be defined)
Definition at line 1073 of file ResourceFinder.cpp.
|
inlinestatic |
Location where user data files are stored.
If $YARP_DATA_HOME is set, that is returned. We do not check to see if that directory exists. Otherwise: (In all the following cases, we attempt to create the directory returned if it does not already exist). If $XDG_DATA_HOME is set, "yarp" is appended to it after the OS-appropriate directory separator, and the result returned. Otherwise: On Windows APPDATA%\yarp is returned. On Linux and all others: $HOME/.local/share is returned. (an OSX-specific case remains to be defined)
Definition at line 282 of file ResourceFinder.h.
|
inlinestatic |
Variant of getDataHome that will never create the directory returned.
Definition at line 294 of file ResourceFinder.h.
std::string ResourceFinder::getHomeContextPath | ( | ) |
Return the path to the "user" context directory for the current context.
Definition at line 954 of file ResourceFinder.cpp.
std::string ResourceFinder::getHomeRobotPath | ( | ) |
Return the path to the "user" robot directory.
Definition at line 959 of file ResourceFinder.cpp.
|
static |
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
Definition at line 976 of file ResourceFinder.cpp.
|
inline |
Definition at line 243 of file ResourceFinder.h.
|
overridevirtual |
Checks if the object is invalid.
Reimplemented from yarp::os::Searchable.
Definition at line 938 of file ResourceFinder.cpp.
const ResourceFinder & ResourceFinder::operator= | ( | const ResourceFinder & | alt | ) |
Definition at line 791 of file ResourceFinder.cpp.
bool ResourceFinder::readConfig | ( | Property & | config, |
const std::string & | key, | ||
const ResourceFinderOptions & | options | ||
) |
Definition at line 1138 of file ResourceFinder.cpp.
bool ResourceFinder::setDefault | ( | const std::string & | key, |
const std::string & | val | ||
) |
Provide a default value for a given key.
The provided val
will be converted to a yarp::os::Value, so also string representations for lists and numerical values are accepted.
Definition at line 825 of file ResourceFinder.cpp.
bool ResourceFinder::setDefault | ( | const std::string & | key, |
const yarp::os::Value & | val | ||
) |
Provide a default value for a given key.
Definition at line 842 of file ResourceFinder.cpp.
bool ResourceFinder::setDefault | ( | const std::string & | key, |
std::int32_t | val | ||
) |
Provide a default value for a given key.
The provided val
will be converted to a 32-bit integer yarp::os::Value.
Definition at line 832 of file ResourceFinder.cpp.
bool ResourceFinder::setDefault | ( | const std::string & | key, |
yarp::conf::float64_t | val | ||
) |
Provide a default value for a given key.
The provided val
will be converted to a 64-bit floating point yarp::os::Value.
Definition at line 837 of file ResourceFinder.cpp.
|
inline |
Provide a default value for the configuration file (can be overridden from command line with the –from argument)
Definition at line 134 of file ResourceFinder.h.
|
inline |
Sets the context for the current ResourceFinder object.
contextName | The name of the context |
Definition at line 91 of file ResourceFinder.h.
bool ResourceFinder::setQuiet | ( | bool | quiet = true | ) |
Request that information be suppressed from the console.
By default ResourceFinder will print messages if it fails to find files, for example.
quiet | suppress printing of information |
Definition at line 913 of file ResourceFinder.cpp.
bool ResourceFinder::setVerbose | ( | bool | verbose = true | ) |
Request that information be printed to the console on how resources are being found.
This is especially useful to understand why resources are not found or the wrong resource is picked up.
verbose | set/suppress printing of information |
Definition at line 907 of file ResourceFinder.cpp.
|
overridevirtual |
Return a standard text representation of the content of the object.
The representation is readable by the Bottle and Property classes.
Implements yarp::os::Searchable.
Definition at line 944 of file ResourceFinder.cpp.