-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgeneral_io.hpp
66 lines (52 loc) · 1.94 KB
/
general_io.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2018-2023, University of Bremen, M. Farzalipour Tabriz
// Copyrights licensed under the 2-Clause BSD License.
// See the accompanying LICENSE.txt file for terms.
#pragma once
#include "arma_io.hpp"
#include "clara.hpp"
#include "nlopt.hpp"
#include "sinks/basic_file_sink.h"
#include "sinks/stdout_color_sinks.h"
#include "slabcc_info.hpp"
#include "spdlog.h"
extern int verbosity_level;
struct cli_params {
std::string &input_file, &output_file, &log_file;
bool &diff_only;
// reads the command line and sets the input_file and output_file
void parse(int argc, char *argv[]);
};
// defines the minimum verbosity level for each type of action
enum class verbosity : int {
info = 1, // spdlog->info()
write_normal_planarAvg = 1,
debug = 2, // spdlog->debug()
write_defect_file = 2,
write_dielectric_file = 2,
write_planarAvg_file = 3,
trace = 4, // spdlog->trace()
timing = 4,
};
// converts the first letter of the string from "a-b-c"/"x-y-z" to 0/1/2
unsigned int xyz2int(const std::string &s);
// converts 0/1/2 to X/Y/Z
char int2xyz(const unsigned int &i);
inline bool file_exists(const std::string &name) {
return std::ifstream(name.c_str()).good();
}
// decides if a functionality is active with the current verbosity level
inline bool is_active(const verbosity &action) noexcept {
return verbosity_level >= static_cast<int>(verbosity(action));
}
inline bool file_is_empty(std::ifstream &file) {
return file.peek() == std::ifstream::traits_type::eof();
}
std::string tolower(std::string in_str) noexcept;
void initialize_loggers(const std::string &log_file,
const std::string &output_file);
void update_loggers();
void finalize_loggers();
// renames the old output file if possible or choose a new output file name
void prepare_output_file(std::string &output_file);
// bool to yes/no conversion
std::string to_string(const bool &b);