Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OPreferenceManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
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  #include <vector>
34 
39 // typedef std::map<QString, QString> OPrefMap;
40 struct OPrefMap
41 {
42  typedef std::map<QString, QString>::iterator OPrefMapIt;
43  std::map<QString, QString> _prefMap;
44 };
45 
50 // typedef std::map<QString, OPrefMap> ODirMap;
51 struct ODirMap
52 {
53  typedef std::map<QString, OPrefMap>::iterator ODirMapIt;
54  std::map<QString, OPrefMap> _dirMap;
55 };
56 
84 {
85 public:
93  OPreferenceManager(const QString& currentDirectory);
97  OPreferenceManager(const QString& rootNodeName, const QString& paramNodeName);
101  OPreferenceManager(const QString& rootNodeName, const QString& paramNodeName,
102  const QString& currentDirectory);
106  virtual ~OPreferenceManager();
107 
113  void completePreferences(QString filePath);
114 
121  void loadDefault(const char* defaultParams[][2], int nbParams);
122 
126  void reset();
127 
133  void setXMLRootNodeName(QString name)
134  {
136  }
137 
143  void setXMLParamNodeName(QString name)
144  {
146  }
147 
155  bool readXML(QString fileName);
156 
164  bool writeXML(QString fileName);
165 
174  bool exists(const QString& pref);
175 
185  bool exists(const QString& dir, const QString& pref);
186 
195  QString getDirectory(const QString& pref);
196 
202  void setCurrentDirectory(QString dir);
209  {
210  return _curDir;
211  }
212 
223  void setString(const QString& pref, const QString& value);
224 
236  void setString(const QString& dir, const QString& pref, const QString& value);
237 
245  QString getString(const QString& pref);
246 
255  QString getString(const QString& dir, const QString& pref);
256 
268  void setStringArray(const QString& pref, const QString* valueArray, const int& sizeArray);
269 
282  void setStringArray(const QString& dir, const QString& pref, const QString* valueArray,
283  const int& sizeArray);
284 
294  QString* getStringArray(const QString& pref, int& sizeArray);
295 
306  QString* getStringArray(const QString& dir, const QString& pref, int& sizeArray);
307 
308  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
318  void setUInt(const QString& pref, const unsigned int& value);
329  void setUInt(const QString& dir, const QString& pref, const unsigned int& value);
330 
340  void setUInt(const QString& pref, const size_t& value);
351  void setUInt(const QString& dir, const QString& pref, const size_t& value);
352 
353  #if TY_COMPILER == TY_COMPILER_MSVC
363  void setUInt(const QString& pref, const unsigned long& value);
374  void setUInt(const QString& dir, const QString& pref, const unsigned long& value);
375  #endif
376  #else
387  void setUInt(const QString& pref, const size_t& value);
388 
401  void setUInt(const QString& dir, const QString& pref, const size_t& value);
402 
413  void setUInt(const QString& pref, const unsigned long& value);
414 
427  void setUInt(const QString& dir, const QString& pref, const unsigned long& value);
428 
429  #endif
440  void setInt(const QString& pref, const int& value);
441 
453  void setInt(const QString& dir, const QString& pref, const int& value);
454 
462  int getInt(const QString& pref);
463 
474  int getInt(const QString& dir, const QString& pref);
475 
486  void setBool(const QString& pref, const bool& value);
497  void setBool(const QString& dir, const QString& pref, const bool& value);
498 
506  bool getBool(const QString& pref);
507 
516  bool getBool(const QString& dir, const QString& pref);
517 
528  void setFloat(const QString& pref, const float& value);
529 
540  void setFloat(const QString& dir, const QString& pref, const float& value);
541 
549  float getFloat(const QString& pref);
550 
559  float getFloat(const QString& dir, const QString& pref);
560 
571  void setDouble(const QString& pref, const double& value);
572 
583  void setDouble(const QString& dir, const QString& pref, const double& value);
584 
592  double getDouble(const QString& pref);
601  double getDouble(const QString& dir, const QString& pref);
602 
616  void setFrame(const QString& pref, const int& posX, const int& posY, const int& sizeX, const int& sizeY);
617 
632  void setFrame(const QString& dir, const QString& pref, const int& posX, const int& posY, const int& sizeX,
633  const int& sizeY);
634 
644  void getFrame(const QString& pref, int& posX, int& posY, int& sizeX, int& sizeY);
645 
656  void getFrame(const QString& dir, const QString& pref, int& posX, int& posY, int& sizeX, int& sizeY);
657 
669  void setPoint(const QString& pref, const int& x, const int& y);
670 
682  void setPoint(const QString& dir, const QString& pref, const int& x, const int& y);
683 
691  void getPoint(const QString& pref, int& x, int& y);
692 
701  void getPoint(const QString& dir, const QString& pref, int& x, int& y);
702 
714  void setColor(const QString& pref, const float& r, const float& g, const float& b);
715 
728  void setColor(const QString& dir, const QString& pref, const float& r, const float& g, const float& b);
729 
738  void getColor(const QString& pref, float& r, float& g, float& b);
739 
749  void getColor(const QString& dir, const QString& pref, float& r, float& g, float& b);
750 
751  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
756  static QString uintToString(const unsigned int& val);
757 
762  static QString uintToString(const size_t& val);
763  #if TY_COMPILER == TY_COMPILER_MSVC
768  static QString uintToString(const unsigned long& val);
769  #endif
770  #else
775  static QString uintToString(const size_t& val);
776 
781  static QString uintToString(const unsigned long& val);
782  #endif
783 
788  static QString intToString(const int& val);
789 
794  static QString floatToString(const float& val);
795 
800  static QString doubleToString(const double& val);
801 
806  {
808  }
809 
813  std::vector<QString> getPreferenceNames();
814 
815 protected:
818 
820  QString _curDir;
821 
826 
827 private:
829 };
830 
831 #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)
void completePreferences(QString filePath)
Complete les préférences utilisateur manquante avec les valeurs par défaut.
static QString uintToString(const unsigned int &val)
std::vector< QString > getPreferenceNames()
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