ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
preprocess_state.cpp
Go to the documentation of this file.
4
5void Preprocess_State::save_current_run_params(const fs::path& path, const fs::path& cache_path) {
6 auto end = std::chrono::system_clock::now();
7 std::time_t end_time = std::chrono::system_clock::to_time_t(end);
8 std::string time_str(std::ctime(&end_time));
9 std::string version = Config::config().project_version;
10 if (!time_str.empty() && time_str.back() == '\n')
11 time_str.pop_back();
12 auto size = Utils::folder_size(cache_path);
13
14 json data = PreprocessRunParams{path, time_str, version, size};
15
17 Utils::write_file(config_path, data.dump(4) + '\n');
18}
19
22
23 std::ifstream infile(file_path);
24 if (!infile.is_open()) {
25 std::cerr << "Error: could not open " << file_path << "\n";
26 return {};
27 }
28
29 json data = json::parse(infile, nullptr, false);
30 if (data.is_discarded()) {
31 std::cerr << "Error: could not parse " << file_path << "\n";
32 return {};
33 }
34
35 return data.get<PreprocessRunParams>();
36}
37
38constexpr int MAX_MINOR_VERSION_DIFF = 1;
39
40bool Preprocess_State::is_cache_compatible(const std::string& cache_version) {
41 int current_major, current_minor, current_patch;
42 int cache_major, cache_minor, cache_patch;
43 char dot;
44
45 std::istringstream(Config::config().project_version)
46 >> current_major >> dot >> current_minor >> dot >> current_patch;
47
48 std::istringstream(cache_version)
49 >> cache_major >> dot >> cache_minor >> dot >> cache_patch;
50
51 return (current_major == cache_major && current_minor == cache_minor);
52}
static Config & config()
Gets the singleton configuration instance.
Definition: config.cpp:68
static PreprocessRunParams read_current_run_params()
read preprocessing parameters runs
static void save_current_run_params(const fs::path &path, const fs::path &cache_path)
Saves preprocessing parameters for future runs.
static bool is_cache_compatible(const std::string &cache_version)
static constexpr const char * CONFIG_PATH
Configuration file path.
Configuration management interface.
nlohmann::json json
void write_file(const fs::path &path, const std::string &content)
Writes content to a file at specified path.
Definition: utils.cpp:19
std::uintmax_t folder_size(const fs::path &folder)
Calculates the total size of all regular files in a folder.
Definition: utils.cpp:164
constexpr int MAX_MINOR_VERSION_DIFF
std::filesystem::path base_path
Default base path for temporary files.
Definition: schema.hpp:16
std::string project_version
Current project version.
Definition: schema.hpp:19
std::filesystem::path name_container
Name of the cache container.
Definition: schema.hpp:18
Defines utility functions used across all files.