This commit is contained in:
kampersanda 2021-07-03 10:39:15 +09:00
parent 08bb9fd2c4
commit 63a096e21e
4 changed files with 12 additions and 9 deletions

View file

@ -21,7 +21,7 @@ else ()
message(STATUS "Compiler is recent enough to support C++17.") message(STATUS "Compiler is recent enough to support C++17.")
endif () endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -pthread -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -march=native -O3") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -march=native -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O0 -g -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -O0 -g -DDEBUG")

View file

@ -1,5 +1,8 @@
#pragma once #pragma once
#include <fstream>
#include <string>
#include "xcdat/bc_vector_15.hpp" #include "xcdat/bc_vector_15.hpp"
#include "xcdat/bc_vector_16.hpp" #include "xcdat/bc_vector_16.hpp"
#include "xcdat/bc_vector_7.hpp" #include "xcdat/bc_vector_7.hpp"
@ -40,7 +43,7 @@ template <class Trie>
//! Load the trie dictionary from the file. //! Load the trie dictionary from the file.
template <class Trie> template <class Trie>
[[maybe_unused]] Trie load(std::string_view filepath) { [[maybe_unused]] Trie load(const std::string& filepath) {
load_visitor visitor(filepath); load_visitor visitor(filepath);
std::uint32_t flag; std::uint32_t flag;
@ -54,7 +57,7 @@ template <class Trie>
//! Save the trie dictionary to the file and returns the file size in bytes. //! Save the trie dictionary to the file and returns the file size in bytes.
template <class Trie> template <class Trie>
[[maybe_unused]] std::uint64_t save(const Trie& idx, std::string_view filepath) { [[maybe_unused]] std::uint64_t save(const Trie& idx, const std::string& filepath) {
save_visitor visitor(filepath); save_visitor visitor(filepath);
visitor.visit(static_cast<std::uint32_t>(Trie::l1_bits)); // flag visitor.visit(static_cast<std::uint32_t>(Trie::l1_bits)); // flag
visitor.visit(const_cast<Trie&>(idx)); visitor.visit(const_cast<Trie&>(idx));
@ -72,7 +75,7 @@ template <class Trie>
//! Get the flag indicating the trie dictionary type, embedded by the function 'save'. //! Get the flag indicating the trie dictionary type, embedded by the function 'save'.
//! The flag corresponds to trie::l1_bits and will be used to detect the trie type from the file. //! The flag corresponds to trie::l1_bits and will be used to detect the trie type from the file.
[[maybe_unused]] std::uint32_t get_flag(std::string_view filepath) { [[maybe_unused]] std::uint32_t get_flag(const std::string& filepath) {
std::ifstream ifs(filepath); std::ifstream ifs(filepath);
XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file");
@ -82,7 +85,7 @@ template <class Trie>
} }
//! Load the keywords from the file. //! Load the keywords from the file.
[[maybe_unused]] std::vector<std::string> load_strings(std::string_view filepath, char delim = '\n') { [[maybe_unused]] std::vector<std::string> load_strings(const std::string& filepath, char delim = '\n') {
std::ifstream ifs(filepath); std::ifstream ifs(filepath);
XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file");

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string_view> #include <string>
#include <type_traits> #include <type_traits>
#include "exception.hpp" #include "exception.hpp"
@ -13,7 +13,7 @@ class load_visitor {
std::ifstream m_ifs; std::ifstream m_ifs;
public: public:
load_visitor(std::string_view filepath) : m_ifs(filepath, std::ios::binary) { load_visitor(const std::string& filepath) : m_ifs(filepath, std::ios::binary) {
XCDAT_THROW_IF(!m_ifs.good(), "Cannot open the input file"); XCDAT_THROW_IF(!m_ifs.good(), "Cannot open the input file");
} }

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string_view> #include <string>
#include <type_traits> #include <type_traits>
#include "exception.hpp" #include "exception.hpp"
@ -13,7 +13,7 @@ class save_visitor {
std::ofstream m_ofs; std::ofstream m_ofs;
public: public:
save_visitor(std::string_view filepath) : m_ofs(filepath, std::ios::binary) { save_visitor(const std::string& filepath) : m_ofs(filepath, std::ios::binary) {
XCDAT_THROW_IF(!m_ofs.good(), "Cannot open the input file"); XCDAT_THROW_IF(!m_ofs.good(), "Cannot open the input file");
} }