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