Add parser implementation interface and selection API (#501)

* Make architecture implementations virtual functions

- Easier to add new architectures (add implementation to implementation.cpp)
- Easier to add new algorithms / functions to architecture selection
(add to implementation.h, implement)
- Automatically select best implementation in static initialization
- Allow user to explicitly select implementation with a string (i.e.
parameter)
- Allow user to inspect current implementation name/description
- Allow user to list available implementations
- Eliminate architecture enum and architecture-based templating
- Add noexcept in non-inline functions

* Move implementation static methods to their own classes

* Detect best supported implementation on first use

* available_implementationsI() -> available_implementations
This commit is contained in:
John Keiser
2020-02-21 13:34:27 -08:00
committed by GitHub
parent b6423a3426
commit 910f272467
43 changed files with 1565 additions and 1730 deletions
+11 -11
View File
@@ -10,28 +10,28 @@ const std::map<int, const std::string> error_strings = {
{MEMALLOC, "Error allocating memory, we're most likely out of memory"},
{TAPE_ERROR, "Something went wrong while writing to the tape"},
{STRING_ERROR, "Problem while parsing a string"},
{T_ATOM_ERROR,
"Problem while parsing an atom starting with the letter 't'"},
{F_ATOM_ERROR,
"Problem while parsing an atom starting with the letter 'f'"},
{N_ATOM_ERROR,
"Problem while parsing an atom starting with the letter 'n'"},
{T_ATOM_ERROR, "Problem while parsing an atom starting with the letter 't'"},
{F_ATOM_ERROR, "Problem while parsing an atom starting with the letter 'f'"},
{N_ATOM_ERROR, "Problem while parsing an atom starting with the letter 'n'"},
{NUMBER_ERROR, "Problem while parsing a number"},
{UTF8_ERROR, "The input is not valid UTF-8"},
{UNINITIALIZED, "Uninitialized"},
{EMPTY, "Empty: no JSON found"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
"found unescaped characters"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we"
" found unescaped characters"},
{UNCLOSED_STRING, "A string is opened, but never closed."},
{UNEXPECTED_ERROR, "Unexpected error, consider reporting this problem as "
"you may have found a bug in simdjson"},
{UNSUPPORTED_ARCHITECTURE, "simdjson does not have an implementation"
" supported by this CPU architecture (perhaps"
" it's a non-SIMD CPU?)."},
{UNEXPECTED_ERROR, "Unexpected error, consider reporting this problem as"
" you may have found a bug in simdjson"},
};
// string returned when the error code is not recognized
const std::string unexpected_error_msg {"Unexpected error"};
// returns a string matching the error code
const std::string &error_message(error_code code) {
const std::string &error_message(error_code code) noexcept {
auto keyvalue = error_strings.find(code);
if(keyvalue == error_strings.end()) {
return unexpected_error_msg;