From 577fc0845718ed8ad5bebf02a277c0579a817f77 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 17 May 2024 17:58:38 +0200 Subject: wanda: restructure source layout --- source/lib/include/wanda/system/environment.hpp | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 source/lib/include/wanda/system/environment.hpp (limited to 'source/lib/include/wanda/system/environment.hpp') diff --git a/source/lib/include/wanda/system/environment.hpp b/source/lib/include/wanda/system/environment.hpp new file mode 100644 index 0000000..8cd9ecf --- /dev/null +++ b/source/lib/include/wanda/system/environment.hpp @@ -0,0 +1,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 + +#include +#include + +namespace wanda::system +{ + /** + * @brief A type to provide access to the runtime environment + */ + struct environment + { + using map_type = std::map; + 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 \ No newline at end of file -- cgit v1.2.3