argparser/src/type.h
2023-05-17 10:17:56 +02:00

42 lines
972 B
C++

#ifndef ARGPARSER_TYPE_H
#define ARGPARSER_TYPE_H
#include "defs.h"
#include <any>
#include <memory>
#include <string>
#include <utility>
namespace argparser {
class type {
public:
virtual ~type() = default;
[[nodiscard]] std::string get_name() const {
return name;
}
protected:
explicit type(std::string name) : name(std::move(name)) {}
std::string name;
};
using type_handle = std::shared_ptr<type>;
template<typename T>
class type_impl : public type {
public:
virtual T parse(const char *begin, const char *end, const char *&parse_end, internal::parser_allow_undelimited allow_undelimited = internal::parser_allow_undelimited::None) = 0;
protected:
explicit type_impl(std::string name) : type(std::move(name)) {}
};
template<typename T>
using type_handle_impl = std::shared_ptr<type_impl<T>>;
}// namespace argparser
#endif//ARGPARSER_TYPE_H