enable matchers for parser

This commit is contained in:
ado 2021-01-17 21:46:36 +01:00
parent 024e5d3810
commit 6193c65388
3 changed files with 14 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
compile_commands.json compile_commands.json
.clang-format .clang-format
experiment/ experiment/
build/

View File

@ -11,11 +11,10 @@
namespace ss { namespace ss {
struct none {}; template <typename... Matchers>
template <typename...>
class composite;
class parser { class parser {
struct none {};
public: public:
parser(const std::string& file_name, const std::string& delimiter) parser(const std::string& file_name, const std::string& delimiter)
: file_name_{file_name}, delim_{delimiter}, : file_name_{file_name}, delim_{delimiter},
@ -29,7 +28,9 @@ public:
} }
~parser() { ~parser() {
fclose(file_); if (file_) {
fclose(file_);
}
} }
bool valid() const { bool valid() const {
@ -68,7 +69,7 @@ public:
return {}; return {};
} }
auto value = buff_.get_converter().convert<T, Ts...>(); auto value = buff_.get_converter().template convert<T, Ts...>();
if (!buff_.get_converter().valid()) { if (!buff_.get_converter().valid()) {
set_error_invalid_conversion(); set_error_invalid_conversion();
@ -134,8 +135,8 @@ public:
auto merged_values = auto merged_values =
std::tuple_cat(std::move(values_), std::tuple_cat(std::move(values_),
std::tuple<T>{parser_.valid() std::tuple<T>{parser_.valid()
? std::forward<T>(new_value) ? std::forward<T>(new_value)
: std::nullopt}); : std::nullopt});
return {std::move(merged_values), parser_}; return {std::move(merged_values), parser_};
} }
@ -189,9 +190,6 @@ public:
}; };
private: private:
template <typename...>
friend class composite;
// tries to invoke the given function (see below), if the function // tries to invoke the given function (see below), if the function
// returns a value which can be used as a conditional, and it returns // returns a value which can be used as a conditional, and it returns
// false, the function sets an error, and allows the invoke of the // false, the function sets an error, and allows the invoke of the
@ -250,8 +248,8 @@ private:
char* buffer_{nullptr}; char* buffer_{nullptr};
char* next_line_buffer_{nullptr}; char* next_line_buffer_{nullptr};
converter<> converter_; converter<Matchers...> converter_;
converter<> next_line_converter_; converter<Matchers...> next_line_converter_;
size_t size_{0}; size_t size_{0};
const std::string& delim_; const std::string& delim_;
@ -288,7 +286,7 @@ private:
next_line_converter_.set_error_mode(mode); next_line_converter_.set_error_mode(mode);
} }
converter<>& get_converter() { converter<Matchers...>& get_converter() {
return converter_; return converter_;
} }

View File

@ -340,6 +340,7 @@ S to_object(std::index_sequence<Is...>, Tup&& tup) {
return {std::get<Is>(std::forward<Tup>(tup))...}; return {std::get<Is>(std::forward<Tup>(tup))...};
} }
// TODO Tup may not be a tuple ...
template <class S, class Tup> template <class S, class Tup>
S to_object(Tup&& tup) { S to_object(Tup&& tup) {
using T = std::remove_reference_t<Tup>; using T = std::remove_reference_t<Tup>;