GED 2006 (C++)
File detail
Source code
/*
* File: gedconf.h
* Project: GED - bitmap editor (ICP)
* Author: Jakub Filak, xfilak01
* Team: xdudka00, xfilak01, xhefka00, xhradi08
* Created: 2006-04-14
*/
#ifndef GEDCONF_H
#define GEDCONF_H
#include <map>
#include <vector>
#include <xercesc/dom/DOM.hpp>
/**
* Map used for list of plugin directories.
* Key part of pair is the directory.
* Value part of pair is the configuration file where it was found.
*/
typedef std::map<std::string, std::string> PluginDirsList;
typedef PluginDirsList::iterator PluginDirsListIterator; ///< iterator for PluginDirsList
/**
* Map used for list of macro names.
* Key part of pair is the name.
* Value part of pair is the configuration file where it was found.
*/
typedef std::map<std::string, std::string> MacroList;
/**
* Class containing command name and command data.
*/
class GedMacroCommand {
public:
/**
* Create new GedMacroCommand instance.
* \param name Name of command.
* \param param Command data.
*/
GedMacroCommand (std::string name, std::string param) {
_commandName = name;
_params = param;
};
/**
* Get command name.
* \return Command name.
*/
std::string getName () { return _commandName; }
/**
* Get command data.
* \return Text string containing command data.
*/
std::string getParam () { return _params; }
/**
* Set command name.
* \param name Command name to set.
*/
void setName ( std::string name ) { _commandName = name; }
/**
* Set command data.
* \param param Text string containing command data.
*/
void setParam ( std::string param ) { _params = param; }
/**
* Add data to existing command.
* \param param String to add.
*/
void addParam ( std::string param ) { _params += ( " " + param ); }
private:
std::string _commandName;
std::string _params;
};
/**
* Vector containing squence of commands.
*/
typedef std::vector<GedMacroCommand> CommandVector;
/**
* Map containing macros.
* Key part of pair is macro name.
* Value part of pair is sequence of commands.
*/
typedef std::map<std::string, CommandVector> MacroCommands;
/*
* Support for reading/writing configuration. Design pattern singleton.
*/
class GedConf {
public:
~GedConf ();
/**
* Access point to singleton.
* \return Return pointer to singleton.
*/
static GedConf *ptr();
/**
* Destroy singleton object. It has no effect, if object is not allocated.
*/
static void destroy();
/**
* Read configuration file incrementally.
* New nodes replace existing if redefined.
* \param pathToFile Path to config file to read.
*/
void readConfig ( const char* pathToFile );
/**
* Save configuration to config file that was opened last.
* Existing file is replaced.
*/
void saveConfig ();
/**
* Return the list of directories containing plugins.
* \return Return map of plugins, empty map if no directory was found. The key contains directory name.
*/
PluginDirsList getPluginDirs();
/**
* Add plugin directory to configuration file opened as last.
* If there wasn't any opened configuration file, 'ged.conf' is used.
* \param pathToDir Path to directory with plugins.
*/
void setPluginDir( const char* pathToDir );
/**
* Remove plugin directory from last opend configuration file.
* \param pathToDir Directory to remove.
*/
void removePluginDir( const char* pathToDir );
/**
* Return macro list, empty map if no macro was found.
* \return Return macro map. The key is name of the macro. The value is configuration file, where was macro found.
*/
MacroList getMacroList();
/**
* Return vector of commands for desired macro, empty vector if macro wasn't found.
* \param macroName Name of the macro.
* \return Return squence of commands.
*/
CommandVector getCommands( const std::string macroName );
/**
* Remove macro from configuration file. It has no effect if macro isn't from last configuration file.
* \param macroName Macro name to remove.
*/
void removeMacro( const std::string macroName );
/**
* Add macro or add command to existing macro.
* \param macroName Macro name.
* \param commandName Command name.
* \param commandParams Command data.
*/
void addMacro( const char* macroName, const char* commandName, const char* commandParams );
/**
* Return help directory. If help directory option is not found, return default help directory '../doc/help'.
* \return Help directory.
*/
std::string getHelpDir();
/**
* Return images directory. If images directory option is not found, return default help directory 'images'.
* \return Images directory.
*/
std::string getImageDir();
/**
* Return font properties.
* \param fileName File containing font.
* \param dpi Font resolution.
* \param size Base font size.
*/
void getFont( std::string &fileName, std::string &dpi, std::string &size);
protected:
/**
* Singleton can't be allocated static. use GedConf::ptr() method to obtain singleton address.
*/
GedConf():_change(false){}
private:
static GedConf *_instance;
PluginDirsList _PluginDirs; // plugin list, plugin dirs mapped with their config file
MacroList _MacroList; // list of macro names
MacroCommands _MacroCommands; // macro names with their commands
std::string _helpdir; // dir with help file
std::string _imagesDir;
std::string _fontFile;
std::string _fontDPI;
std::string _fontSize;
std::string _lastCofingFile; // last used configure file
bool _change; // true when changes some in config file
bool _PLFR; // true if is plugin record in last file
bool _MLFR; // true if is macro record in last file
bool _HLFR; // true if is help record in last file
bool _ILFR; // true if is images record in last file
bool _FLFR; // true if is font record in last file
#if XERCES_VERSION_MINOR == 7
/**
* Read and parse dirs with plugins
*/
void parsePluginDirs( xercesc_2_7::DOMNodeList* listPluginNodes );
/**
* Read and parse macros
*/
void parseMacros( xercesc_2_7::DOMNodeList* listPluginNodes );
/**
* Read and parse nodes wiht one attribute
*/
void parseNodeWithOneAttribute( xercesc_2_7::DOMNode* Node, const char* nName, std::string &Store, bool* recor);
/**
* Read and parse fonts property
*/
void parseFont( xercesc_2_7::DOMNode* fontNode );
/**
* Read and parse macro commands from config file
*/
CommandVector parseMacroCommands( xercesc_2_7::DOMNodeList* listPluginNodes );
/**
* Create command vector
*/
void createCommandTree( xercesc_2_7::DOMNode* macroNode, std::string macroName );
#endif
#if XERCES_VERSION_MINOR == 6
/**
* Read and parse dirs with plugins
*/
void parsePluginDirs( xercesc_2_6::DOMNodeList* listPluginNodes );
/**
* Read and parse macros
*/
void parseMacros( xercesc_2_6::DOMNodeList* listPluginNodes );
/**
* Read and parse nodes wiht one attribute
*/
void parseNodeWithOneAttribute( xercesc_2_6::DOMNode* Node, const char* nName, std::string &Store, bool* recor);
/**
* Read and parse fonts property
*/
void parseFont( xercesc_2_6::DOMNode* fontNode );
/**
* Read and parse macro commands from config file
*/
CommandVector parseMacroCommands( xercesc_2_6::DOMNodeList* listPluginNodes );
/**
* Create command vector
*/
void createCommandTree( xercesc_2_6::DOMNode* macroNode, std::string macroName );
#endif
};
#endif