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