Source-highlight Library
srchilite::Settings Class Reference

Handles the settings for source-highlight (and its library). More...

#include <settings.h>

Collaboration diagram for srchilite::Settings:

List of all members.

Public Member Functions

const std::string getConfDir () const
void setConfDir (const std::string &dir)
const std::string getConfFileName () const
const std::string getTestFileName () const
void setTestFileName (const std::string &name)
const std::string getDataDir () const
void setDataDir (const std::string &ddir)
bool checkForConfFile ()
 Checks whether the conf file exists.
bool checkForTestFile ()
 Checks whether the test file is in the datadir.
bool readDataDir ()
 Reads the datadir from the configuration file.
SettingError save ()
 Saves the setting (for datadir) in the conf file.

Static Public Member Functions

static const std::string retrieveDataDir (bool reload=false)
 Retrieves the value for the data dir.
static const std::string getDefaultDataDir ()
static void setGlobalDataDir (const std::string &dataDir)
 Sets the global data dir value.
static bool checkSettings ()
 Checks whether the current retrieved data dir is a valid data dir value for source-highlight.

Private Attributes

std::string homeDir
 the home directory of the user
std::string confDir
 the directory for configuration file (default: $HOME/.source-highlight/)
std::string confFileName
 the name of the configuration file (default: source-highlight.conf)
std::string testFileName
 test file to search for in the datadir (default: lang.map)
std::string dataDir
 the data dir (used for .lang, .outlang, lang.map, etc), this is read from the configuration file

Detailed Description

Handles the settings for source-highlight (and its library).

At the moment the only setting that is stored is the value for datadir (command line option --data-dir), that specifies whether source-highlight should search for .lang, .outlang, .map and other files.

A default value for this datadir is hardcoded, based on the configure --prefix option: prefix/share/source-highlight (where prefix is the one specified at configure, and it defaults to /usr/local).

When an object of this class is created, it will get the value of the environment variable $HOME.

The method checkForConfFile() should be used to check whether configuration exists at all.

The method readDataDir() can be used to retrieve the datadir value from the configuration file. If it returns false it can be assumed that no configuration file was found.

The method checkForTestFile() should be used to make sure that datadir contains the files needed by source-highlight. If it returns false it can be assumed that that directory is not correct (that directory may not exist at all).

The new value for datadir can be set with method setDataDir().

The method save() will save the current value of datadir in the configuration file (it also creates the directory if it does not exist).

This class also provides a static method retrieveDataDir() which uses an object of this class to retrieve datadir (if the environment variable SOURCE_HIGHLIGHT_DATADIR is not set). If also the reading of configuration file fails, then it returns the hardcoded value.

Thus, the users of the library should always rely on this static method for retrieving the datadir value. The other methods of this class should be used when (possibly) configuring the library from within the program itself. For instance this is done by the program source-highlight-settings.

An alternative use, is to set a global data dir value with setGlobalDataDir(); this way, retrieveDataDir() will always return the global value (this enforces consistency in a library using the source-highlight library).


Member Function Documentation

Checks whether the conf file exists.

Returns:
true if the conf file exists

Checks whether the test file is in the datadir.

Returns:
true if the test file is in the datadir

Checks whether the current retrieved data dir is a valid data dir value for source-highlight.

Returns:
whether the current retrieved data dir is a valid data dir value for source-highlight.
const std::string srchilite::Settings::getDefaultDataDir ( ) [static]
Returns:
the hardcoded datadir value

Reads the datadir from the configuration file.

Returns:
true if the datadir was specified in the configuration file
const string srchilite::Settings::retrieveDataDir ( bool  reload = false) [static]

Retrieves the value for the data dir.

If the global value was set with setGlobalDataDir() then always returns this global value. It returns the value of the environment variable SOURCE_HIGHLIGHT_DATADIR if set. Otherwise, it returns the value read from the configuration file.

Thus, the users of the library should always rely on this static method for retrieving the datadir value.

If also the reading of configuration file fails, then it returns the hardcoded value.

If the global data dir was set (and it's not empty) with setGlobalDataDir, then this method will always return the global value, without inspecting the environment variable nor the configuration file.

Parameters:
reloadwhether to perform the retrieval from scratch (otherwise it is cached)
Returns:
the value for datadir

Saves the setting (for datadir) in the conf file.

Returns:
a possible error in case saving (or creating directory) fails
void srchilite::Settings::setGlobalDataDir ( const std::string &  dataDir) [static]

Sets the global data dir value.

If the passed value is not empty, then retrieveDataDir() will always return this value (and it won't read the configuration file).

Parameters:
dataDir

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