ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
environment.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_system of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace system {
9
10//==================================================================================================
11/// Simple struct providing one static method that reads an environment variable into an
12/// \alib string-type.
13///
14/// While under POSIX-compatible operating systems, environment variable names are
15/// case-sensitive, under Microsoft windows they are not.
16//==================================================================================================
18 /// Reads an environment variable into an \alib string.
19 ///
20 /// \attention
21 /// 1. While under POSIX-compatible operating systems, environment variable names are
22 /// case-sensitive, under Microsoft windows they are not.
23 /// <br><br>
24 /// 2. As documented with
25 /// \https{std::getenv,en.cppreference.com/w/cpp/utility/program/getenv}, the operation is
26 /// not thread-safe against changes of the environment in parallel threads.
27 ///
28 /// \note
29 /// When path-variables are requested, usually instead of passing an #"%AString" for parameter
30 /// \p{target}, a reference of type #"system::Path" may be given, which is derived
31 /// from class #"%AString".
32 /// However, compatibility of both types depend on the platform and compilation flags
33 /// of the \alibbuild: The character-type of class #"%Path" equals C++ standard type
34 /// <c>std::filesystem::path::value_type</c>, while the one of #"%AString" depends on
35 /// configuration macro #"ALIB_CHARACTERS_WIDE". On GNU/Linux and MacOS, both default to
36 /// #"characters::nchar", on WindowsOS both default to #"characters::wchar" and as such
37 /// compatibility is given with the defaults. If compilation of \alib is explicitly switched
38 /// to use a different character type, then conversion has to be performed.<br><p>
39 /// \note
40 /// Class #"system::Path" provides built-in mechanics that uses the environment
41 /// to retrieve certain default paths, and that performs conversion when necessary
42 /// internally.
43 ///
44 /// @param varName The name of the variable to be retrieved.
45 /// @param target An AString to write the result to.
46 /// @param targetData If \c CurrentData::Keep, the parameter \p{target} is not cleared
47 /// before the result is written. Defaults to \c CurrentData::Clear.
48 /// @return \c true if variable was found.
49 ALIB_DLL static
50 bool Get( const CString& varName,
51 AString& target,
53};
54
55} // namespace alib[::system]
56
57/// Type alias in namespace #"%alib".
59
60} // namespace [alib]
#define ALIB_DLL
#define ALIB_EXPORT
@ Clear
Chooses to clear existing data.
Definition alox.cpp:14
strings::TCString< character > CString
Type alias in namespace #"%alib".
Definition cstring.hpp:399
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
system::EnvironmentVariables EnvironmentVariables
Type alias in namespace #"%alib".
static bool Get(const CString &varName, AString &target, lang::CurrentData targetData=lang::CurrentData::Clear)