λ61
Loading...
Searching...
No Matches
EnvironmentVariable.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Tetex7
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18//
19// Created by tete on 09/15/2025.
20//
21#pragma once
22
23#ifndef L61_RS_ENVIRONMENT_VARIABLE_HPP
24#define L61_RS_ENVIRONMENT_VARIABLE_HPP
25#include <string>
27
29{
38 class EnvironmentVariable final : public Object
39 {
40 private:
41 std::string name_;
42 public:
43
44 static EnvironmentVariable of(const std::string& name)
45 {
46 return EnvironmentVariable(name);
47 }
48
53 explicit EnvironmentVariable(const std::string& name);
54
68 std::string getValue() const;
69
82 std::string get(const std::string& defaultValue = "") const;
83
97 bool exists() const;
98
110 const std::string& getKey() const;
111
112 std::string toString() const override;
113
128 std::size_t hashCode() const override;
129
130
131 nlohmann::json toJsonValue() const override;
132
133
152 bool operator==(const EnvironmentVariable& other) const;
153
154
155 EnvironmentVariable(const EnvironmentVariable& environment_variable);
156 EnvironmentVariable(EnvironmentVariable&& environment_variable) noexcept;
157
158 ~EnvironmentVariable() override = default;
159 };
160
161 inline EnvironmentVariable getEnv(const std::string& name)
162 {
163 return EnvironmentVariable::of(name);
164 }
165}
166
168{
169 RosettaSystem::EnvironmentVariable operator ""_env(const char* raw_str, std::size_t len);
170}
171
172#endif //ENVIRONMENTVARIABLE_HPP
Definition Object.hpp:47
A utility class for accessing environment variables by name.
Definition EnvironmentVariable.hpp:39
nlohmann::json toJsonValue() const override
Serializes the object into JSON form.
Definition EnvironmentVariable.cpp:66
std::string getValue() const
Retrieves the value of the environment variable.
Definition EnvironmentVariable.cpp:31
EnvironmentVariable(const std::string &name)
Constructs an EnvironmentVariable object with the given name.
Definition EnvironmentVariable.cpp:29
bool exists() const
Checks if the environment variable exists.
Definition EnvironmentVariable.cpp:46
std::string toString() const override
Returns a human-readable string representation of the object.
Definition EnvironmentVariable.cpp:56
static EnvironmentVariable of(const std::string &name)
Definition EnvironmentVariable.hpp:44
const std::string & getKey() const
Retrieves the name (key) of the environment variable.
Definition EnvironmentVariable.cpp:51
bool operator==(const EnvironmentVariable &other) const
Equality operator for EnvironmentVariable objects.
Definition EnvironmentVariable.cpp:74
std::size_t hashCode() const override
Computes a hash code for this environment variable.
Definition EnvironmentVariable.cpp:61
std::string name_
Definition EnvironmentVariable.hpp:41
std::string get(const std::string &defaultValue="") const
Retrieves the value of the environment variable, or returns a default.
Definition EnvironmentVariable.cpp:40
Definition EnvironmentVariable.hpp:29
EnvironmentVariable getEnv(const std::string &name)
Definition EnvironmentVariable.hpp:161
Definition EnvironmentVariable.hpp:168