blob: 8cd9ecf011c847bfb595a834cbe7cd144e4cfc62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/**
* @file environment.hpp
* @author Felix Morgner (felix.morgner@gmail.com)
* @since 1.0.0
*/
#ifndef WANDA_SYSTEM_ENVIRONMENT_HPP
#define WANDA_SYSTEM_ENVIRONMENT_HPP
#include <unistd.h>
#include <map>
#include <string>
namespace wanda::system
{
/**
* @brief A type to provide access to the runtime environment
*/
struct environment
{
using map_type = std::map<std::string, std::string>;
using iterator = map_type::iterator;
using const_iterator = map_type::const_iterator;
using reference = map_type::reference;
using const_reference = map_type::const_reference;
/**
* @brief Construct a new environment from the given string array
*/
explicit environment(char const * const * env = ::environ);
/**
* @brief Get the value of the given variable
*
* @return A mutable reference to the value of the given environment variable
*/
std::string & operator[](std::string const & variable);
/**
* @brief Get the value of the given variable
*
* @return An immutable reference to the value of the given environment variable
*/
std::string const & operator[](std::string const & variable) const;
iterator begin();
const_iterator begin() const;
const_iterator cbegin() const;
iterator end();
const_iterator end() const;
const_iterator cend() const;
private:
map_type m_cache{};
};
} // namespace wanda::system
#endif
|