diff --git a/include/xcdat.hpp b/include/xcdat.hpp index 7189d43..d59b57f 100644 --- a/include/xcdat.hpp +++ b/include/xcdat.hpp @@ -13,14 +13,14 @@ namespace xcdat { using trie_7_type = trie; using trie_8_type = trie; -using flag_type = std::remove_const_t; - template [[maybe_unused]] Trie mmap(const char* address) { mmap_visitor visitor(address); - flag_type flag; + + std::uint32_t flag; visitor.visit(flag); XCDAT_THROW_IF(flag != Trie::l1_bits, "The input index type is different."); + Trie idx; visitor.visit(idx); return idx; @@ -29,9 +29,11 @@ template template [[maybe_unused]] Trie load(std::string_view filepath) { load_visitor visitor(filepath); - flag_type flag; + + std::uint32_t flag; visitor.visit(flag); XCDAT_THROW_IF(flag != Trie::l1_bits, "The input index type is different."); + Trie idx; visitor.visit(idx); return idx; @@ -40,7 +42,7 @@ template template [[maybe_unused]] std::uint64_t save(const Trie& idx, std::string_view filepath) { save_visitor visitor(filepath); - visitor.visit(Trie::l1_bits); // flag + visitor.visit(static_cast(Trie::l1_bits)); // flag visitor.visit(const_cast(idx)); return visitor.bytes(); } @@ -48,11 +50,20 @@ template template [[maybe_unused]] std::uint64_t memory_in_bytes(const Trie& idx) { size_visitor visitor; - visitor.visit(Trie::l1_bits); // flag + visitor.visit(static_cast(Trie::l1_bits)); // flag visitor.visit(const_cast(idx)); return visitor.bytes(); } +[[maybe_unused]] std::uint32_t get_flag(std::string_view filepath) { + std::ifstream ifs(filepath); + XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); + + std::uint32_t flag; + ifs.read(reinterpret_cast(&flag), sizeof(flag)); + return flag; +} + [[maybe_unused]] std::vector load_strings(std::string_view filepath) { std::ifstream ifs(filepath); if (!ifs) { diff --git a/tools/xcdat_decode.cpp b/tools/xcdat_decode.cpp index d6d30c3..25d77d0 100644 --- a/tools/xcdat_decode.cpp +++ b/tools/xcdat_decode.cpp @@ -10,14 +10,6 @@ cmd_line_parser::parser make_parser(int argc, char** argv) { return p; } -xcdat::flag_type get_flag(std::string_view filepath) { - std::ifstream ifs(filepath); - XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); - xcdat::flag_type flag; - ifs.read(reinterpret_cast(&flag), sizeof(flag)); - return flag; -} - template int decode(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); @@ -45,7 +37,7 @@ int main(int argc, char** argv) { } const auto input_idx = p.get("input_idx"); - const auto flag = get_flag(input_idx); + const auto flag = xcdat::get_flag(input_idx); switch (flag) { case 7: diff --git a/tools/xcdat_enumerate.cpp b/tools/xcdat_enumerate.cpp index cd4b99e..9316211 100644 --- a/tools/xcdat_enumerate.cpp +++ b/tools/xcdat_enumerate.cpp @@ -10,14 +10,6 @@ cmd_line_parser::parser make_parser(int argc, char** argv) { return p; } -xcdat::flag_type get_flag(std::string_view filepath) { - std::ifstream ifs(filepath); - XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); - xcdat::flag_type flag; - ifs.read(reinterpret_cast(&flag), sizeof(flag)); - return flag; -} - template int enumerate(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); @@ -42,7 +34,7 @@ int main(int argc, char** argv) { } const auto input_idx = p.get("input_idx"); - const auto flag = get_flag(input_idx); + const auto flag = xcdat::get_flag(input_idx); switch (flag) { case 7: diff --git a/tools/xcdat_lookup.cpp b/tools/xcdat_lookup.cpp index d06d738..ed68298 100644 --- a/tools/xcdat_lookup.cpp +++ b/tools/xcdat_lookup.cpp @@ -10,14 +10,6 @@ cmd_line_parser::parser make_parser(int argc, char** argv) { return p; } -xcdat::flag_type get_flag(std::string_view filepath) { - std::ifstream ifs(filepath); - XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); - xcdat::flag_type flag; - ifs.read(reinterpret_cast(&flag), sizeof(flag)); - return flag; -} - template int lookup(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); @@ -49,7 +41,7 @@ int main(int argc, char** argv) { } const auto input_idx = p.get("input_idx"); - const auto flag = get_flag(input_idx); + const auto flag = xcdat::get_flag(input_idx); switch (flag) { case 7: diff --git a/tools/xcdat_predictive_search.cpp b/tools/xcdat_predictive_search.cpp index 00f1130..39195fa 100644 --- a/tools/xcdat_predictive_search.cpp +++ b/tools/xcdat_predictive_search.cpp @@ -11,14 +11,6 @@ cmd_line_parser::parser make_parser(int argc, char** argv) { return p; } -xcdat::flag_type get_flag(std::string_view filepath) { - std::ifstream ifs(filepath); - XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); - xcdat::flag_type flag; - ifs.read(reinterpret_cast(&flag), sizeof(flag)); - return flag; -} - template int predictive_search(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); @@ -64,7 +56,7 @@ int main(int argc, char** argv) { } const auto input_idx = p.get("input_idx"); - const auto flag = get_flag(input_idx); + const auto flag = xcdat::get_flag(input_idx); switch (flag) { case 7: diff --git a/tools/xcdat_prefix_search.cpp b/tools/xcdat_prefix_search.cpp index ac2f81b..41141c6 100644 --- a/tools/xcdat_prefix_search.cpp +++ b/tools/xcdat_prefix_search.cpp @@ -10,14 +10,6 @@ cmd_line_parser::parser make_parser(int argc, char** argv) { return p; } -xcdat::flag_type get_flag(std::string_view filepath) { - std::ifstream ifs(filepath); - XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); - xcdat::flag_type flag; - ifs.read(reinterpret_cast(&flag), sizeof(flag)); - return flag; -} - template int prefix_search(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); @@ -62,7 +54,7 @@ int main(int argc, char** argv) { } const auto input_idx = p.get("input_idx"); - const auto flag = get_flag(input_idx); + const auto flag = xcdat::get_flag(input_idx); switch (flag) { case 7: