mirror of
https://github.com/red0124/ssp.git
synced 2025-02-02 16:51:12 +01:00
enable matchers for parser
This commit is contained in:
parent
024e5d3810
commit
6193c65388
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
.clang-format
|
.clang-format
|
||||||
experiment/
|
experiment/
|
||||||
|
build/
|
||||||
|
@ -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,8 +28,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~parser() {
|
~parser() {
|
||||||
|
if (file_) {
|
||||||
fclose(file_);
|
fclose(file_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool valid() const {
|
bool valid() const {
|
||||||
return (error_mode_ == error_mode::error_string) ? string_error_.empty()
|
return (error_mode_ == error_mode::error_string) ? string_error_.empty()
|
||||||
@ -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();
|
||||||
@ -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_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>;
|
||||||
|
Loading…
Reference in New Issue
Block a user