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