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