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