t7x/src/client/component/command.hpp

59 lines
1.3 KiB
C++
Raw Normal View History

2022-12-30 13:17:36 -05:00
#pragma once
namespace command
{
class params
{
public:
params();
2023-03-14 14:12:50 -04:00
params(const std::string& text);
~params();
params(params&&) = delete;
params(const params&) = delete;
params& operator=(params&&) = delete;
params& operator=(const params&) = delete;
2022-12-30 13:17:36 -05:00
2023-01-09 10:53:51 -05:00
[[nodiscard]] int size() const;
[[nodiscard]] const char* get(int index) const;
[[nodiscard]] std::string join(int index) const;
2022-12-30 13:17:36 -05:00
2023-01-09 10:53:51 -05:00
[[nodiscard]] const char* operator[](const int index) const
{
return this->get(index); //
}
private:
2023-03-14 14:12:50 -04:00
bool needs_end_{false};
2023-01-09 10:53:51 -05:00
int nesting_;
};
class params_sv
{
public:
params_sv();
[[nodiscard]] int size() const;
[[nodiscard]] const char* get(int index) const;
[[nodiscard]] std::string join(int index) const;
[[nodiscard]] const char* operator[](const int index) const
2022-12-30 13:17:36 -05:00
{
return this->get(index); //
}
private:
int nesting_;
};
using command_function = std::function<void()>;
using command_param_function = std::function<void(const params&)>;
2023-01-09 10:53:51 -05:00
using sv_command_param_function = std::function<void(const params_sv&)>;
2022-12-30 13:17:36 -05:00
2023-01-02 09:18:37 -05:00
void add(const std::string& command, command_function function);
void add(const std::string& command, command_param_function function);
2023-01-09 10:53:51 -05:00
void add_sv(const std::string& command, sv_command_param_function function);
2022-12-30 13:17:36 -05:00
}