Manual for OpenFLUID 2.1.10

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  return m_UserDataDir + "/" + Path;
263  }
264 
265  /**
266  Returns the full path of the examples directory for the current user
267  @return the full path to the directory
268  */
269  static std::string getUserExamplesDir()
270  {
271  return m_UserExamplesDir;
272  }
273 
274  /**
275  Returns the full path of the example simulators directory
276  @return the full path to the directory
277  */
278  static std::string getUserExampleSimulatorsDir()
279  {
280  return m_UserExampleSimulatorsDir;
281  }
282 
283  /**
284  Returns the full path of the directory where examples provided by OpenFLUID or models installations are stored
285  @return the full path to the directory
286  */
287  static std::string getProvidedExamplesDir()
288  {
289  return m_ProvidedExamplesDir;
290  }
291 
292  /**
293  Automatically prepares the user data directory
294  */
295  static void prepareUserDataDirectory();
296 
297  /**
298  Returns the configuration file path for the current user
299  @return the full path to the file
300  */
301  static std::string getConfigFile()
302  {
303  return m_ConfigFile;
304  }
305 
306  /**
307  Returns the OpenFLUID translations directory
308  @return the full path to the directory
309  */
310  static std::string getTranslationsDir()
311  {
312  return m_TranslationsDir;
313  }
314 
315  /**
316  Returns the OpenFLUID common resources directory
317  @return the full path to the directory
318  */
319  static std::string getCommonResourcesDir()
320  {
321  return m_CommonResourcesDir;
322  }
323 
324  /**
325  Returns the full path of a file or directory relative to the OpenFLUID common resources directory
326  @param[in] Path the path relative to the OpenFLUID common resources directory
327  @return the full path to the file or directory
328  */
329  static std::string getCommonResourcesFullPath(const std::string& Path)
330  {
331  return m_CommonResourcesDir + "/" + Path;
332  }
333 
334  /**
335  Returns the resources directory for a given OpenFLUID software application
336  @param[in] AppName the name of the OpenFLUID application
337  @return the full path to the directory
338  */
339  static std::string getAppResourcesDir(const std::string& AppName)
340  {
341  return m_AppsResourcesDir + "/" + AppName;
342  }
343 
344  /**
345  Returns the full path of a file or directory relative to the resources directory
346  of a given OpenFLUID software application
347  @param[in] AppName the name of the OpenFLUID application
348  @param[in] Path the path relative to the OpenFLUID application resources directory
349  @return the full path to the file or directory
350  */
351  static std::string getAppResourcesFullPath(const std::string& AppName, const std::string& Path)
352  {
353  return getAppResourcesDir(AppName) + "/" + Path;
354  }
355 
356  /**
357  Returns the list of directories full paths where OpenFLUID searches for simulators.
358  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
359  @return the list of directories full paths
360  */
361  static std::vector<std::string> getSimulatorsDirs();
362 
363  /**
364  Returns the list of default directories full paths where OpenFLUID searches for simulators.
365  @return the list of directories full paths
366  */
367  static std::vector<std::string> getDefaultSimulatorsDirs()
368  {
369  return m_DefaultSimulatorsDirs;
370  }
371 
372  /**
373  Returns the list of extra added directories full paths where OpenFLUID searches for simulators.
374  @return the list of directories full paths
375  */
376  static std::vector<std::string> getExtraSimulatorsDirs()
377  {
378  return m_ExtraSimulatorsDirs;
379  }
380 
381  /**
382  Adds paths to the list of directories where OpenFLUID searches for simulators.
383  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
384  @param[in] Paths the list of full paths as a single string
385  */
386  static void addExtraSimulatorsDirs(const std::string& Paths);
387 
388  /**
389  Resets the list of extra directories where OpenFLUID searches for simulators to empty
390  */
391  static void resetExtraSimulatorsDirs();
392 
393  /**
394  Returns the full path of a searched simulator file
395  @return the full path of the searched file, empty if not found
396  */
397  static std::string getSimulatorFullPath(const std::string& Filename);
398 
399  /**
400  Returns the list of directories full paths where OpenFLUID searches for observers.
401  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
402  @return the list of directories full paths
403  */
404  static std::vector<std::string> getObserversDirs();
405 
406  /**
407  Returns the list of default directories full paths where OpenFLUID searches for observers.
408  @return the list of directories full paths
409  */
410  static std::vector<std::string> getDefaultObserversDirs()
411  {
412  return m_DefaultObserversDirs;
413  }
414 
415  /**
416  Returns the list of extra added directories full paths where OpenFLUID searches for observers.
417  @return the list of directories full paths
418  */
419  static std::vector<std::string> getExtraObserversDirs()
420  {
421  return m_ExtraObserversDirs;
422  }
423 
424  /**
425  Adds paths to the list of directories where OpenFLUID searches for observers.
426  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
427  @param[in] Paths the list of full paths as a single string
428  */
429  static void addExtraObserversDirs(const std::string& Paths);
430 
431  /**
432  Resets the list of extra directories where OpenFLUID searches for observers to empty
433  */
434  static void resetExtraObserversDirs();
435 
436  /**
437  Returns the full path of a searched observer file
438  @return the full path of the searched file, empty if not found
439  */
440  static std::string getObserverFullPath(const std::string& Filename);
441 
442  /**
443  Returns the list of directories full paths where OpenFLUID searches for builder-extensions.
444  Extra directories added at run time are at the beginning of the list, followed by standard search paths.
445  @return the list of directories full paths
446  */
447  static std::vector<std::string> getBuilderextsDirs();
448 
449  /**
450  Returns the list of default directories full paths where OpenFLUID searches for builder-extensions.
451  @return the list of directories full paths
452  */
453  static std::vector<std::string> getDefaultBuilderextsDirs()
454  {
455  return m_DefaultBuilderextsDirs;
456  }
457 
458  /**
459  Returns the list of extra added directories full paths where OpenFLUID searches for builder-extensions.
460  @return the list of directories full paths
461  */
462  static std::vector<std::string> getExtraBuilderextsDirs()
463  {
464  return m_ExtraBuilderextsDirs;
465  }
466 
467  /**
468  Adds paths to the list of directories where OpenFLUID searches for builder-extensions.
469  The paths are given as a single string of paths separated by ":" (on Unices systems) or ";" (on Windows systems)
470  @param[in] Paths the list of full paths as a single string
471  */
472  static void addExtraBuilderextsDirs(const std::string& Paths);
473 
474  /**
475  Resets the list of extra directories where OpenFLUID searches for builder-extensions to empty
476  */
477  static void resetExtraBuilderextsDirs();
478 
479  /**
480  Returns the full path of a searched builder-extension file
481  @return the full path of the searched file, empty if not found
482  */
483  static std::string getBuilderextFullPath(const std::string& Filename);
484 
485  static std::string getMarketBagBinSubDir()
486  {
487  return m_MarketBagBinSubDir;
488  }
489 
490  static std::string getMarketBagBuilderextsDir()
491  {
492  return m_MarketBagBuilderextsDir;
493  }
494 
495  static std::string getMarketBagDataDir()
496  {
497  return m_MarketBagDataDir;
498  }
499 
500  static std::string getMarketBagDir()
501  {
502  return m_MarketBagDir;
503  }
504 
505  static std::string getMarketBagObserversDir()
506  {
507  return m_MarketBagObserversDir;
508  }
509 
510  static std::string getMarketBagSimulatorsDir()
511  {
512  return m_MarketBagSimulatorsDir;
513  }
514 
515  static std::string getMarketBagSrcSubDir()
516  {
517  return m_MarketBagSrcSubDir;
518  }
519 
520  static std::string getMarketBagVersionDir()
521  {
522  return m_MarketBagVersionDir;
523  }
524 };
525 
526 
527 } } // namespaces
528 
529 
530 #endif /* __OPENFLUID_BASE_ENVIRONMENT_HPP__ */
Definition: ApplicationException.hpp:47
static std::string m_MarketBagSimulatorsDir
Definition: Environment.hpp:109
static std::string getUserExamplesDir()
Definition: Environment.hpp:269
static std::string m_TranslationsDir
Definition: Environment.hpp:121
static std::string m_MarketBagBuilderextsDir
Definition: Environment.hpp:113
static std::string m_UserName
Definition: Environment.hpp:69
static std::string getTranslationsDir()
Definition: Environment.hpp:310
static std::string getUserExampleSimulatorsDir()
Definition: Environment.hpp:278
static std::string m_SystemArch
Definition: Environment.hpp:65
static std::string getVersionFull()
Definition: Environment.hpp:203
static std::string getUserHomeDir()
Definition: Environment.hpp:241
static std::vector< std::string > m_ExtraBuilderextsDirs
Definition: Environment.hpp:97
static std::string getConfigFile()
Definition: Environment.hpp:301
static std::string getMarketBagSrcSubDir()
Definition: Environment.hpp:515
Environment()
Definition: Environment.hpp:129
static std::string m_ConfigFile
Definition: Environment.hpp:85
static int getIdealJobsCount()
Definition: Environment.hpp:176
static std::string getMarketBagDir()
Definition: Environment.hpp:500
static std::string getInstallPrefix()
Definition: Environment.hpp:232
static std::string getProvidedExamplesDir()
Definition: Environment.hpp:287
static std::string getUserName()
Definition: Environment.hpp:185
static std::string m_InstallPrefix
Definition: Environment.hpp:77
static std::vector< std::string > getDefaultSimulatorsDirs()
Definition: Environment.hpp:367
static int getIdealThreadCount()
Definition: Environment.hpp:167
static std::vector< std::string > getDefaultObserversDirs()
Definition: Environment.hpp:410
static std::string getAppResourcesDir(const std::string &AppName)
Definition: Environment.hpp:339
static std::string getAppResourcesFullPath(const std::string &AppName, const std::string &Path)
Definition: Environment.hpp:351
static std::string getMarketBagBuilderextsDir()
Definition: Environment.hpp:490
static std::string getUserDataDir()
Definition: Environment.hpp:250
static std::string getSystemArch()
Definition: Environment.hpp:158
static std::string getMarketBagObserversDir()
Definition: Environment.hpp:505
static std::string getMarketBagBinSubDir()
Definition: Environment.hpp:485
static std::vector< std::string > m_DefaultSimulatorsDirs
Definition: Environment.hpp:87
static std::vector< std::string > m_DefaultBuilderextsDirs
Definition: Environment.hpp:95
static std::vector< std::string > getExtraObserversDirs()
Definition: Environment.hpp:419
static std::string getHostName()
Definition: Environment.hpp:148
static std::string getUserDataFullPath(const std::string &Path)
Definition: Environment.hpp:260
static std::string m_CommonResourcesDir
Definition: Environment.hpp:123
static std::string m_VersionFull
Definition: Environment.hpp:73
static std::string m_UserExamplesDir
Definition: Environment.hpp:101
static std::string m_VersionMajorMinor
Definition: Environment.hpp:75
static std::string m_MarketBagBinSubDir
Definition: Environment.hpp:117
static std::string m_Version
Definition: Environment.hpp:71
static std::string getMarketBagSimulatorsDir()
Definition: Environment.hpp:510
static std::vector< std::string > getDefaultBuilderextsDirs()
Definition: Environment.hpp:453
static std::string getCommonResourcesFullPath(const std::string &Path)
Definition: Environment.hpp:329
static std::string getMarketBagDataDir()
Definition: Environment.hpp:495
static std::string getVersionMajorMinor()
Definition: Environment.hpp:212
Definition: Environment.hpp:52
static std::string m_UserDataDir
Definition: Environment.hpp:83
static std::string m_ProvidedExamplesDir
Definition: Environment.hpp:99
static std::string m_MarketBagSrcSubDir
Definition: Environment.hpp:119
static int m_IdealThreadCount
Definition: Environment.hpp:127
static std::vector< std::string > getExtraBuilderextsDirs()
Definition: Environment.hpp:462
static std::string m_UserExampleSimulatorsDir
Definition: Environment.hpp:103
static std::string m_AppsResourcesDir
Definition: Environment.hpp:125
#define OPENFLUID_API
Definition: dllexport.hpp:86
static std::string m_MarketBagVersionDir
Definition: Environment.hpp:107
static std::vector< std::string > m_DefaultObserversDirs
Definition: Environment.hpp:91
static std::string getCommonResourcesDir()
Definition: Environment.hpp:319
static std::string getTempDir()
Definition: Environment.hpp:222
static std::string m_HostName
Definition: Environment.hpp:67
static std::vector< std::string > m_ExtraSimulatorsDirs
Definition: Environment.hpp:89
static std::vector< std::string > m_ExtraObserversDirs
Definition: Environment.hpp:93
static std::vector< std::string > getExtraSimulatorsDirs()
Definition: Environment.hpp:376
static std::string m_MarketBagDataDir
Definition: Environment.hpp:115
static std::string m_MarketBagObserversDir
Definition: Environment.hpp:111
static std::string m_MarketBagDir
Definition: Environment.hpp:105
static std::string m_UserHomeDir
Definition: Environment.hpp:81
static std::string getVersion()
Definition: Environment.hpp:194
static std::string m_TempDir
Definition: Environment.hpp:79
static std::string getMarketBagVersionDir()
Definition: Environment.hpp:520