Added Include folder

*facepalm*
This commit is contained in:
2025-07-29 15:33:17 +02:00
parent 82abf3c259
commit f54a3ba309
11 changed files with 224 additions and 20 deletions

View File

@ -1,10 +1,16 @@
#pragma once
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include "cmd/args/arg_base.hpp"
#include "ast/ast_component.hpp"
#include "lexer.hpp"
#include "util/stringliteral.hpp"
namespace fsh {
template <typename T>
@ -15,22 +21,33 @@ namespace fsh {
Argument() {}
virtual void svalue(const std::string& val, const Lexer::TokenType& type) override;
virtual T& gvalue() { return value; }
private:
bool gis_string_literal() { return is_string_literal; }
protected:
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 {
is_string_literal = type == Lexer::TokenType::STRING_LITERAL;
if constexpr (std::is_same_v<T, StringLiteral>) {
if(type != Lexer::TokenType::STRING_LITERAL) {
throw std::invalid_argument("Incorrect type");
}
}
if constexpr (!std::is_same_v<T, std::string> && !std::is_base_of_v<std::string, T>) {
std::stringstream ss_val(val);
if (!(ss_val >> value)) { throw std::invalid_argument("Incorrect type"); }
} else {
value = val;
}
is_string_literal = type == Lexer::TokenType::STRING_LITERAL;
}
}

View File

@ -4,19 +4,20 @@
#include <sstream>
#include "cmd/args/arg_base.hpp"
#include "cmd/args/arg_generic.hpp"
namespace fsh {
class ArgInput : public _Argument {
class ArgInput : public Argument<std::string> {
public:
static std::istream& get(std::shared_ptr<_Argument> a) {
return std::dynamic_pointer_cast<ArgInput>(a)->gvalue();
return std::dynamic_pointer_cast<ArgInput>(a)->gstream();
}
ArgInput() {}
virtual void svalue(const std::string& val, const Lexer::TokenType& type) override;
virtual std::istream& gvalue();
virtual std::istream& gstream();
private:
std::optional<std::stringstream> str;

View File

@ -30,11 +30,16 @@ namespace fsh {
if (flags.find(id) != flags.end()) return Argument<T>::get(flags[id]);
return std::make_optional<T>();
}
bool get(const std::string& id) { return flags.find(id) != flags.end(); }
void push_arg(std::shared_ptr<_Argument> arg) { pos_argument.push_back(arg); }
void push_flag(const std::string& id, std::shared_ptr<_Argument> arg = nullptr) { flags[id] = arg; }
unsigned int size() {
return pos_argument.size();
}
private:
PosArgs pos_argument;
FlagOpts flags;