Manual for OpenFLUID 2.1.11

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