λ61
Loading...
Searching...
No Matches
l61::RosettaSystem::EnvironmentVariable Class Referencefinal

A utility class for accessing environment variables by name. More...

#include <EnvironmentVariable.hpp>

Inheritance diagram for l61::RosettaSystem::EnvironmentVariable:
l61::Object

Public Member Functions

 EnvironmentVariable (const std::string &name)
 Constructs an EnvironmentVariable object with the given name.
std::string getValue () const
 Retrieves the value of the environment variable.
std::string get (const std::string &defaultValue="") const
 Retrieves the value of the environment variable, or returns a default.
bool exists () const
 Checks if the environment variable exists.
const std::string & getKey () const
 Retrieves the name (key) of the environment variable.
std::string toString () const override
 Returns a human-readable string representation of the object.
std::size_t hashCode () const override
 Computes a hash code for this environment variable.
nlohmann::json toJsonValue () const override
 Serializes the object into JSON form.
bool operator== (const EnvironmentVariable &other) const
 Equality operator for EnvironmentVariable objects.
 EnvironmentVariable (const EnvironmentVariable &environment_variable)
 EnvironmentVariable (EnvironmentVariable &&environment_variable) noexcept
 ~EnvironmentVariable () override=default
Public Member Functions inherited from l61::Object
virtual ~Object ()=default
std::string typeName () const
 Returns the demangled name of the type.
const std::type_info & typeInfo () const
 Returns RTTI type information object.
 operator std::string () const
 Explicit conversion operator to std::string.
 operator nlohmann::json () const
 Explicit conversion operator to nlohmann::json.

Static Public Member Functions

static EnvironmentVariable of (const std::string &name)

Private Attributes

std::string name_

Detailed Description

A utility class for accessing environment variables by name.

This class provides a clean interface to query, check, and retrieve environment variables. It does not modify or set environment variables, only reads them.

Constructor & Destructor Documentation

◆ EnvironmentVariable() [1/3]

l61::RosettaSystem::EnvironmentVariable::EnvironmentVariable ( const std::string & name)
explicit

Constructs an EnvironmentVariable object with the given name.

Parameters
nameThe name of the environment variable.

◆ EnvironmentVariable() [2/3]

l61::RosettaSystem::EnvironmentVariable::EnvironmentVariable ( const EnvironmentVariable & environment_variable)

◆ EnvironmentVariable() [3/3]

l61::RosettaSystem::EnvironmentVariable::EnvironmentVariable ( EnvironmentVariable && environment_variable)
noexcept

◆ ~EnvironmentVariable()

l61::RosettaSystem::EnvironmentVariable::~EnvironmentVariable ( )
overridedefault

Member Function Documentation

◆ exists()

bool l61::RosettaSystem::EnvironmentVariable::exists ( ) const

Checks if the environment variable exists.

Returns
true if the environment variable exists, false otherwise.

Example:

EnvironmentVariable editor("EDITOR");
if (editor.exists()) {
std::cout << "EDITOR is set." << std::endl;
}
EnvironmentVariable(const std::string &name)
Constructs an EnvironmentVariable object with the given name.
Definition EnvironmentVariable.cpp:29

◆ get()

std::string l61::RosettaSystem::EnvironmentVariable::get ( const std::string & defaultValue = "") const

Retrieves the value of the environment variable, or returns a default.

Parameters
defaultValueThe value to return if the environment variable does not exist.
Returns
The value of the environment variable if it exists, otherwise defaultValue.

Example:

EnvironmentVariable home("HOME");
std::string homeValue = home.get("/tmp");

◆ getKey()

const std::string & l61::RosettaSystem::EnvironmentVariable::getKey ( ) const

Retrieves the name (key) of the environment variable.

Returns
A constant reference to the name of the environment variable.

Example:

EnvironmentVariable var("LANG");
std::cout << "Variable key: " << var.getKey() << std::endl;

◆ getValue()

std::string l61::RosettaSystem::EnvironmentVariable::getValue ( ) const

Retrieves the value of the environment variable.

Returns
The value of the environment variable as a std::string.
Exceptions
std::runtime_errorif the environment variable does not exist.

Example:

EnvironmentVariable path("PATH");
std::string pathValue = path.getValue();

◆ hashCode()

std::size_t l61::RosettaSystem::EnvironmentVariable::hashCode ( ) const
overridevirtual

Computes a hash code for this environment variable.

The hash is derived from the variable's name, making it suitable for use in hash-based containers (e.g., std::unordered_map).

Returns
A std::size_t value representing the hash code of the variable.

Example:

EnvironmentVariable var("LANG");
std::size_t hash = var.hashCode();

Reimplemented from l61::Object.

◆ of()

EnvironmentVariable l61::RosettaSystem::EnvironmentVariable::of ( const std::string & name)
inlinestatic

◆ operator==()

bool l61::RosettaSystem::EnvironmentVariable::operator== ( const EnvironmentVariable & other) const

Equality operator for EnvironmentVariable objects.

Two EnvironmentVariable objects are considered equal if they reference the same variable name.

Parameters
otherAnother EnvironmentVariable to compare with.
Returns
true if both objects reference the same environment variable name, false otherwise.

Example:

if (a == b) {
std::cout << "Both refer to the same environment variable." << std::endl;
}

◆ toJsonValue()

nlohmann::json l61::RosettaSystem::EnvironmentVariable::toJsonValue ( ) const
overridevirtual

Serializes the object into JSON form.

Intended for persistence, logging, or communication. Derived classes should override this to produce structured JSON output representing their state.

Returns
nlohmann::json JSON representation of the object.

Reimplemented from l61::Object.

◆ toString()

std::string l61::RosettaSystem::EnvironmentVariable::toString ( ) const
overridevirtual

Returns a human-readable string representation of the object.

Derived classes should override this to provide a meaningful textual description of their internal state. Default implementation may just return the type name or placeholder text.

Returns
std::string textual representation of the object.

Reimplemented from l61::Object.

Member Data Documentation

◆ name_

std::string l61::RosettaSystem::EnvironmentVariable::name_
private

The documentation for this class was generated from the following files: