36 lines
1001 B
C++
36 lines
1001 B
C++
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include "cmd/args/arg_base.hpp"
|
|
#include "ast/ast_component.hpp"
|
|
|
|
namespace fsh {
|
|
|
|
template <typename T>
|
|
class Argument : public _Argument {
|
|
public:
|
|
static T& get(std::shared_ptr<_Argument> a) { return std::dynamic_pointer_cast<Argument<T> >(a)->gvalue(); }
|
|
|
|
Argument() {}
|
|
|
|
virtual void svalue(const std::string& val, const Lexer::TokenType& type) override;
|
|
virtual T& gvalue() { return value; }
|
|
|
|
private:
|
|
bool is_string_literal; // Currently no getter
|
|
T value;
|
|
};
|
|
|
|
template <class T>
|
|
void Argument<T>::svalue(const std::string& val, const Lexer::TokenType& type) {
|
|
if constexpr (std::is_same_v<T, std::string>) {
|
|
value = val;
|
|
} else {
|
|
std::stringstream ss_val(val);
|
|
if (!(ss_val >> value)) { throw std::invalid_argument("Incorrect type"); }
|
|
}
|
|
is_string_literal = type == Lexer::TokenType::STRING_LITERAL;
|
|
}
|
|
|
|
} |