Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ApplicationInfo.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ApplicationInfo.cc (C) 2000-2025 */
9/* */
10/* Information about an application. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ApplicationInfo.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/CommandLineArguments.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/List.h"
19#include "arccore/common/internal/Property.h"
20#include "arcane/utils/internal/ApplicationInfoProperties.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class ApplicationInfoPrivate
32{
33 public:
34 ApplicationInfoPrivate(const CommandLineArguments& args,const String& name,
35 const VersionInfo& version)
36 : m_command_line_args(args), m_version(version), m_is_debug(false), m_application_name(name)
37 {
38 }
39 public:
40 CommandLineArguments m_command_line_args;
41 VersionInfo m_version; //!< Version number
42 bool m_is_debug; //!< \a true if it is a debug version.
43 String m_version_date; //!< Version date.
44 String m_application_name; //!< Application name
45 String m_code_name; //!< Code name
46 String m_target_full_name; //!< Full target name
47 String m_osname; //!< OS name
48 String m_data_os_dir; //!< Directory of OS-dependent config files
49 String m_data_dir; //!< Directory of common config files
50 StringList m_args;
51 StringList m_dynamic_libraries_name;
52 UniqueArray<std::byte> m_runtime_config_file_content;
53};
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58ApplicationInfo::
59ApplicationInfo()
60: m_argc(nullptr)
61, m_argv(nullptr)
63{
64 _init("Arcane");
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70ApplicationInfo::
71ApplicationInfo(int* argc,char*** argv,const String& name,const VersionInfo& aversion)
72: m_argc(nullptr)
73, m_argv(nullptr)
74, m_p(new ApplicationInfoPrivate(CommandLineArguments(argc,argv),name,aversion))
75{
76 _init(name);
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82ApplicationInfo::
83ApplicationInfo(const StringList& aargs,const String& name,
84 const VersionInfo& aversion)
85: m_argc(nullptr)
86, m_argv(nullptr)
87, m_p(new ApplicationInfoPrivate(CommandLineArguments(aargs),name,aversion))
88{
89 _init(name);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95ApplicationInfo::
96ApplicationInfo(const CommandLineArguments& aargs,const String& name,
97 const VersionInfo& aversion)
98: m_argc(nullptr)
99, m_argv(nullptr)
100, m_p(new ApplicationInfoPrivate(aargs,name,aversion))
101{
102 _init(name);
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108ApplicationInfo::
109ApplicationInfo(const ApplicationInfo& rhs)
110: m_argc(nullptr)
111, m_argv(nullptr)
112, m_p(new ApplicationInfoPrivate(*rhs.m_p))
113{
114 _setArgs();
115}
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120ApplicationInfo& ApplicationInfo::
121operator=(const ApplicationInfo& rhs)
122{
123 if (&rhs!=this){
124 auto old_p = m_p;
125 m_p = new ApplicationInfoPrivate(*rhs.m_p);
126 delete old_p;
127 _setArgs();
128 }
129 return *this;
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135ApplicationInfo::
136~ApplicationInfo()
137{
138 delete m_p;
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144void ApplicationInfo::
145_setArgs()
146{
147 m_argc = m_p->m_command_line_args.commandLineArgc();
148 m_argv = m_p->m_command_line_args.commandLineArgv();
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154void ApplicationInfo::
155_init(const String& name)
156{
157 _setArgs();
158
159 m_p->m_version_date = "0";
160 m_p->m_data_os_dir = String();
161 m_p->m_data_dir = String();
162
163 {
164 String s = platform::getEnvironmentVariable("ARCANE_USER_CONFIG_FILE_NAME");
165 if (!s.null())
166 m_p->m_code_name = s;
167 else
168 m_p->m_code_name = name;
169 }
170
171 {
172 String s = platform::getEnvironmentVariable("ARCANE_SHARE_PATH");
173 if (!s.null())
174 m_p->m_data_dir = s;
175 else{
176 s = platform::getEnvironmentVariable("STDENV_PATH_SHR");
177 if (!s.null())
178 m_p->m_data_dir = s;
179 }
180 }
181 {
182 String s = platform::getEnvironmentVariable("ARCANE_LIB_PATH");
183 if (!s.null())
184 m_p->m_data_os_dir = s;
185 else{
186 String s = platform::getEnvironmentVariable("STDENV_PATH_LIB");
187 if (!s.null())
188 m_p->m_data_os_dir = s;
189 }
190 }
191
192 if (dataDir().null() || dataOsDir().null()){
193 // Assumes that shared info and libs are
194 // in the same place as the executable.
195 String exe_full_path = platform::getExeFullPath();
196 String exe_path = platform::getFileDirName(exe_full_path);
197 if (dataDir().null())
198 setDataDir(exe_path);
199 if (dataOsDir().null())
200 setDataOsDir(exe_path);
201 }
202
203 m_p->m_target_full_name = "TargetUnknown";
204
205#ifdef ARCANE_DEBUG
206 m_p->m_is_debug = true;
207#else
208 m_p->m_is_debug = false;
209#endif
210}
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
216applicationName() const
217{
218 return m_p->m_application_name;
219}
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
225codeVersion() const
226{
227 return m_p->m_version;
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
234dataOsDir() const
235{
236 return m_p->m_data_os_dir;
237}
238
240setDataOsDir(const String& v)
241{
242 m_p->m_data_os_dir = v;
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
249dataDir() const
250{
251 return m_p->m_data_dir;
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
258setDataDir(const String& v)
259{
260 m_p->m_data_dir = v;
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
267versionMajor() const
268{
269 return m_p->m_version.versionMajor();
270}
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
276versionMinor() const
277{
278 return m_p->m_version.versionMinor();
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
285versionPatch() const
286{
287 return m_p->m_version.versionPatch();
288}
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
292
294isDebug() const
295{
296 return m_p->m_is_debug;
297}
298
299/*---------------------------------------------------------------------------*/
300/*---------------------------------------------------------------------------*/
301
303codeName() const
304{
305 return m_p->m_code_name;
306}
307
308/*---------------------------------------------------------------------------*/
309/*---------------------------------------------------------------------------*/
310
312targetFullName() const
313{
314 return m_p->m_target_full_name;
315}
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
320int* ApplicationInfo::
321commandLineArgc() const
322{
323 return m_argc;
324}
325
326/*---------------------------------------------------------------------------*/
327/*---------------------------------------------------------------------------*/
328
329char*** ApplicationInfo::
330commandLineArgv() const
331{
332 return m_argv;
333}
334
335/*---------------------------------------------------------------------------*/
336/*---------------------------------------------------------------------------*/
337
339args(StringList& aargs) const
340{
341 m_p->m_command_line_args.fillArgs(aargs);
342}
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
346
348addDynamicLibrary(const String& lib_name)
349{
350 m_p->m_dynamic_libraries_name.add(lib_name);
351}
352
353/*---------------------------------------------------------------------------*/
354/*---------------------------------------------------------------------------*/
355
358{
359 return m_p->m_dynamic_libraries_name;
360}
361
362/*---------------------------------------------------------------------------*/
363/*---------------------------------------------------------------------------*/
364
367{
368 return m_p->m_command_line_args;
369}
370
371/*---------------------------------------------------------------------------*/
372/*---------------------------------------------------------------------------*/
373
376{
377 m_p->m_application_name = v;
378}
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
382
385{
386 m_p->m_version = version;
387}
388
389/*---------------------------------------------------------------------------*/
390/*---------------------------------------------------------------------------*/
391
393setCodeName(const String& code_name)
394{
395 m_p->m_code_name = code_name;
396}
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
403{
404 m_p->m_command_line_args = aargs;
405 _setArgs();
406}
407
408/*---------------------------------------------------------------------------*/
409/*---------------------------------------------------------------------------*/
410
412setIsDebug(bool v)
413{
414 m_p->m_is_debug = v;
415}
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
422{
423 m_p->m_runtime_config_file_content = content;
424}
425
426/*---------------------------------------------------------------------------*/
427/*---------------------------------------------------------------------------*/
428
431{
432 return m_p->m_runtime_config_file_content;
433}
434
435/*---------------------------------------------------------------------------*/
436/*---------------------------------------------------------------------------*/
437
439addParameterLine(const String& line)
440{
441 m_p->m_command_line_args.addParameterLine(line);
442}
443
444/*---------------------------------------------------------------------------*/
445/*---------------------------------------------------------------------------*/
446
447/*---------------------------------------------------------------------------*/
448/*---------------------------------------------------------------------------*/
449
450template<typename V> void ApplicationInfoProperties::
451_applyPropertyVisitor(V& p)
452{
453 auto b = p.builder();
454
455 p << b.addString("CodeName")
456 .addDescription("Name of the code")
457 .addGetter([](auto a) { return a.x.codeName(); })
458 .addSetter([](auto a) { a.x.setCodeName(a.v); });
459
460 p << b.addString("DataDir")
461 .addDescription("Directory containing os independant files")
462 .addGetter([](auto a) { return a.x.dataDir(); })
463 .addSetter([](auto a) { a.x.setDataDir(a.v); });
464
465 p << b.addString("DataOsDir")
466 .addDescription("Directory containing os dependant files")
467 .addGetter([](auto a) { return a.x.dataOsDir(); })
468 .addSetter([](auto a) { a.x.setDataOsDir(a.v); });
469
470 p << b.addBool("Debug")
471 .addDescription("Indicate if debug mode is active")
472 .addGetter([](auto a) { return a.x.isDebug(); })
473 .addSetter([](auto a) { a.x.setIsDebug(a.v); });
474
475 p << b.addString("CodeVersion")
476 .addDescription("Version (x.y.z) of the code")
477 .addSetter([](auto a) { a.x.setCodeVersion(VersionInfo(a.v)); })
478 .addGetter([](auto a) { return a.x.codeVersion().versionAsString(); });
479
480 p << b.addStringList("DynamicLibraries")
481 .addDescription("Dynamic libraries to load at startup")
482 .addSetter([](auto a)
483 {
484 for(String s : a.v)
485 a.x.addDynamicLibrary(s);
486 })
487 .addGetter([](auto a) { return a.x.dynamicLibrariesName(); });
488}
489
490/*---------------------------------------------------------------------------*/
491/*---------------------------------------------------------------------------*/
492
493ARCANE_REGISTER_PROPERTY_CLASS(ApplicationInfoProperties,());
494
495/*---------------------------------------------------------------------------*/
496/*---------------------------------------------------------------------------*/
497
498} // End namespace Arcane
499
500/*---------------------------------------------------------------------------*/
501/*---------------------------------------------------------------------------*/
String m_target_full_name
Full target name.
bool m_is_debug
true if it is a debug version.
String m_data_os_dir
Directory of OS-dependent config files.
String m_data_dir
Directory of common config files.
VersionInfo m_version
Version number.
String m_version_date
Version date.
String m_application_name
Application name.
Application information.
const String & dataDir() const
Returns the path where data files are located.
const String & codeName() const
Returns the name of the calculation code linked to the application.
void setCommandLineArguments(const CommandLineArguments &args)
Sets the command line arguments.
int * m_argc
Number of command line arguments.
void addParameterLine(const String &line)
Adds an Arcane parameter to the command line.
void setCodeVersion(const VersionInfo &version_info)
Sets the version number.
ByteConstSpan runtimeConfigFileContent() const
Application configuration file content.
void setDataDir(const String &v)
Sets the path where data files are located.
void setIsDebug(bool v)
Sets the debug state.
const String & applicationName() const
Application name.
void addDynamicLibrary(const String &lib_name)
Adds the library lib_name to the list of dynamically loaded libraries.
int versionMajor() const
Returns the major version number of the application.
int versionMinor() const
Returns the minor version number of the application.
const String & targetFullName() const
Returns the full target name.
const CommandLineArguments & commandLineArguments() const
Command line arguments.
void args(StringList &args) const
Fills args with command line arguments.
const VersionInfo & codeVersion() const
Version number.
const VersionInfo & version() const
Version number.
char *** m_argv
Array of command line arguments.
int versionPatch() const
Returns the patch version number of the application.
void setApplicationName(const String &v)
Sets the application name.
bool isDebug() const
Returns true if running in debug mode.
void setRuntimeConfigFileContent(ByteConstSpan content)
Sets the application configuration file content.
const String & dataOsDir() const
Returns the path where OS-dependent data files are located.
void setDataOsDir(const String &v)
Sets the path where OS-dependent data files are located.
StringCollection dynamicLibrariesName() const
List of dynamic libraries.
void setCodeName(const String &code_name)
Sets the code name.
1D data vector with value semantics (STL style).
Information about a version.
Definition VersionInfo.h:47
String getFileDirName(const String &file_name)
Returns the directory name of a file.
String getExeFullPath()
Returns the full name with the executable path.
String getEnvironmentVariable(const String &name)
Environment variable named name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Collection< String > StringCollection
Collection of strings.
Definition UtilsTypes.h:506
List< String > StringList
Unicode string list.
Definition UtilsTypes.h:509
Span< const std::byte > ByteConstSpan
Read-only view of a 1D array of characters.
Definition UtilsTypes.h:548