pairinteraction
A Rydberg Interaction Calculator
args.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <filesystem>
7#include <string>
8#include <system_error>
9
11inline bool parse_download_missing(int &i, int argc, char **const argv, bool &download_missing) {
12 if (i >= argc || std::string(argv[i]) != "--download-missing") {
13 return false;
14 }
15
16 download_missing = true;
17
18 return true;
19}
20
21inline bool parse_database_dir(int &i, int argc, char **const argv,
22 std::filesystem::path &database_dir) {
23 if (i >= argc || std::string(argv[i]) != "--database-dir") {
24 return false;
25 }
26
27 if (++i >= argc) {
28 throw std::runtime_error("Option --database-dir expects an arguments, but none is given.");
29 }
30
31 database_dir = argv[i];
32 if (!std::filesystem::exists(database_dir)) {
33 return true;
34 }
35
36 database_dir = std::filesystem::canonical(database_dir);
37 if (!std::filesystem::is_directory(database_dir)) {
38 throw std::filesystem::filesystem_error("Cannot access database", database_dir.string(),
39 std::make_error_code(std::errc::not_a_directory));
40 }
41
42 return true;
43}
44
45inline bool parse_data_dir(int &i, int argc, char **const argv, std::filesystem::path &data_dir) {
46 if (i >= argc || std::string(argv[i]) != "--data-dir") {
47 return false;
48 }
49
50 if (++i >= argc) {
51 throw std::runtime_error("Option --data-dir expects an arguments, but none is given.");
52 }
53
54 data_dir = argv[i];
55 if (!std::filesystem::exists(data_dir)) {
56 return true;
57 }
58
59 data_dir = std::filesystem::canonical(data_dir);
60 if (!std::filesystem::is_directory(data_dir)) {
61 throw std::filesystem::filesystem_error("Cannot access data directory", data_dir.string(),
62 std::make_error_code(std::errc::not_a_directory));
63 }
64
65 return true;
66}
67
68} // namespace pairinteraction::args
bool parse_data_dir(int &i, int argc, char **const argv, std::filesystem::path &data_dir)
Definition: args.hpp:45
bool parse_database_dir(int &i, int argc, char **const argv, std::filesystem::path &database_dir)
Definition: args.hpp:21
bool parse_download_missing(int &i, int argc, char **const argv, bool &download_missing)
Definition: args.hpp:11