1#ifndef KNNCOLLE_UTILS_HPP
2#define KNNCOLLE_UTILS_HPP
10#include "sanisizer/sanisizer.hpp"
32template<
typename Input_,
typename Length_>
33void quick_save(
const std::filesystem::path& path,
const Input_*
const contents,
const Length_ length) {
34 std::ofstream output(path, std::ofstream::binary);
36 throw std::runtime_error(
"failed to open a binary file at '" + path.string() +
"'");
39 output.exceptions(std::ofstream::failbit | std::ofstream::badbit);
40 output.write(
reinterpret_cast<const char*
>(contents), sanisizer::product<std::streamsize>(
sizeof(Input_), sanisizer::attest_gez(length)));
56template<
typename Input_,
typename Length_>
57void quick_load(
const std::filesystem::path& path, Input_*
const contents,
const Length_ length) {
58 std::ifstream input(path, std::ifstream::binary);
60 throw std::runtime_error(
"failed to open a binary file at '" + path.string() +
"'");
63 input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
64 input.read(
reinterpret_cast<char*
>(contents), sanisizer::product<std::streamsize>(
sizeof(Input_), sanisizer::attest_gez(length)));
75 std::ifstream input(path, std::ifstream::binary);
77 throw std::runtime_error(
"failed to open a binary file at '" + path.string() +
"'");
80 input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
81 return std::string( (std::istreambuf_iterator<char>(input)), (std::istreambuf_iterator<char>()) );
87template<
typename Input_>
88using I = std::remove_cv_t<std::remove_reference_t<Input_> >;
Collection of KNN algorithms.
Definition Bruteforce.hpp:29
void quick_load(const std::filesystem::path &path, Input_ *const contents, const Length_ length)
Definition utils.hpp:57
std::string quick_load_as_string(const std::filesystem::path &path)
Definition utils.hpp:74
void quick_save(const std::filesystem::path &path, const Input_ *const contents, const Length_ length)
Definition utils.hpp:33