ug4
ug::PathProvider Class Reference

Singleton which stores common paths and a stack of current paths. More...

#include <path_provider.h>

Static Public Member Functions

static void clear_current_path_stack ()
 clears the stack of current paths. This makes sense if an error was catched. More...
 
static const std::string & get_current_path (PathTypes defPath=BIN_PATH)
 returns the current path More...
 
static bool get_dirname_relative_to_current_path (const std::string &relativeDirname, std::string &absoluteDirname)
 
static bool get_dirname_relative_to_path (PathTypes pathType, const std::string &relativeDirname, std::string &absoluteDirname)
 
static bool get_filename_relative_to_current_path (const std::string &relativeFilename, std::string &absoluteFilename)
 
static bool get_filename_relative_to_path (PathTypes pathType, const std::string &relativeFilename, std::string &absoluteFilename)
 
static const std::string & get_path (PathTypes pathType)
 returns the path associated with the given constant. More...
 
static bool has_current_path ()
 returns true if a current path exists, false if not. More...
 
static bool has_path (PathTypes pathType)
 returns true, if the path associated with the given constant exists. More...
 
static void pop_current_path ()
 pops a path from the stack of current paths More...
 
static void push_current_path (const std::string &path)
 pushes a path to the stack of current paths More...
 
static void set_path (PathTypes pathType, const std::string &path)
 sets the path for the given constant. More...
 

Private Member Functions

 PathProvider ()
 
 PathProvider (const PathProvider &)
 

Static Private Member Functions

static PathProviderinst ()
 

Private Attributes

std::stack< std::string > m_curPaths
 
std::map< PathTypes, std::string > m_map
 

Detailed Description

Singleton which stores common paths and a stack of current paths.

All paths are initially set to "".

Note that all public methods of PathProvider are static. That means you have to call them through the :: operator. E.g.

std::string appPath = PathProvider::get_path(BIN_PATH);
static const std::string & get_path(PathTypes pathType)
returns the path associated with the given constant.
Definition: path_provider.h:93
@ BIN_PATH
path in which the binary lies
Definition: path_provider.h:54

Constructor & Destructor Documentation

◆ PathProvider() [1/2]

ug::PathProvider::PathProvider ( )
inlineprivate

◆ PathProvider() [2/2]

ug::PathProvider::PathProvider ( const PathProvider )
inlineprivate

Member Function Documentation

◆ clear_current_path_stack()

static void ug::PathProvider::clear_current_path_stack ( )
inlinestatic

clears the stack of current paths. This makes sense if an error was catched.

References has_current_path(), and pop_current_path().

◆ get_current_path()

static const std::string& ug::PathProvider::get_current_path ( PathTypes  defPath = BIN_PATH)
inlinestatic

returns the current path

current paths are stored in a stack. The top of the stack is considered to be the most current path and is returned by this method.

Parameters
defPath(optional) If the stack is empty, the path associated with defPath is returned. By default defPath is set to BIN_PATH.

References get_path(), inst(), and m_curPaths.

Referenced by get_dirname_relative_to_current_path(), and get_filename_relative_to_current_path().

◆ get_dirname_relative_to_current_path()

static bool ug::PathProvider::get_dirname_relative_to_current_path ( const std::string &  relativeDirname,
std::string &  absoluteDirname 
)
inlinestatic
Parameters
relativeDirname(in) relative directory name
absoluteDirname(out) absolute directory name
Returns
true if directory exists relative to current path

References ug::DirectoryExists(), get_current_path(), ug::GetPathSeparator(), has_current_path(), and inst().

◆ get_dirname_relative_to_path()

static bool ug::PathProvider::get_dirname_relative_to_path ( PathTypes  pathType,
const std::string &  relativeDirname,
std::string &  absoluteDirname 
)
inlinestatic
Parameters
relativeDirname(in) relative directory name
absoluteDirname(out) absolute directory name
Returns
true if directory exists relative to current path

References ug::DirectoryExists(), get_path(), ug::GetPathSeparator(), has_path(), and inst().

◆ get_filename_relative_to_current_path()

static bool ug::PathProvider::get_filename_relative_to_current_path ( const std::string &  relativeFilename,
std::string &  absoluteFilename 
)
inlinestatic
Parameters
relativeFilename(in) relative filename
absoluteFilename(out) absolute filename
Returns
true if file exists relative to current path

References ug::FileExists(), get_current_path(), ug::GetPathSeparator(), has_current_path(), and inst().

◆ get_filename_relative_to_path()

static bool ug::PathProvider::get_filename_relative_to_path ( PathTypes  pathType,
const std::string &  relativeFilename,
std::string &  absoluteFilename 
)
inlinestatic
Parameters
relativeFilename(in) relative filename
absoluteFilename(out) absolute filename
Returns
true if file exists relative to current path

References ug::FileExists(), get_path(), ug::GetPathSeparator(), has_path(), and inst().

◆ get_path()

static const std::string& ug::PathProvider::get_path ( PathTypes  pathType)
inlinestatic

returns the path associated with the given constant.

Parameters
pathTypeshould be one of the constants enumerated in PathTypes or a used defined constant starting from MAX_PATH_CONSTANT + 1.

References inst(), and m_map.

Referenced by get_current_path(), get_dirname_relative_to_path(), get_filename_relative_to_path(), and ug::InitPaths().

◆ has_current_path()

static bool ug::PathProvider::has_current_path ( )
inlinestatic

returns true if a current path exists, false if not.

References inst(), and m_curPaths.

Referenced by clear_current_path_stack(), get_dirname_relative_to_current_path(), and get_filename_relative_to_current_path().

◆ has_path()

static bool ug::PathProvider::has_path ( PathTypes  pathType)
inlinestatic

returns true, if the path associated with the given constant exists.

Parameters
pathTypeshould be one of the constants enumerated in PathTypes or a used defined constant starting from MAX_PATH_CONSTANT + 1.

References inst(), and m_map.

Referenced by get_dirname_relative_to_path(), get_filename_relative_to_path(), and ug::InitPaths().

◆ inst()

◆ pop_current_path()

static void ug::PathProvider::pop_current_path ( )
inlinestatic

pops a path from the stack of current paths

References inst(), and m_curPaths.

Referenced by clear_current_path_stack().

◆ push_current_path()

static void ug::PathProvider::push_current_path ( const std::string &  path)
inlinestatic

pushes a path to the stack of current paths

References inst(), and m_curPaths.

◆ set_path()

static void ug::PathProvider::set_path ( PathTypes  pathType,
const std::string &  path 
)
inlinestatic

sets the path for the given constant.

Parameters
pathTypeshould be one of the constants enumerated in PathTypes or a used defined constant starting from MAX_PATH_CONSTANT + 1.

References inst(), and m_map.

Referenced by ug::InitPaths(), Java_edu_gcsc_vrl_ug_UG__1ugInit(), ug::SetAppsPath(), ug::SetPluginPath(), ug::SetRootPath(), and ug::SetScriptPath().

Member Data Documentation

◆ m_curPaths

std::stack<std::string> ug::PathProvider::m_curPaths
private

◆ m_map

std::map<PathTypes, std::string> ug::PathProvider::m_map
private

Referenced by get_path(), has_path(), and set_path().


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