srchilite::Settings Class Reference

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

#include <settings.h>

Collaboration diagram for srchilite::Settings:
[legend]

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)
 Uses an object of this class to retrieve datadir only if the environment variable SOURCE_HIGHLIGHT_DATADIR is not set.

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 only 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.


Member Function Documentation

bool srchilite::Settings::checkForConfFile (  ) 

Checks whether the conf file exists.

Returns:
true if the conf file exists

bool srchilite::Settings::checkForTestFile (  ) 

Checks whether the test file is in the datadir.

Returns:
true if the test file is in the datadir

bool srchilite::Settings::readDataDir (  ) 

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]

Uses an object of this class to retrieve datadir only if the environment variable SOURCE_HIGHLIGHT_DATADIR is not set.

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.

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

SettingError srchilite::Settings::save (  ) 

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

Returns:
a possible error in case saving (or creating directory) fails


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

Generated on Sun Jun 14 18:23:26 2009 for Source-highlight Library by  doxygen 1.5.9