53 [[nodiscard]] std::string
get_var(
const std::string &sVar)
const {
54 const auto pIter = this->m_mVariables.find(sVar);
55 return pIter != this->m_mVariables.end() ? pIter->second :
"";
64 [[nodiscard]] std::string
get_var_hop2(
const std::string &sVar)
const {
65 const auto pIter1 = this->m_mVariables.find(sVar);
66 if (pIter1 == this->m_mVariables.end())
return "";
67 const auto pIter2 = this->m_mVariables.find(pIter1->second);
68 return pIter2 != this->m_mVariables.end() ? pIter2->second :
"";
76 void set_var(std::string sVar, std::string sValue) {
77 this->m_mVariables.insert_or_assign(std::move(sVar), std::move(sValue));
85 [[nodiscard]]
bool has_var(
const std::string &sVar)
const noexcept {
86 return this->m_mVariables.contains(sVar);
94 return this->m_mVariables.size();
101 [[nodiscard]]
const std::unordered_map<std::string, std::string, shell_hash> &
get_var() const noexcept {
102 return this->m_mVariables;
107 std::unordered_map<std::string, std::string, shell_hash> m_mVariables;
Represents a variable map for shell commands.
Definition shell_var.h:42
void set_var(std::string sVar, std::string sValue)
Sets the value of a variable.
Definition shell_var.h:76
std::string get_var_hop2(const std::string &sVar) const
Retrieves the value of a variable, whose value is another variable (1-hop resolution).
Definition shell_var.h:64
const std::unordered_map< std::string, std::string, shell_hash > & get_var() const noexcept
Retrieves all variables.
Definition shell_var.h:101
bool has_var(const std::string &sVar) const noexcept
Checks if a variable exists.
Definition shell_var.h:85
std::string get_var(const std::string &sVar) const
Retrieves the value of a variable.
Definition shell_var.h:53
shell_var()=default
Default constructor.
std::size_t get_var_size() const noexcept
Gets the number of variables.
Definition shell_var.h:93
BashSpark main namespace.
Definition command.h:39
Defines the bs::shell_hash functor implementing a 64-bit FNV-1a hash.