OpenWalnut  1.4.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
WPathHelper Class Reference

Singleton class helping to find files and paths. More...

#include <WPathHelper.h>

List of all members.

Classes

struct  Fonts
 Paths to all known fonts. More...

Public Member Functions

virtual ~WPathHelper ()
 Destructor.
void setBasePaths (boost::filesystem::path appPath, boost::filesystem::path homePath)
 Set the current application path.
void setBasePathsOSXBundle (boost::filesystem::path appPath, boost::filesystem::path homePath)
 Set the current application path.
void addAdditionalModulePath (const boost::filesystem::path &path)
 This method adds the given path to the list of module paths.
const std::vector
< boost::filesystem::path > & 
getAdditionalModulePaths () const
 Returns the list of paths added using addAdditionalModulePath.

Static Public Member Functions

static boost::shared_ptr
< WPathHelper
getPathHelper ()
 Returns instance of the path helper.
static boost::filesystem::path getAppPath ()
 The path where the binary file resides in.
static boost::filesystem::path getFontPath ()
 The path where font files reside in.
static Fonts getAllFonts ()
 The paths to all fonts supported.
static boost::filesystem::path getShaderPath ()
 The path to the global shaders.
static boost::filesystem::path getModulePath ()
 The path to the globally installed modules.
static boost::filesystem::path getHomePath ()
 The path to the OW dir in the user's home.
static std::vector
< boost::filesystem::path > 
getAllModulePaths ()
 This returns a list of search paths for modules.
static boost::filesystem::path getLibPath ()
 The path to the OW libs.
static boost::filesystem::path getSharePath ()
 The path where shared files reside in.
static boost::filesystem::path getDocPath ()
 The path where the doc files reside in.
static boost::filesystem::path getConfigPath ()
 The path where the config files reside in.
static boost::filesystem::path getModuleResourcePath (boost::filesystem::path moduleLibPath, std::string packageName)
 The path to a given module's resources.

Protected Member Functions

 WPathHelper ()
 Constructors are protected because this is a Singleton.

Private Attributes

boost::filesystem::path m_appPath
 Application path.
boost::filesystem::path m_sharePath
 The path where all the shared files reside in.
boost::filesystem::path m_docPath
 The path where all the documentation files reside in.
boost::filesystem::path m_configPath
 The path where all the config files reside in.
boost::filesystem::path m_modulePath
 The path to the globally installed modules.
boost::filesystem::path m_libPath
 The path to the OW libs.
boost::filesystem::path m_homePath
 The path of a user specific OW directory.
boost::filesystem::path m_moduleResourcePathRelative
 The path to module resources, relative to the module libraries path.
std::vector
< boost::filesystem::path > 
m_additionalModulePaths
 A list of additional paths to search for modules.

Static Private Attributes

static boost::shared_ptr
< WPathHelper
m_instance = boost::shared_ptr< WPathHelper >()
 Singleton instance of WPathHelper.

Detailed Description

Singleton class helping to find files and paths.

It is a useful to to search for resources and the central place to "hardcode" relative paths. It contains global paths only. Modules have their OWN local paths.

Definition at line 38 of file WPathHelper.h.


Constructor & Destructor Documentation

Destructor.

Definition at line 42 of file WPathHelper.cpp.

WPathHelper::WPathHelper ( ) [protected]

Constructors are protected because this is a Singleton.

Definition at line 37 of file WPathHelper.cpp.

Referenced by getPathHelper().


Member Function Documentation

void WPathHelper::addAdditionalModulePath ( const boost::filesystem::path &  path)

This method adds the given path to the list of module paths.

This way, arbitrary paths can be specified to search for modules. Each path is searched recursively.

Parameters:
paththe path to add.

Definition at line 188 of file WPathHelper.cpp.

References m_additionalModulePaths.

const std::vector< boost::filesystem::path > & WPathHelper::getAdditionalModulePaths ( ) const

Returns the list of paths added using addAdditionalModulePath.

This does NOT contain the paths in OW_MODULE_PATH. Use getAllModulePaths for this.

Returns:
the list of additional paths

Definition at line 196 of file WPathHelper.cpp.

References m_additionalModulePaths.

The paths to all fonts supported.

Returns:
the file paths to all fonts

Definition at line 104 of file WPathHelper.cpp.

References WPathHelper::Fonts::Bold, WPathHelper::Fonts::Default, getFontPath(), WPathHelper::Fonts::Italic, and WPathHelper::Fonts::Regular.

Referenced by wge::addLabel(), WGELabel::WGELabel(), and WGETextureHud::WGETextureHudEntry::WGETextureHudEntry().

std::vector< boost::filesystem::path > WPathHelper::getAllModulePaths ( ) [static]

This returns a list of search paths for modules.

This list is defined by the environment variable "OW_MODULE_PATH" and the list of additional module paths. All of these directories CAN contain modules. On startup, they get searched in the specified order.

Returns:
list of search paths for modules

Definition at line 154 of file WPathHelper.cpp.

References getHomePath(), getModulePath(), getPathHelper(), and m_additionalModulePaths.

Referenced by WModuleLoader::load().

boost::filesystem::path WPathHelper::getAppPath ( ) [static]

The path where the binary file resides in.

This is for example /usr/bin.

Returns:
the application path.

Definition at line 89 of file WPathHelper.cpp.

References getPathHelper().

boost::filesystem::path WPathHelper::getConfigPath ( ) [static]

The path where the config files reside in.

Returns:
the config file path.

Definition at line 140 of file WPathHelper.cpp.

References getPathHelper().

boost::filesystem::path WPathHelper::getDocPath ( ) [static]

The path where the doc files reside in.

Returns:
the doc file path.

Definition at line 135 of file WPathHelper.cpp.

References getPathHelper().

boost::filesystem::path WPathHelper::getFontPath ( ) [static]

The path where font files reside in.

Returns:
the font path.

Definition at line 94 of file WPathHelper.cpp.

References getPathHelper().

Referenced by getAllFonts().

boost::filesystem::path WPathHelper::getHomePath ( ) [static]

The path to the OW dir in the user's home.

This will not be the home dir directly. It is something like $HOME/.OpenWalnut.

Returns:
OW home path

Definition at line 120 of file WPathHelper.cpp.

References getPathHelper().

Referenced by getAllModulePaths().

boost::filesystem::path WPathHelper::getLibPath ( ) [static]

The path to the OW libs.

You normally should not need this.

Returns:
the path to the libs.

Definition at line 125 of file WPathHelper.cpp.

References getPathHelper().

boost::filesystem::path WPathHelper::getModulePath ( ) [static]

The path to the globally installed modules.

This does not respect any environment variables or config options! Use this only to search global modules. To get a list of all module search paths, including user defined ones, use getAllModulePaths().

Returns:
path to globally installed modules.

Definition at line 115 of file WPathHelper.cpp.

References getPathHelper().

Referenced by getAllModulePaths().

boost::filesystem::path WPathHelper::getModuleResourcePath ( boost::filesystem::path  moduleLibPath,
std::string  packageName 
) [static]

The path to a given module's resources.

This should be used to get a share-like path for the module. The path is relative to the module's library path. This method is most useful for the module loader. You should not query your own resource path with this function. Use your module instance's m_localPath.

Parameters:
moduleLibPaththe path to the lib. Can be relative or absolute. This must be the directory the lib contains and NOT the path to the lib itself
packageNamethe name of the resource. This is usually the package name.
Returns:
the absolute path for the given module path.

Definition at line 145 of file WPathHelper.cpp.

References getPathHelper().

Referenced by WModuleLoader::load().

boost::shared_ptr< WPathHelper > WPathHelper::getPathHelper ( ) [static]

Returns instance of the path helper.

If it does not exists, it will be created.

Returns:
the running path helper instance.

Definition at line 47 of file WPathHelper.cpp.

References m_instance, and WPathHelper().

Referenced by getAllModulePaths(), getAppPath(), getConfigPath(), getDocPath(), getFontPath(), getHomePath(), getLibPath(), getModulePath(), getModuleResourcePath(), getShaderPath(), and getSharePath().

boost::filesystem::path WPathHelper::getShaderPath ( ) [static]

The path to the global shaders.

Modules usually have their own local shader directory.

Returns:
global shader path.

Definition at line 99 of file WPathHelper.cpp.

References getPathHelper().

Referenced by WGEShader::processShaderRecursive().

boost::filesystem::path WPathHelper::getSharePath ( ) [static]

The path where shared files reside in.

Returns:
the shared files path.

Definition at line 130 of file WPathHelper.cpp.

References getPathHelper().

Referenced by WGEViewerEffectImageOverlay::WGEViewerEffectImageOverlay().

void WPathHelper::setBasePaths ( boost::filesystem::path  appPath,
boost::filesystem::path  homePath 
)

Set the current application path.

This should be called only once. The home path hereby is NOT the users home. It is a directory, where OW can write user specific data. A good default here is to specify USERHOME/.OpenWalnut for example.

Parameters:
appPaththe application path
homePaththe OW home path

Definition at line 57 of file WPathHelper.cpp.

References m_appPath, m_configPath, m_docPath, m_homePath, m_libPath, m_modulePath, m_moduleResourcePathRelative, and m_sharePath.

void WPathHelper::setBasePathsOSXBundle ( boost::filesystem::path  appPath,
boost::filesystem::path  homePath 
)

Set the current application path.

This should be called only once. The home path hereby is NOT the users home. It is a directory, where OW can write user specific data. A good default here is to specify USERHOME/.OpenWalnut for example.

Parameters:
appPaththe application path
homePaththe OW home path

Definition at line 73 of file WPathHelper.cpp.

References m_appPath, m_configPath, m_docPath, m_homePath, m_libPath, m_modulePath, m_moduleResourcePathRelative, and m_sharePath.


Member Data Documentation

std::vector< boost::filesystem::path > WPathHelper::m_additionalModulePaths [private]

A list of additional paths to search for modules.

This does not contain the paths in the environment variable OW_MODULE_PATH. This method is not thread-safe. You should only use it before the module factory loads the modules.

Definition at line 259 of file WPathHelper.h.

Referenced by addAdditionalModulePath(), getAdditionalModulePaths(), and getAllModulePaths().

boost::filesystem::path WPathHelper::m_appPath [private]

Application path.

NOT the path of the binary. The application path is the directory in which the binary is placed. The binary path is m_appPath+"/openwalnut".

Definition at line 218 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_configPath [private]

The path where all the config files reside in.

Definition at line 233 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_docPath [private]

The path where all the documentation files reside in.

Definition at line 228 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_homePath [private]

The path of a user specific OW directory.

Definition at line 248 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::shared_ptr< WPathHelper > WPathHelper::m_instance = boost::shared_ptr< WPathHelper >() [static, private]

Singleton instance of WPathHelper.

Definition at line 264 of file WPathHelper.h.

Referenced by getPathHelper().

boost::filesystem::path WPathHelper::m_libPath [private]

The path to the OW libs.

Definition at line 243 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_modulePath [private]

The path to the globally installed modules.

Definition at line 238 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_moduleResourcePathRelative [private]

The path to module resources, relative to the module libraries path.

Definition at line 253 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().

boost::filesystem::path WPathHelper::m_sharePath [private]

The path where all the shared files reside in.

Definition at line 223 of file WPathHelper.h.

Referenced by setBasePaths(), and setBasePathsOSXBundle().


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