Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OPreferenceManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 /*
17  *
18  *
19  *
20  *
21  */
22 #ifdef _MSC_VER
23  #pragma warning(disable : 4503)
24  #pragma warning(disable : 4786)
25 #endif
26 
27 #ifndef __O_PREFERENCE_MANAGER__
28  #define __O_PREFERENCE_MANAGER__
29 
30  #include "Tympan/core/defines.h"
31  #include <map>
32  #include <QString>
33 
38 // typedef std::map<QString, QString> OPrefMap;
39 struct OPrefMap
40 {
41  typedef std::map<QString, QString>::iterator OPrefMapIt;
42  std::map<QString, QString> _prefMap;
43 };
44 
49 // typedef std::map<QString, OPrefMap> ODirMap;
50 struct ODirMap
51 {
52  typedef std::map<QString, OPrefMap>::iterator ODirMapIt;
53  std::map<QString, OPrefMap> _dirMap;
54 };
55 
83 {
84 public:
92  OPreferenceManager(const QString& currentDirectory);
96  OPreferenceManager(const QString& rootNodeName, const QString& paramNodeName);
100  OPreferenceManager(const QString& rootNodeName, const QString& paramNodeName,
101  const QString& currentDirectory);
105  virtual ~OPreferenceManager();
106 
113  void loadDefault(const char* defaultParams[][2], int nbParams);
114 
118  void reset();
119 
125  void setXMLRootNodeName(QString name)
126  {
128  }
129 
135  void setXMLParamNodeName(QString name)
136  {
138  }
139 
147  bool readXML(QString fileName);
148 
156  bool writeXML(QString fileName);
157 
166  bool exists(const QString& pref);
167 
177  bool exists(const QString& dir, const QString& pref);
178 
187  QString getDirectory(const QString& pref);
188 
194  void setCurrentDirectory(QString dir);
201  {
202  return _curDir;
203  }
204 
215  void setString(const QString& pref, const QString& value);
216 
228  void setString(const QString& dir, const QString& pref, const QString& value);
229 
237  QString getString(const QString& pref);
238 
247  QString getString(const QString& dir, const QString& pref);
248 
260  void setStringArray(const QString& pref, const QString* valueArray, const int& sizeArray);
261 
274  void setStringArray(const QString& dir, const QString& pref, const QString* valueArray,
275  const int& sizeArray);
276 
286  QString* getStringArray(const QString& pref, int& sizeArray);
287 
298  QString* getStringArray(const QString& dir, const QString& pref, int& sizeArray);
299 
300  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
310  void setUInt(const QString& pref, const unsigned int& value);
321  void setUInt(const QString& dir, const QString& pref, const unsigned int& value);
322 
332  void setUInt(const QString& pref, const size_t& value);
343  void setUInt(const QString& dir, const QString& pref, const size_t& value);
344 
345  #if TY_COMPILER == TY_COMPILER_MSVC
355  void setUInt(const QString& pref, const unsigned long& value);
366  void setUInt(const QString& dir, const QString& pref, const unsigned long& value);
367  #endif
368  #else
379  void setUInt(const QString& pref, const size_t& value);
380 
393  void setUInt(const QString& dir, const QString& pref, const size_t& value);
394 
405  void setUInt(const QString& pref, const unsigned long& value);
406 
419  void setUInt(const QString& dir, const QString& pref, const unsigned long& value);
420 
421  #endif
432  void setInt(const QString& pref, const int& value);
433 
445  void setInt(const QString& dir, const QString& pref, const int& value);
446 
454  int getInt(const QString& pref);
455 
466  int getInt(const QString& dir, const QString& pref);
467 
478  void setBool(const QString& pref, const bool& value);
489  void setBool(const QString& dir, const QString& pref, const bool& value);
490 
498  bool getBool(const QString& pref);
499 
508  bool getBool(const QString& dir, const QString& pref);
509 
520  void setFloat(const QString& pref, const float& value);
521 
532  void setFloat(const QString& dir, const QString& pref, const float& value);
533 
541  float getFloat(const QString& pref);
542 
551  float getFloat(const QString& dir, const QString& pref);
552 
563  void setDouble(const QString& pref, const double& value);
564 
575  void setDouble(const QString& dir, const QString& pref, const double& value);
576 
584  double getDouble(const QString& pref);
593  double getDouble(const QString& dir, const QString& pref);
594 
608  void setFrame(const QString& pref, const int& posX, const int& posY, const int& sizeX, const int& sizeY);
609 
624  void setFrame(const QString& dir, const QString& pref, const int& posX, const int& posY, const int& sizeX,
625  const int& sizeY);
626 
636  void getFrame(const QString& pref, int& posX, int& posY, int& sizeX, int& sizeY);
637 
648  void getFrame(const QString& dir, const QString& pref, int& posX, int& posY, int& sizeX, int& sizeY);
649 
661  void setPoint(const QString& pref, const int& x, const int& y);
662 
674  void setPoint(const QString& dir, const QString& pref, const int& x, const int& y);
675 
683  void getPoint(const QString& pref, int& x, int& y);
684 
693  void getPoint(const QString& dir, const QString& pref, int& x, int& y);
694 
706  void setColor(const QString& pref, const float& r, const float& g, const float& b);
707 
720  void setColor(const QString& dir, const QString& pref, const float& r, const float& g, const float& b);
721 
730  void getColor(const QString& pref, float& r, float& g, float& b);
731 
741  void getColor(const QString& dir, const QString& pref, float& r, float& g, float& b);
742 
743  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
748  static QString uintToString(const unsigned int& val);
749 
754  static QString uintToString(const size_t& val);
755  #if TY_COMPILER == TY_COMPILER_MSVC
760  static QString uintToString(const unsigned long& val);
761  #endif
762  #else
767  static QString uintToString(const size_t& val);
768 
773  static QString uintToString(const unsigned long& val);
774  #endif
775 
780  static QString intToString(const int& val);
781 
786  static QString floatToString(const float& val);
787 
792  static QString doubleToString(const double& val);
793 
798  {
800  }
801 
802 protected:
805 
807  QString _curDir;
808 
813 
814 private:
816 };
817 
818 #endif // __O_PREFERENCE_MANAGER__
const char * name
Systeme de gestion des preferences.
QString _xmlParamNodeName
Nom des noeuds des parametres du fichier XML.
void loadDefault(const char *defaultParams[][2], int nbParams)
Charge le tableau associatif preference/valeur avec les valeurs par defaut.
void getColor(const QString &pref, float &r, float &g, float &b)
Charge les composantes RGB d'une couleur, en float.Utilise la categorie courante.
void setDouble(const QString &pref, const double &value)
Met a jour la valeur associee a une preference.
QString getCurrentDirectory()
Retourne la categorie courante pour la lecture et l'ecriture de parametres.
ODirMap _prefDirs
Tableau associatif parametre/valeur.
static QString doubleToString(const double &val)
QString getDirectory(const QString &pref)
Recherche le nom de la categorie pour une preference donnee.
void setBool(const QString &pref, const bool &value)
Met a jour la valeur associee a une preference. Si la preference n'existe pas, celle-ci est ajoutee a...
static QString floatToString(const float &val)
void setString(const QString &pref, const QString &value)
Met a jour la valeur associee a une preference.
static QString intToString(const int &val)
double getDouble(const QString &pref)
Recherche une ressource et retourne sa valeur associee. Utilise la categorie courante.
float getFloat(const QString &pref)
Recherche une ressource et retourne sa valeur associee. Utilise la categorie courante.
QString _curDir
Le nom de la categorie courante.
QString _xmlRootNodeName
Nom du noeud root du fichier XML.
void setUInt(const QString &pref, const unsigned int &value)
static QString uintToString(const unsigned int &val)
bool writeXML(QString fileName)
Enregistre le fichier de preference au format XML.
bool getBool(const QString &pref)
Recherche une ressource et retourne sa valeur associee. Utilise la categorie courante.
void setFrame(const QString &pref, const int &posX, const int &posY, const int &sizeX, const int &sizeY)
Sauvegarde la position et la taille d'une fenetre.
int getInt(const QString &pref)
Recherche une ressource et retourne sa valeur associee.Utilise la categorie courante.
void setFloat(const QString &pref, const float &value)
Met a jour la valeur associee a une preference.
void setXMLParamNodeName(QString name)
Change le nom des noeuds de parametres dans le fichier XML.
void setXMLRootNodeName(QString name)
Change le nom du noeud root du fichier XML.
bool readXML(QString fileName)
Ouvre un fichier de preference en XML et le parcours pour mettre a jour la tableau de preferences.
QString * getStringArray(const QString &pref, int &sizeArray)
Recherche une ressource et retourne son tableau de valeurs associees. Utilise la categorie courante.
void getPoint(const QString &pref, int &x, int &y)
Charge les coordonnees en pixel d'un point. Utilise la categorie courante.
void setColor(const QString &pref, const float &r, const float &g, const float &b)
Sauvegarde les composantes RGB d'une couleur, en float.Utilise la categorie courante.
void setStringArray(const QString &pref, const QString *valueArray, const int &sizeArray)
Met a jour un tableau de valeurs associees a une preference.
void reset()
Vide le tableau associatif preference/valeur.
bool exists(const QString &pref)
Test si une preference est presente dans le tableau de preferences. Utilise la categorie courante.
void setInt(const QString &pref, const int &value)
Met a jour la valeur associee a une preference.
void setPoint(const QString &pref, const int &x, const int &y)
Sauvegarde les coordonnees en pixel d'un point.
void setCurrentDirectory(QString dir)
Defini la categorie courante pour la lecture et l'ecriture de parametres.
void getFrame(const QString &pref, int &posX, int &posY, int &sizeX, int &sizeY)
Charge la position et la taille d'une fenetre. Utilise la categorie courante.
QString getString(const QString &pref)
Recherche une ressource et retourne sa valeur associee. Utilise la categorie courante.
Le type utilise pour stocker une categorie de preferences. C'est un tableau associatif string/OPrefMa...
std::map< QString, OPrefMap >::iterator ODirMapIt
std::map< QString, OPrefMap > _dirMap
Le type utilise pour stocker les preferences et leur valeur. C'est un tableau associatif string/strin...
std::map< QString, QString >::iterator OPrefMapIt
std::map< QString, QString > _prefMap