mirror of
https://git.lynn.is/Gwen/argparser.git
synced 2024-05-15 05:41:08 +02:00
34 lines
880 B
C
34 lines
880 B
C
|
#ifndef ARGPARSER_BASIC_TYPE_H
|
||
|
#define ARGPARSER_BASIC_TYPE_H
|
||
|
|
||
|
#include "defs.h"
|
||
|
#include "parser_func.h"
|
||
|
#include "type.h"
|
||
|
#include <any>
|
||
|
#include <functional>
|
||
|
#include <memory>
|
||
|
#include <string>
|
||
|
|
||
|
namespace argparser {
|
||
|
|
||
|
|
||
|
template<typename T>
|
||
|
class basic_type : public type_impl<T> {
|
||
|
public:
|
||
|
basic_type(std::string name, internal::parser_func<T> parser) : type_impl<T>(std::move(name)), parser(std::move(parser)) {}
|
||
|
|
||
|
T parse(const char *begin, const char *end, const char *&parse_end, internal::parser_allow_undelimited allow_undelimited) override {
|
||
|
const char *n_parse_end;
|
||
|
auto val = parser(begin, end, n_parse_end, allow_undelimited);
|
||
|
parse_end = n_parse_end;
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
internal::parser_func<T> parser;
|
||
|
};
|
||
|
|
||
|
}// namespace argparser
|
||
|
|
||
|
#endif//ARGPARSER_BASIC_TYPE_H
|