Skip to content

Commit

Permalink
Extract Method printMatchingSequences and implement other queries usi…
Browse files Browse the repository at this point in the history
…ng it
  • Loading branch information
LegalizeAdulthood committed May 8, 2024
1 parent 3995cb0 commit 35d5792
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion comics/comics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class JSONDatabase : public Database
void printColorSequences(std::ostream &str, const std::string &name) override;

private:
void printMatchingSequences(std::ostream &str, const std::string_view &fieldName, const std::string &name);

simdjson::dom::parser parser;
simdjson::simdjson_result<simdjson::dom::element> m_issues;
simdjson::simdjson_result<simdjson::dom::element> m_sequences;
Expand Down Expand Up @@ -103,6 +105,11 @@ JSONDatabase::JSONDatabase(const std::filesystem::path &jsonDir)
}

void JSONDatabase::printScriptSequences(std::ostream &str, const std::string &name)
{
printMatchingSequences(str, "script", name);
}

void JSONDatabase::printMatchingSequences(std::ostream &str, const std::string_view &fieldName, const std::string &name)
{
std::map<int, std::vector<simdjson::dom::object>> issueSequences;

Expand All @@ -115,7 +122,7 @@ void JSONDatabase::printScriptSequences(std::ostream &str, const std::string &na

for (const simdjson::dom::key_value_pair &field : record.get_object())
{
if (field.key == "script")
if (field.key == fieldName)
{
const simdjson::dom::element &value = field.value;
if (!value.is_string())
Expand Down Expand Up @@ -157,14 +164,17 @@ void JSONDatabase::printScriptSequences(std::ostream &str, const std::string &na

void JSONDatabase::printPencilSequences(std::ostream &str, const std::string &name)
{
printMatchingSequences(str, "pencils", name);
}

void JSONDatabase::printInkSequences(std::ostream &str, const std::string &name)
{
printMatchingSequences(str, "inks", name);
}

void JSONDatabase::printColorSequences(std::ostream &str, const std::string &name)
{
printMatchingSequences(str, "colors", name);
}

} // namespace
Expand Down

0 comments on commit 35d5792

Please sign in to comment.