Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/engine/core/include/console.hpp

52 lines
1.4 KiB
C++
Raw Normal View History

2020-09-20 22:37:15 -04:00
#pragma once
#include <string_view>
#include <functional>
#include <vector>
#include <variant>
2020-09-22 22:43:30 -04:00
#include <string>
2020-09-20 22:37:15 -04:00
namespace console {
enum class ArgType {
String,
Integer,
Boolean
};
2020-09-22 22:43:30 -04:00
struct ConsoleArgument {
ConsoleArgument(bool data) : data(data) {}
ConsoleArgument(int data) : data(data) {}
ArgType query_type() const {
if(std::holds_alternative<std::string>(data))
return ArgType::String;
else if(std::holds_alternative<int>(data))
return ArgType::Integer;
else if(std::holds_alternative<bool>(data))
return ArgType::Boolean;
}
std::variant<std::string, int, bool> data;
};
2020-09-20 22:37:15 -04:00
struct Arguments {
std::vector<ConsoleArgument> arguments;
};
using FunctionPtr = std::function<void(console::Arguments)>;
struct ArgumentFormat {
ArgumentFormat(const int num_arguments) : num_arguments(num_arguments) {}
int num_arguments = 0;
std::vector<ArgType> argument_types;
};
void register_command(const std::string_view name, const ArgumentFormat expected_format, const FunctionPtr function);
void invoke_command(const std::string_view name, const Arguments arguments);
2020-09-22 22:43:30 -04:00
void parse_and_invoke_command(const std::string_view command);
void register_variable(const std::string_view name, bool& variable);
2020-09-20 22:37:15 -04:00
}