1#ifndef KNNCOLLE_UTILS_HPP
2#define KNNCOLLE_UTILS_HPP
9#include "sanisizer/sanisizer.hpp"
31template<
typename Input_,
typename Length_>
32void quick_save(
const std::string& path,
const Input_*
const contents,
const Length_ length) {
33 std::ofstream output(path, std::ofstream::binary);
35 throw std::runtime_error(
"failed to open a binary file at '" + path +
"'");
38 output.exceptions(std::ofstream::failbit | std::ofstream::badbit);
39 output.write(
reinterpret_cast<const char*
>(contents), sanisizer::product<std::streamsize>(
sizeof(Input_), sanisizer::attest_gez(length)));
55template<
typename Input_,
typename Length_>
56void quick_load(
const std::string& path, Input_*
const contents,
const Length_ length) {
57 std::ifstream input(path, std::ifstream::binary);
59 throw std::runtime_error(
"failed to open a binary file at '" + path +
"'");
62 input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
63 input.read(
reinterpret_cast<char*
>(contents), sanisizer::product<std::streamsize>(
sizeof(Input_), sanisizer::attest_gez(length)));
74 std::ifstream input(path, std::ifstream::binary);
76 throw std::runtime_error(
"failed to open a binary file at '" + path +
"'");
79 input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
80 return std::string( (std::istreambuf_iterator<char>(input)), (std::istreambuf_iterator<char>()) );
86template<
typename Input_>
87using I = std::remove_cv_t<std::remove_reference_t<Input_> >;
Collection of KNN algorithms.
Definition Bruteforce.hpp:28
std::string quick_load_as_string(const std::string &path)
Definition utils.hpp:73
void quick_load(const std::string &path, Input_ *const contents, const Length_ length)
Definition utils.hpp:56
void quick_save(const std::string &path, const Input_ *const contents, const Length_ length)
Definition utils.hpp:32