BashSpark
Loading...
Searching...
No Matches
shell_vtable.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <memory>
32#include <string>
33#include <unordered_map>
34
35#include "shell_node.h"
37
38namespace bs {
39 class shell_node_evaluable;
40}
41
42namespace bs {
50 public:
53
54 public:
56 shell_vtable() = default;
57
58 public:
64 [[nodiscard]] const func_type* get_func(const std::string &sVar) const {
65 const auto pIter = this->m_mFunctions.find(sVar);
66 return pIter != this->m_mFunctions.end() ? pIter->second : nullptr;
67 }
68
74 void set_func(const std::string& sName, const func_type* pFunction) {
75 this->m_mFunctions[sName] = pFunction;
76 }
77
83 [[nodiscard]] bool has_func(const std::string &sName) const noexcept {
84 return this->m_mFunctions.contains(sName);
85 }
86
91 [[nodiscard]] std::size_t get_vtable_size() const noexcept {
92 return this->m_mFunctions.size();
93 }
94
99 [[nodiscard]] const std::unordered_map<std::string, const func_type*, shell_hash> &get_env() const noexcept {
100 return this->m_mFunctions;
101 }
102
103 private:
105 std::unordered_map<std::string, const func_type*, shell_hash> m_mFunctions;
106 };
107} // namespace bs
Base interface for nodes that can be evaluated (executed).
Definition shell_node.h:164
Represents an environment for shell commands.
Definition shell_vtable.h:49
std::size_t get_vtable_size() const noexcept
Gets the number of functions in the vtable.
Definition shell_vtable.h:91
bool has_func(const std::string &sName) const noexcept
Checks if a function exists.
Definition shell_vtable.h:83
shell_vtable()=default
Default constructor (empty environment).
const func_type * get_func(const std::string &sVar) const
Gets a function.
Definition shell_vtable.h:64
void set_func(const std::string &sName, const func_type *pFunction)
Sets the a function.
Definition shell_vtable.h:74
const std::unordered_map< std::string, const func_type *, shell_hash > & get_env() const noexcept
Retrieves all environment variables.
Definition shell_vtable.h:99
BashSpark main namespace.
Definition command.h:39
Defines the bs::shell_hash functor implementing a 64-bit FNV-1a hash.
Defines the shell node hierarchy used by the parser.