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