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