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  }
131 
132  static std::string getWareFullPath(const std::vector<std::string>& Dirs, const std::string& Filename);
133 
134 
135  public:
136 
137  /**
138  Initializes OpenFLUID environment
139  */
140  static void init();
141 
142  /**
143  Returns the current host name
144  @return the host name
145  */
146  static std::string getHostName()
147  {
148  return m_HostName;
149  }
150 
151  /**
152  Returns the current system architecture. Possible values are defined in the global.hpp file
153  with the OPENFLUID_OS_STRLABEL definition
154  @return the system architecture
155  */
156  static std::string getSystemArch()
157  {
158  return m_SystemArch;
159  }
160 
161  /**
162  Returns the ideal thread count for the current running system
163  @return the number of threads
164  */
165  static int getIdealThreadCount()
166  {
167  return m_IdealThreadCount;
168  }
169 
170  /**
171  Returns the ideal jobs count for the current running system
172  @return the number of jobs
173  */
174  static int getIdealJobsCount()
175  {
176  return int(m_IdealThreadCount/2);
177  }
178 
179  /**
180  Returns the current user name
181  @return the user name
182  */
183  static std::string getUserName()
184  {
185  return m_UserName;
186  }
187 
188  /**
189  Returns the current OpenFLUID version using the MAJOR.MINOR.PATCH format
190  @return the version number
191  */
192  static std::string getVersion()
193  {
194  return m_Version;
195  }
196 
197  /**
198  Returns the current OpenFLUID version using the MAJOR.MINOR.PATCH~STATUS format
199  @return the fully qualified version number
200  */
201  static std::string getVersionFull()
202  {
203  return m_VersionFull;
204  }
205 
206  /**
207  Returns the current OpenFLUID version using the MAJOR.MINOR format
208  @return the simplified version number
209  */
210  static std::string getVersionMajorMinor()
211  {
212  return m_VersionMajorMinor;
213  }
214 
215  /**
216  Returns the current OpenFLUID temporary directory. It is automatically defined but can be forced using
217  the OPENFLUID_TEMP_PATH environment variable.
218  @return the full path to the directory
219  */
220  static std::string getTempDir()
221  {
222  return m_TempDir;
223  }
224 
225  /**
226  Returns the OpenFLUID install prefix directory. It is defined at build time but can be forced using
227  the OPENFLUID_INSTALL_PREFIX environment variable.
228  @return the full path to the directory
229  */
230  static std::string getInstallPrefix()
231  {
232  return m_InstallPrefix;
233  }
234 
235  /**
236  Returns the current user home directory
237  @return the full path to the directory
238  */
239  static std::string getUserHomeDir()
240  {
241  return m_UserHomeDir;
242  }
243 
244  /**
245  Returns the OpenFLUID data directory for the current user
246  @return the full path to the directory
247  */
248  static std::string getUserDataDir()
249  {
250  return m_UserDataDir;
251  }
252 
253  /**
254  Returns the full path of a file or directory relative to the OpenFLUID data directory for the current user
255  @param[in] Path the path relative to the OpenFLUID user data directory
256  @return the full path to the file or directory
257  */
258  static std::string getUserDataFullPath(const std::string& Path)
259  {
260  return m_UserDataDir + "/" + Path;
261  }
262 
263  /**
264  Returns the full path of the examples directory for the current user
265  @return the full path to the directory
266  */
267  static std::string getUserExamplesDir()
268  {
269  return m_UserExamplesDir;
270  }
271 
272  /**
273  Returns the full path of the directory where examples provided by OpenFLUID or models installations are stored
274  @return the full path to the directory
275  */
276  static std::string getProvidedExamplesDir()
277  {
278  return m_ProvidedExamplesDir;
279  }
280 
281  /**
282  Automatically prepares the user data directory
283  */
284  static void prepareUserDataDirectory();
285 
286  /**
287  Returns the configuration file path for the current user
288  @return the full path to the file
289  */
290  static std::string getConfigFile()
291  {
292  return m_ConfigFile;
293  }
294 
295  /**
296  Returns the OpenFLUID translations directory
297  @return the full path to the directory
298  */
299  static std::string getTranslationsDir()
300  {
301  return m_TranslationsDir;
302  }
303 
304  /**
305  Returns the OpenFLUID common resources directory
306  @return the full path to the directory
307  */
308  static std::string getCommonResourcesDir()
309  {
310  return m_CommonResourcesDir;
311  }
312 
313  /**
314  Returns the full path of a file or directory relative to the OpenFLUID common resources directory
315  @param[in] Path the path relative to the OpenFLUID common resources directory
316  @return the full path to the file or directory
317  */
318  static std::string getCommonResourcesFullPath(const std::string& Path)
319  {
320  return m_CommonResourcesDir + "/" + Path;
321  }
322 
323  /**
324  Returns the resources directory for a given OpenFLUID software application
325  @param[in] AppName the name of the OpenFLUID application
326  @return the full path to the directory
327  */
328  static std::string getAppResourcesDir(const std::string& AppName)
329  {
330  return m_AppsResourcesDir + "/" + AppName;
331  }
332 
333  /**
334  Returns the full path of a file or directory relative to the resources directory
335  of a given OpenFLUID software application
336  @param[in] AppName the name of the OpenFLUID application
337  @param[in] Path the path relative to the OpenFLUID application resources directory
338  @return the full path to the file or directory
339  */
340  static std::string getAppResourcesFullPath(const std::string& AppName, const std::string& Path)
341  {
342  return getAppResourcesDir(AppName) + "/" + Path;
343  }
344 
345  /**
346  Returns the list of directories full paths where OpenFLUID searches for simulators.
347  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
348  @return the list of directories full paths
349  */
350  static std::vector<std::string> getSimulatorsDirs();
351 
352  /**
353  Returns the list of default directories full paths where OpenFLUID searches for simulators.
354  @return the list of directories full paths
355  */
356  static std::vector<std::string> getDefaultSimulatorsDirs()
357  {
358  return m_DefaultSimulatorsDirs;
359  }
360 
361  /**
362  Returns the list of extra added directories full paths where OpenFLUID searches for simulators.
363  @return the list of directories full paths
364  */
365  static std::vector<std::string> getExtraSimulatorsDirs()
366  {
367  return m_ExtraSimulatorsDirs;
368  }
369 
370  /**
371  Adds paths to the list of directories where OpenFLUID searches for simulators.
372  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
373  @param[in] Paths the list of full paths as a single string
374  */
375  static void addExtraSimulatorsDirs(const std::string& Paths);
376 
377  /**
378  Resets the list of extra directories where OpenFLUID searches for simulators to empty
379  */
380  static void resetExtraSimulatorsDirs();
381 
382  /**
383  Returns the full path of a searched simulator file
384  @return the full path of the searched file, empty if not found
385  */
386  static std::string getSimulatorFullPath(const std::string& Filename);
387 
388  /**
389  Returns the list of directories full paths where OpenFLUID searches for observers.
390  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
391  @return the list of directories full paths
392  */
393  static std::vector<std::string> getObserversDirs();
394 
395  /**
396  Returns the list of default directories full paths where OpenFLUID searches for observers.
397  @return the list of directories full paths
398  */
399  static std::vector<std::string> getDefaultObserversDirs()
400  {
401  return m_DefaultObserversDirs;
402  }
403 
404  /**
405  Returns the list of extra added directories full paths where OpenFLUID searches for observers.
406  @return the list of directories full paths
407  */
408  static std::vector<std::string> getExtraObserversDirs()
409  {
410  return m_ExtraObserversDirs;
411  }
412 
413  /**
414  Adds paths to the list of directories where OpenFLUID searches for observers.
415  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
416  @param[in] Paths the list of full paths as a single string
417  */
418  static void addExtraObserversDirs(const std::string& Paths);
419 
420  /**
421  Resets the list of extra directories where OpenFLUID searches for observers to empty
422  */
423  static void resetExtraObserversDirs();
424 
425  /**
426  Returns the full path of a searched observer file
427  @return the full path of the searched file, empty if not found
428  */
429  static std::string getObserverFullPath(const std::string& Filename);
430 
431  /**
432  Returns the list of directories full paths where OpenFLUID searches for builder-extensions.
433  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
434  @return the list of directories full paths
435  */
436  static std::vector<std::string> getBuilderextsDirs();
437 
438  /**
439  Returns the list of default directories full paths where OpenFLUID searches for builder-extensions.
440  @return the list of directories full paths
441  */
442  static std::vector<std::string> getDefaultBuilderextsDirs()
443  {
444  return m_DefaultBuilderextsDirs;
445  }
446 
447  /**
448  Returns the list of extra added directories full paths where OpenFLUID searches for builder-extensions.
449  @return the list of directories full paths
450  */
451  static std::vector<std::string> getExtraBuilderextsDirs()
452  {
453  return m_ExtraBuilderextsDirs;
454  }
455 
456  /**
457  Adds paths to the list of directories where OpenFLUID searches for builder-extensions.
458  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
459  @param[in] Paths the list of full paths as a single string
460  */
461  static void addExtraBuilderextsDirs(const std::string& Paths);
462 
463  /**
464  Resets the list of extra directories where OpenFLUID searches for builder-extensions to empty
465  */
466  static void resetExtraBuilderextsDirs();
467 
468  /**
469  Returns the full path of a searched builder-extension file
470  @return the full path of the searched file, empty if not found
471  */
472  static std::string getBuilderextFullPath(const std::string& Filename);
473 
474  static std::string getMarketBagBinSubDir()
475  {
476  return m_MarketBagBinSubDir;
477  }
478 
479  static std::string getMarketBagBuilderextsDir()
480  {
481  return m_MarketBagBuilderextsDir;
482  }
483 
484  static std::string getMarketBagDataDir()
485  {
486  return m_MarketBagDataDir;
487  }
488 
489  static std::string getMarketBagDir()
490  {
491  return m_MarketBagDir;
492  }
493 
494  static std::string getMarketBagObserversDir()
495  {
496  return m_MarketBagObserversDir;
497  }
498 
499  static std::string getMarketBagSimulatorsDir()
500  {
501  return m_MarketBagSimulatorsDir;
502  }
503 
504  static std::string getMarketBagSrcSubDir()
505  {
506  return m_MarketBagSrcSubDir;
507  }
508 
509  static std::string getMarketBagVersionDir()
510  {
511  return m_MarketBagVersionDir;
512  }
513 };
514 
515 
516 } } // namespaces
517 
518 
519 #endif /* __OPENFLUID_BASE_ENVIRONMENT_HPP__ */
static std::string getMarketBagDataDir()
Definition: Environment.hpp:484
static std::string getProvidedExamplesDir()
Definition: Environment.hpp:276
static int getIdealThreadCount()
Definition: Environment.hpp:165
Environment()
Definition: Environment.hpp:127
static std::string m_TempDir
Definition: Environment.hpp:79
static std::string getMarketBagBinSubDir()
Definition: Environment.hpp:474
static std::string m_MarketBagSrcSubDir
Definition: Environment.hpp:117
static std::string getMarketBagSrcSubDir()
Definition: Environment.hpp:504
static std::string m_InstallPrefix
Definition: Environment.hpp:77
Definition: Environment.hpp:52
static std::string m_MarketBagVersionDir
Definition: Environment.hpp:105
static std::vector< std::string > getDefaultBuilderextsDirs()
Definition: Environment.hpp:442
static std::string getMarketBagSimulatorsDir()
Definition: Environment.hpp:499
static std::string getCommonResourcesDir()
Definition: Environment.hpp:308
static std::string getTempDir()
Definition: Environment.hpp:220
static std::string m_SystemArch
Definition: Environment.hpp:65
static std::vector< std::string > getDefaultSimulatorsDirs()
Definition: Environment.hpp:356
static std::string getSystemArch()
Definition: Environment.hpp:156
static std::string getMarketBagBuilderextsDir()
Definition: Environment.hpp:479
static std::vector< std::string > getExtraBuilderextsDirs()
Definition: Environment.hpp:451
static std::string m_HostName
Definition: Environment.hpp:67
static int getIdealJobsCount()
Definition: Environment.hpp:174
static std::string getVersion()
Definition: Environment.hpp:192
static std::vector< std::string > m_DefaultSimulatorsDirs
Definition: Environment.hpp:87
static std::vector< std::string > getExtraSimulatorsDirs()
Definition: Environment.hpp:365
static std::vector< std::string > m_DefaultObserversDirs
Definition: Environment.hpp:91
static std::string getInstallPrefix()
Definition: Environment.hpp:230
static std::string m_TranslationsDir
Definition: Environment.hpp:119
static std::vector< std::string > m_DefaultBuilderextsDirs
Definition: Environment.hpp:95
static std::string getVersionMajorMinor()
Definition: Environment.hpp:210
static std::string getUserHomeDir()
Definition: Environment.hpp:239
static std::vector< std::string > m_ExtraBuilderextsDirs
Definition: Environment.hpp:97
static std::string getMarketBagVersionDir()
Definition: Environment.hpp:509
static std::string m_CommonResourcesDir
Definition: Environment.hpp:121
static std::string getCommonResourcesFullPath(const std::string &Path)
Definition: Environment.hpp:318
static std::string m_MarketBagDir
Definition: Environment.hpp:103
static std::string m_MarketBagSimulatorsDir
Definition: Environment.hpp:107
Definition: ApplicationException.hpp:47
static std::string m_ProvidedExamplesDir
Definition: Environment.hpp:99
static std::string getMarketBagObserversDir()
Definition: Environment.hpp:494
static std::string m_MarketBagBinSubDir
Definition: Environment.hpp:115
static int m_IdealThreadCount
Definition: Environment.hpp:125
static std::string m_Version
Definition: Environment.hpp:71
static std::string getUserDataDir()
Definition: Environment.hpp:248
static std::string m_MarketBagDataDir
Definition: Environment.hpp:113
static std::string m_UserName
Definition: Environment.hpp:69
static std::string m_ConfigFile
Definition: Environment.hpp:85
static std::string getAppResourcesDir(const std::string &AppName)
Definition: Environment.hpp:328
static std::string m_UserHomeDir
Definition: Environment.hpp:81
static std::string getUserDataFullPath(const std::string &Path)
Definition: Environment.hpp:258
static std::string getUserName()
Definition: Environment.hpp:183
static std::vector< std::string > getExtraObserversDirs()
Definition: Environment.hpp:408
static std::string getHostName()
Definition: Environment.hpp:146
static std::string m_VersionFull
Definition: Environment.hpp:73
#define OPENFLUID_API
Definition: dllexport.hpp:86
static std::string getConfigFile()
Definition: Environment.hpp:290
static std::string getVersionFull()
Definition: Environment.hpp:201
static std::vector< std::string > m_ExtraObserversDirs
Definition: Environment.hpp:93
static std::string m_MarketBagBuilderextsDir
Definition: Environment.hpp:111
static std::vector< std::string > getDefaultObserversDirs()
Definition: Environment.hpp:399
static std::string getTranslationsDir()
Definition: Environment.hpp:299
static std::vector< std::string > m_ExtraSimulatorsDirs
Definition: Environment.hpp:89
static std::string m_UserDataDir
Definition: Environment.hpp:83
static std::string m_UserExamplesDir
Definition: Environment.hpp:101
static std::string m_VersionMajorMinor
Definition: Environment.hpp:75
static std::string getMarketBagDir()
Definition: Environment.hpp:489
static std::string getUserExamplesDir()
Definition: Environment.hpp:267
static std::string m_AppsResourcesDir
Definition: Environment.hpp:123
static std::string getAppResourcesFullPath(const std::string &AppName, const std::string &Path)
Definition: Environment.hpp:340
static std::string m_MarketBagObserversDir
Definition: Environment.hpp:109