1 | /* |
---|
2 | Copyright (C) 2012 |
---|
3 | Alejandro Mujica (amujica@cenditel.gob.ve) |
---|
4 | Erwin Paredes (eparedes@cenditel.gob.ve) |
---|
5 | José Ruiz (jruiz@cenditel.gob.ve) |
---|
6 | Rodolfo Rangel (rrangel@cenditel.gob.ve) |
---|
7 | Julie Vera (jvera@cenditel.gob.ve) |
---|
8 | |
---|
9 | CENDITEL Fundación Centro Nacional de Desarrollo e Investigación en |
---|
10 | Tecnologías Libres |
---|
11 | |
---|
12 | Este programa es software libre; Usted puede usarlo bajo los términos de la |
---|
13 | licencia de software GPL versión 2.0 de la Free Software Foundation. |
---|
14 | |
---|
15 | Este programa se distribuye con la esperanza de que sea útil, pero SIN |
---|
16 | NINGUNA GARANTÍA; tampoco las implícitas garantías de MERCANTILIDAD o |
---|
17 | ADECUACIÓN A UN PROPÓSITO PARTICULAR. |
---|
18 | Consulte la licencia GPL para más detalles. Usted debe recibir una copia |
---|
19 | de la GPL junto con este programa; si no, escriba a la Free Software |
---|
20 | Foundation Inc. 51 Franklin Street,5 Piso, Boston, MA 02110-1301, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | Este archivo contiene la definición de la clase Configuration. |
---|
25 | |
---|
26 | Autor: Alejandro J. Mujica |
---|
27 | Fecha: |
---|
28 | */ |
---|
29 | |
---|
30 | # ifndef CONFIGURATION_H |
---|
31 | # define CONFIGURATION_H |
---|
32 | |
---|
33 | # include <string> |
---|
34 | # include <memory> |
---|
35 | |
---|
36 | # include <QDir> |
---|
37 | |
---|
38 | /** Contiene los valores básicos de configfuración de la aplicación. |
---|
39 | * |
---|
40 | * Esta clase está implementada bajo el patrón "Singleton" y maneja la |
---|
41 | * información necesaria para la conexión con la base de datos y la información |
---|
42 | * del directorio de usuario en el cual se almacenan los xml generados y los |
---|
43 | * gráficos que se visualizan. |
---|
44 | * |
---|
45 | * Estos valores son leídos de un archivo el cual se encuentra en el directorio |
---|
46 | * de usuario, si el archivo no existe entonces asigna los valores por omisión |
---|
47 | * y escribe el archivo con éstos. |
---|
48 | * |
---|
49 | * @author Alejandro J. Mujica |
---|
50 | */ |
---|
51 | class Configuration { |
---|
52 | |
---|
53 | // Ruta de instalación de la aplicación |
---|
54 | static const std::string APPLICATION_PATH; |
---|
55 | |
---|
56 | // Nombre de la aplicación. |
---|
57 | static const std::string APPLICATION_NAME; |
---|
58 | |
---|
59 | // Nombre del directorio de usuario. |
---|
60 | static const std::string DIR_NAME; |
---|
61 | |
---|
62 | // Nombre del directorio para almacenar archivos xml. |
---|
63 | static const std::string XML_DIR_NAME; |
---|
64 | |
---|
65 | // Nombre del directorio para almacenar archivos dot. |
---|
66 | static const std::string DOT_DIR_NAME; |
---|
67 | |
---|
68 | // Nombre del directorio para almacenar archivos svg. |
---|
69 | static const std::string SVG_DIR_NAME; |
---|
70 | |
---|
71 | // Nombre del archivo de configuración. |
---|
72 | static const std::string CONFIGURATION_FILE_NAME; |
---|
73 | |
---|
74 | // Nombre base del archivo en el cual se especifican las raíces de una red. |
---|
75 | static const std::string ROOTS_FILE_NAME; |
---|
76 | |
---|
77 | /* |
---|
78 | Nombre base de los archivos (xml, dot y svg) que contienen información |
---|
79 | de la red original. |
---|
80 | */ |
---|
81 | static const std::string GRAPH_FILE_NAME; |
---|
82 | |
---|
83 | /* |
---|
84 | Nombre base del archivo que contiene información de la simulación que se |
---|
85 | desea ejecutar. |
---|
86 | */ |
---|
87 | static const std::string SIMULATION_FILE_NAME; |
---|
88 | |
---|
89 | /* |
---|
90 | Nombre base de los archivos (xml, dot y svg) que contienen información |
---|
91 | de una red simulada. |
---|
92 | */ |
---|
93 | static const std::string ALTER_GRAPH_FILE_NAME; |
---|
94 | |
---|
95 | // Comando para ejecutar el constructor de redes. |
---|
96 | static const std::string GRAPH_BUILDER_COMMAND; |
---|
97 | |
---|
98 | // Comando para ejecutar el simulador. |
---|
99 | static const std::string SIMULATION_COMMAND; |
---|
100 | |
---|
101 | // Nombre del archivo de texto para escribir los valores de base de datos. |
---|
102 | static const std::string DB_FILE_NAME; |
---|
103 | |
---|
104 | // Host asignado por defecto al servidor de base de datos. |
---|
105 | static const std::string DFT_HOST; |
---|
106 | |
---|
107 | // Puerto asignado por defecto al servidor de base de datos. |
---|
108 | static const std::string DFT_PORT; |
---|
109 | |
---|
110 | // Nombre de la base de datos asignado por defecto. |
---|
111 | static const std::string DFT_DATA_BASE; |
---|
112 | |
---|
113 | // Usuario asignado por defecto para el servidor de base de datos. |
---|
114 | static const std::string DFT_USER; |
---|
115 | |
---|
116 | // Password asignado por defecto para el servidor de base de datos. |
---|
117 | static const std::string DFT_PASSWORD; |
---|
118 | |
---|
119 | // Instancia única de la clase. |
---|
120 | static std::unique_ptr <Configuration> instance; |
---|
121 | |
---|
122 | std::string host; |
---|
123 | |
---|
124 | std::string port; |
---|
125 | |
---|
126 | std::string dataBase; |
---|
127 | |
---|
128 | std::string user; |
---|
129 | |
---|
130 | std::string password; |
---|
131 | |
---|
132 | std::string configurationFileName; |
---|
133 | |
---|
134 | Configuration(); |
---|
135 | |
---|
136 | /// Carga los valores del archivo de configuración.. |
---|
137 | void readFile(); |
---|
138 | |
---|
139 | /// Escribe los valores sobre el archivo de configuración. |
---|
140 | void writeFile(); |
---|
141 | |
---|
142 | |
---|
143 | public: |
---|
144 | /// Referencia a la única instancia de la clase. |
---|
145 | static Configuration & getInstance(); |
---|
146 | |
---|
147 | /// Asigna los valores que se seleccionaron por defecto. |
---|
148 | void restoreDefaultValues(); |
---|
149 | |
---|
150 | /// Convierte |
---|
151 | void setValuesDefault(); |
---|
152 | |
---|
153 | const std::string & getHost() const; |
---|
154 | |
---|
155 | void setHost(const std::string &); |
---|
156 | |
---|
157 | void setHost(std::string &&); |
---|
158 | |
---|
159 | const std::string & getPort() const; |
---|
160 | |
---|
161 | void setPort(const std::string &); |
---|
162 | |
---|
163 | void setPort(std::string &&); |
---|
164 | |
---|
165 | const std::string & getDataBase() const; |
---|
166 | |
---|
167 | void setDataBase(const std::string &); |
---|
168 | |
---|
169 | void setDataBase(std::string &&); |
---|
170 | |
---|
171 | const std::string & getUser() const; |
---|
172 | |
---|
173 | void setUser(const std::string &); |
---|
174 | |
---|
175 | void setUser(std::string &&); |
---|
176 | |
---|
177 | const std::string & getPassword() const; |
---|
178 | |
---|
179 | void setPassword(const std::string &); |
---|
180 | |
---|
181 | void setPassword(std::string &&); |
---|
182 | |
---|
183 | const std::string & getApplicationName() const; |
---|
184 | |
---|
185 | const std::string & getConfigurationFileName() const; |
---|
186 | |
---|
187 | const std::string & getRootsFileName() const; |
---|
188 | |
---|
189 | const std::string & getGraphFileName() const; |
---|
190 | |
---|
191 | const std::string & getSimulationFileName() const; |
---|
192 | |
---|
193 | const std::string & getAlterFileName() const; |
---|
194 | |
---|
195 | const std::string & getGraphBuilderCommand() const; |
---|
196 | |
---|
197 | const std::string & getSimulationCommand() const; |
---|
198 | |
---|
199 | const std::string & getDirName() const; |
---|
200 | |
---|
201 | const std::string & getXmlDirName() const; |
---|
202 | |
---|
203 | const std::string & getDotDirName() const; |
---|
204 | |
---|
205 | const std::string & getSvgDirName() const; |
---|
206 | |
---|
207 | const std::string getDbFileName() const; |
---|
208 | |
---|
209 | void createDbFile(); |
---|
210 | |
---|
211 | void removeDbFile(); |
---|
212 | }; |
---|
213 | |
---|
214 | # define FILE_PATH(conf, prefix, name, ext) \ |
---|
215 | (QDir::homePath().toStdString() + "/" \ |
---|
216 | + conf.get##prefix##DirName() + "/" + conf.get##name##FileName() \ |
---|
217 | + "." + #ext) |
---|
218 | |
---|
219 | |
---|
220 | # endif // CONFIGURATION_H |
---|