Environment.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file Environment.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_BASE_ENVIRONMENT_HPP__
40 #define __OPENFLUID_BASE_ENVIRONMENT_HPP__
41 
42 
43 #include <string>
44 #include <vector>
45 
46 #include <openfluid/dllexport.hpp>
47 
48 
49 namespace openfluid { namespace base {
50 
51 
53 {
54  private:
55 
56  Environment(Environment const&) = delete;
57 
58  void operator=(Environment const&) = delete;
59 
60  static bool m_Initialized;
61 
62 
63  protected:
64 
65  static std::string m_SystemArch;
66 
67  static std::string m_HostName;
68 
69  static std::string m_UserName;
70 
71  static std::string m_Version;
72 
73  static std::string m_VersionFull;
74 
75  static std::string m_VersionMajorMinor;
76 
77  static std::string m_InstallPrefix;
78 
79  static std::string m_TempDir;
80 
81  static std::string m_UserHomeDir;
82 
83  static std::string m_UserDataDir;
84 
85  static std::string m_ConfigFile;
86 
87  static std::vector<std::string> m_DefaultSimulatorsDirs;
88 
89  static std::vector<std::string> m_ExtraSimulatorsDirs;
90 
91  static std::vector<std::string> m_DefaultObserversDirs;
92 
93  static std::vector<std::string> m_ExtraObserversDirs;
94 
95  static std::vector<std::string> m_DefaultBuilderextsDirs;
96 
97  static std::vector<std::string> m_ExtraBuilderextsDirs;
98 
99  static std::string m_ProvidedExamplesDir;
100 
101  static std::string m_UserExamplesDir;
102 
103  static std::string m_MarketBagDir;
104 
105  static std::string m_MarketBagVersionDir;
106 
107  static std::string m_MarketBagSimulatorsDir;
108 
109  static std::string m_MarketBagObserversDir;
110 
111  static std::string m_MarketBagBuilderextsDir;
112 
113  static std::string m_MarketBagDataDir;
114 
115  static std::string m_MarketBagBinSubDir;
116 
117  static std::string m_MarketBagSrcSubDir;
118 
119  static std::string m_TranslationsDir;
120 
121  static std::string m_CommonResourcesDir;
122 
123  static std::string m_AppsResourcesDir;
124 
125  static int m_IdealThreadCount;
126 
128  { }
129 
130  static std::string getWareFullPath(const std::vector<std::string>& Dirs, const std::string& Filename);
131 
132 
133  public:
134 
135  /**
136  Initializes OpenFLUID environment
137  */
138  static void init();
139 
140  /**
141  Returns the current host name
142  @return the host name
143  */
144  static std::string getHostName()
145  { return m_HostName; }
146 
147  /**
148  Returns the current system architecture. Possible values are defined in the global.hpp file
149  with the OPENFLUID_OS_STRLABEL definition
150  @return the system architecture
151  */
152  static std::string getSystemArch()
153  { return m_SystemArch; }
154 
155  /**
156  Returns the ideal thread count for the current running system
157  @return the number of threads
158  */
159  static int getIdealThreadCount()
160  { return m_IdealThreadCount; }
161 
162  /**
163  Returns the ideal jobs count for the current running system
164  @return the number of jobs
165  */
166  static int getIdealJobsCount()
167  { return int(m_IdealThreadCount/2); }
168 
169  /**
170  Returns the current user name
171  @return the user name
172  */
173  static std::string getUserName()
174  { return m_UserName; }
175 
176  /**
177  Returns the current OpenFLUID version using the MAJOR.MINOR.PATCH format
178  @return the version number
179  */
180  static std::string getVersion()
181  { return m_Version; }
182 
183  /**
184  Returns the current OpenFLUID version using the MAJOR.MINOR.PATCH~STATUS format
185  @return the fully qualified version number
186  */
187  static std::string getVersionFull()
188  { return m_VersionFull; }
189 
190  /**
191  Returns the current OpenFLUID version using the MAJOR.MINOR format
192  @return the simplified version number
193  */
194  static std::string getVersionMajorMinor()
195  { return m_VersionMajorMinor; }
196 
197  /**
198  Returns the current OpenFLUID temporary directory. It is automatically defined but can be forced using
199  the OPENFLUID_TEMP_PATH environment variable.
200  @return the full path to the directory
201  */
202  static std::string getTempDir()
203  { return m_TempDir; }
204 
205  /**
206  Returns the OpenFLUID install prefix directory. It is defined at build time but can be forced using
207  the OPENFLUID_INSTALL_PREFIX environment variable.
208  @return the full path to the directory
209  */
210  static std::string getInstallPrefix()
211  { return m_InstallPrefix; }
212 
213  /**
214  Returns the current user home directory
215  @return the full path to the directory
216  */
217  static std::string getUserHomeDir()
218  { return m_UserHomeDir; }
219 
220  /**
221  Returns the OpenFLUID data directory for the current user
222  @return the full path to the directory
223  */
224  static std::string getUserDataDir()
225  { return m_UserDataDir; }
226 
227  /**
228  Returns the full path of a file or directory relative to the OpenFLUID data directory for the current user
229  @param[in] Path the path relative to the OpenFLUID user data directory
230  @return the full path to the file or directory
231  */
232  static std::string getUserDataFullPath(const std::string& Path)
233  { return m_UserDataDir + "/" + Path; }
234 
235  /**
236  Returns the full path of the examples directory for the current user
237  @return the full path to the directory
238  */
239  static std::string getUserExamplesDir()
240  { return m_UserExamplesDir; }
241 
242  /**
243  Returns the full path of the directory where examples provided by OpenFLUID or models installations are stored
244  @return the full path to the directory
245  */
246  static std::string getProvidedExamplesDir()
247  { return m_ProvidedExamplesDir; }
248 
249  /**
250  Automatically prepares the user data directory
251  */
252  static void prepareUserDataDirectory();
253 
254  /**
255  Returns the configuration file path for the current user
256  @return the full path to the file
257  */
258  static std::string getConfigFile()
259  { return m_ConfigFile; }
260 
261  /**
262  Returns the OpenFLUID translations directory
263  @return the full path to the directory
264  */
265  static std::string getTranslationsDir()
266  { return m_TranslationsDir; }
267 
268  /**
269  Returns the OpenFLUID common resources directory
270  @return the full path to the directory
271  */
272  static std::string getCommonResourcesDir()
273  { return m_CommonResourcesDir; }
274 
275  /**
276  Returns the full path of a file or directory relative to the OpenFLUID common resources directory
277  @param[in] Path the path relative to the OpenFLUID common resources directory
278  @return the full path to the file or directory
279  */
280  static std::string getCommonResourcesFullPath(const std::string& Path)
281  { return m_CommonResourcesDir + "/" + Path; }
282 
283  /**
284  Returns the resources directory for a given OpenFLUID software application
285  @param[in] AppName the name of the OpenFLUID application
286  @return the full path to the directory
287  */
288  static std::string getAppResourcesDir(const std::string& AppName)
289  { return m_AppsResourcesDir + "/" + AppName; }
290 
291  /**
292  Returns the full path of a file or directory relative to the resources directory
293  of a given OpenFLUID software application
294  @param[in] AppName the name of the OpenFLUID application
295  @param[in] Path the path relative to the OpenFLUID application resources directory
296  @return the full path to the file or directory
297  */
298  static std::string getAppResourcesFullPath(const std::string& AppName, const std::string& Path)
299  { return getAppResourcesDir(AppName) + "/" + Path; }
300 
301  /**
302  Returns the list of directories full paths where OpenFLUID searches for simulators.
303  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
304  @return the list of directories full paths
305  */
306  static std::vector<std::string> getSimulatorsDirs();
307 
308  /**
309  Returns the list of default directories full paths where OpenFLUID searches for simulators.
310  @return the list of directories full paths
311  */
312  static std::vector<std::string> getDefaultSimulatorsDirs()
313  { return m_DefaultSimulatorsDirs; }
314 
315  /**
316  Returns the list of extra added directories full paths where OpenFLUID searches for simulators.
317  @return the list of directories full paths
318  */
319  static std::vector<std::string> getExtraSimulatorsDirs()
320  { return m_ExtraSimulatorsDirs; }
321 
322  /**
323  Adds paths to the list of directories where OpenFLUID searches for simulators.
324  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
325  @param[in] Paths the list of full paths as a single string
326  */
327  static void addExtraSimulatorsDirs(const std::string& Paths);
328 
329  /**
330  Resets the list of extra directories where OpenFLUID searches for simulators to empty
331  */
332  static void resetExtraSimulatorsDirs();
333 
334  /**
335  Returns the full path of a searched simulator file
336  @return the full path of the searched file, empty if not found
337  */
338  static std::string getSimulatorFullPath(const std::string& Filename);
339 
340  /**
341  Returns the list of directories full paths where OpenFLUID searches for observers.
342  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
343  @return the list of directories full paths
344  */
345  static std::vector<std::string> getObserversDirs();
346 
347  /**
348  Returns the list of default directories full paths where OpenFLUID searches for observers.
349  @return the list of directories full paths
350  */
351  static std::vector<std::string> getDefaultObserversDirs()
352  { return m_DefaultObserversDirs; }
353 
354  /**
355  Returns the list of extra added directories full paths where OpenFLUID searches for observers.
356  @return the list of directories full paths
357  */
358  static std::vector<std::string> getExtraObserversDirs()
359  { return m_ExtraObserversDirs; }
360 
361  /**
362  Adds paths to the list of directories where OpenFLUID searches for observers.
363  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
364  @param[in] Paths the list of full paths as a single string
365  */
366  static void addExtraObserversDirs(const std::string& Paths);
367 
368  /**
369  Resets the list of extra directories where OpenFLUID searches for observers to empty
370  */
371  static void resetExtraObserversDirs();
372 
373  /**
374  Returns the full path of a searched observer file
375  @return the full path of the searched file, empty if not found
376  */
377  static std::string getObserverFullPath(const std::string& Filename);
378 
379  /**
380  Returns the list of directories full paths where OpenFLUID searches for builder-extensions.
381  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
382  @return the list of directories full paths
383  */
384  static std::vector<std::string> getBuilderextsDirs();
385 
386  /**
387  Returns the list of default directories full paths where OpenFLUID searches for builder-extensions.
388  @return the list of directories full paths
389  */
390  static std::vector<std::string> getDefaultBuilderextsDirs()
391  { return m_DefaultBuilderextsDirs; }
392 
393  /**
394  Returns the list of extra added directories full paths where OpenFLUID searches for builder-extensions.
395  @return the list of directories full paths
396  */
397  static std::vector<std::string> getExtraBuilderextsDirs()
398  { return m_ExtraBuilderextsDirs; }
399 
400  /**
401  Adds paths to the list of directories where OpenFLUID searches for builder-extensions.
402  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
403  @param[in] Paths the list of full paths as a single string
404  */
405  static void addExtraBuilderextsDirs(const std::string& Paths);
406 
407  /**
408  Resets the list of extra directories where OpenFLUID searches for builder-extensions to empty
409  */
410  static void resetExtraBuilderextsDirs();
411 
412  /**
413  Returns the full path of a searched builder-extension file
414  @return the full path of the searched file, empty if not found
415  */
416  static std::string getBuilderextFullPath(const std::string& Filename);
417 
418  static std::string getMarketBagBinSubDir()
419  { return m_MarketBagBinSubDir; }
420 
421  static std::string getMarketBagBuilderextsDir()
422  { return m_MarketBagBuilderextsDir; }
423 
424  static std::string getMarketBagDataDir()
425  { return m_MarketBagDataDir; }
426 
427  static std::string getMarketBagDir()
428  { return m_MarketBagDir; }
429 
430  static std::string getMarketBagObserversDir()
431  { return m_MarketBagObserversDir; }
432 
433  static std::string getMarketBagSimulatorsDir()
434  { return m_MarketBagSimulatorsDir; }
435 
436  static std::string getMarketBagSrcSubDir()
437  { return m_MarketBagSrcSubDir; }
438 
439  static std::string getMarketBagVersionDir()
440  { return m_MarketBagVersionDir; }
441 
442 };
443 
444 
445 } } // namespaces
446 
447 
448 #endif /* __OPENFLUID_BASE_ENVIRONMENT_HPP__ */
static int getIdealThreadCount()
Definition: Environment.hpp:159
static std::string m_TempDir
Definition: Environment.hpp:79
static std::vector< std::string > getExtraSimulatorsDirs()
Definition: Environment.hpp:319
static std::string getMarketBagSrcSubDir()
Definition: Environment.hpp:436
static std::vector< std::string > getExtraBuilderextsDirs()
Definition: Environment.hpp:397
static std::string getTranslationsDir()
Definition: Environment.hpp:265
static std::string getProvidedExamplesDir()
Definition: Environment.hpp:246
static std::string m_VersionFull
Definition: Environment.hpp:73
static std::string m_TranslationsDir
Definition: Environment.hpp:119
static std::string m_HostName
Definition: Environment.hpp:67
static std::string m_ProvidedExamplesDir
Definition: Environment.hpp:99
static std::string m_MarketBagBinSubDir
Definition: Environment.hpp:115
static std::string m_MarketBagDir
Definition: Environment.hpp:103
static std::string m_UserDataDir
Definition: Environment.hpp:83
static std::vector< std::string > m_DefaultObserversDirs
Definition: Environment.hpp:91
Definition: Environment.hpp:52
static std::string m_InstallPrefix
Definition: Environment.hpp:77
static std::vector< std::string > m_ExtraSimulatorsDirs
Definition: Environment.hpp:89
static std::string getInstallPrefix()
Definition: Environment.hpp:210
static std::string getMarketBagDataDir()
Definition: Environment.hpp:424
static std::string m_AppsResourcesDir
Definition: Environment.hpp:123
static std::string m_MarketBagBuilderextsDir
Definition: Environment.hpp:111
static std::vector< std::string > m_DefaultBuilderextsDirs
Definition: Environment.hpp:95
static std::string m_MarketBagObserversDir
Definition: Environment.hpp:109
static std::string m_SystemArch
Definition: Environment.hpp:65
static std::string m_MarketBagSimulatorsDir
Definition: Environment.hpp:107
static std::string getMarketBagDir()
Definition: Environment.hpp:427
static std::string m_CommonResourcesDir
Definition: Environment.hpp:121
#define OPENFLUID_API
Definition: dllexport.hpp:87
static std::string getUserDataFullPath(const std::string &Path)
Definition: Environment.hpp:232
static std::string getUserName()
Definition: Environment.hpp:173
static std::string m_MarketBagDataDir
Definition: Environment.hpp:113
static std::string getAppResourcesFullPath(const std::string &AppName, const std::string &Path)
Definition: Environment.hpp:298
static std::vector< std::string > getDefaultObserversDirs()
Definition: Environment.hpp:351
static std::string m_UserName
Definition: Environment.hpp:69
static std::string getAppResourcesDir(const std::string &AppName)
Definition: Environment.hpp:288
static std::string getVersion()
Definition: Environment.hpp:180
static std::string getHostName()
Definition: Environment.hpp:144
static std::string m_MarketBagSrcSubDir
Definition: Environment.hpp:117
Environment()
Definition: Environment.hpp:127
static std::string m_VersionMajorMinor
Definition: Environment.hpp:75
static std::vector< std::string > getDefaultBuilderextsDirs()
Definition: Environment.hpp:390
static std::string m_MarketBagVersionDir
Definition: Environment.hpp:105
static std::string m_Version
Definition: Environment.hpp:71
static std::vector< std::string > m_ExtraObserversDirs
Definition: Environment.hpp:93
static int getIdealJobsCount()
Definition: Environment.hpp:166
static std::string getMarketBagBuilderextsDir()
Definition: Environment.hpp:421
static std::vector< std::string > m_ExtraBuilderextsDirs
Definition: Environment.hpp:97
static std::string getSystemArch()
Definition: Environment.hpp:152
static std::string getUserHomeDir()
Definition: Environment.hpp:217
static std::string m_UserExamplesDir
Definition: Environment.hpp:101
static std::string getUserDataDir()
Definition: Environment.hpp:224
static std::string getVersionMajorMinor()
Definition: Environment.hpp:194
static std::string getMarketBagObserversDir()
Definition: Environment.hpp:430
static std::string m_UserHomeDir
Definition: Environment.hpp:81
static std::string getMarketBagSimulatorsDir()
Definition: Environment.hpp:433
static std::string getUserExamplesDir()
Definition: Environment.hpp:239
static std::vector< std::string > getExtraObserversDirs()
Definition: Environment.hpp:358
static std::vector< std::string > getDefaultSimulatorsDirs()
Definition: Environment.hpp:312
static std::string getCommonResourcesDir()
Definition: Environment.hpp:272
static std::string getConfigFile()
Definition: Environment.hpp:258
static std::string getCommonResourcesFullPath(const std::string &Path)
Definition: Environment.hpp:280
static std::string getMarketBagBinSubDir()
Definition: Environment.hpp:418
static std::string m_ConfigFile
Definition: Environment.hpp:85
static std::string getMarketBagVersionDir()
Definition: Environment.hpp:439
static int m_IdealThreadCount
Definition: Environment.hpp:125
Definition: ApplicationException.hpp:47
static std::vector< std::string > m_DefaultSimulatorsDirs
Definition: Environment.hpp:87
static std::string getTempDir()
Definition: Environment.hpp:202
static std::string getVersionFull()
Definition: Environment.hpp:187