mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-21 11:17:58 +02:00
read write cluster file (#60)
* Read and write cluster files (save work) * add reading test * use define for examples env variable and fix ci * read and write cluster files (working) * fix cluster CI
This commit is contained in:
37
utils/include/aare/utils/compare_files.hpp
Normal file
37
utils/include/aare/utils/compare_files.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief Compare two files
|
||||
*
|
||||
* @param p1 path to the first file
|
||||
* @param p2 path to the second file
|
||||
* @return true if the files are the same, false otherwise
|
||||
*/
|
||||
bool compare_files(const std::string &p1, const std::string &p2) {
|
||||
std::ifstream f1(p1, std::ifstream::binary | std::ifstream::ate);
|
||||
std::ifstream f2(p2, std::ifstream::binary | std::ifstream::ate);
|
||||
|
||||
if (f1.fail() || f2.fail()) {
|
||||
return false; // file problem
|
||||
}
|
||||
|
||||
if (f1.tellg() != f2.tellg()) {
|
||||
return false; // size mismatch
|
||||
}
|
||||
|
||||
// seek back to beginning and use std::equal to compare contents
|
||||
f1.seekg(0, std::ifstream::beg);
|
||||
f2.seekg(0, std::ifstream::beg);
|
||||
return std::equal(std::istreambuf_iterator<char>(f1.rdbuf()), std::istreambuf_iterator<char>(),
|
||||
std::istreambuf_iterator<char>(f2.rdbuf()));
|
||||
}
|
||||
bool compare_files(const std::filesystem::path &p1, const std::filesystem::path &p2) {
|
||||
return compare_files(p1.string(), p2.string());
|
||||
}
|
||||
} // namespace aare
|
@ -244,7 +244,7 @@ extern aare::logger::Logger logger_instance; // NOLINT
|
||||
* @param s arguments to log
|
||||
* @return void
|
||||
*/
|
||||
template <LOGGING_LEVEL level, typename... Strings> void log(const Strings... s) {
|
||||
template <LOGGING_LEVEL level, typename... Strings> void log(const Strings... s) noexcept {
|
||||
internal::logger_instance.log<level>(s...);
|
||||
}
|
||||
/**
|
||||
|
Reference in New Issue
Block a user