Debian Codegraph @

apt-pkg-c/configuration.h

raw symbols SCIP
1 #pragma once
2 #include <apt-pkg/aptconfiguration.h>
3 #include <apt-pkg/configuration.h>
4 #include <apt-pkg/init.h>
5 #include <apt-pkg/pkgsystem.h>
6 #include <sstream>
7 #include "rust/cxx.h"
8
9 #include "types.h"
10
11 /// The configuration pointer is global.
12 /// We do not need to make a new unique one.
13
14 /// Initialize the apt configuration.
15 void init_config() { pkgInitConfig(*_config); }
16 /// Initialize the apt system.
17
18 void init_system() { pkgInitSystem(*_config, _system); }
19
20 struct ConfigTree {
21 const Configuration::Item* ptr;
22
23 bool end() const { return ptr == 0; }
24
25 UniquePtr<ConfigTree> raw_next() const { return std::make_unique<ConfigTree>(ptr->Next); }
26
27 UniquePtr<ConfigTree> unique() const { return std::make_unique<ConfigTree>(ptr); }
28
29 UniquePtr<ConfigTree> parent() const { return std::make_unique<ConfigTree>(ptr->Parent); }
30
31 UniquePtr<ConfigTree> child() const { return std::make_unique<ConfigTree>(ptr->Child); }
32
33 String tag() const { return ptr->Tag; }
34
35 String value() const { return ptr->Value; }
36
37 ConfigTree(const Configuration::Item* base) : ptr(base){};
38 };
39
40 UniquePtr<ConfigTree> root_tree() { return std::make_unique<ConfigTree>(_config->Tree(0)); }
41
42 UniquePtr<ConfigTree> tree(String key) {
43 return std::make_unique<ConfigTree>(_config->Tree(key.c_str()));
44 }
45
46 /// Returns a String dump of configuration options separated by `\n`
47 String dump() {
48 std::stringstream String_stream;
49 _config->Dump(String_stream);
50 return String_stream.str();
51 }
52
53 /// Find a key and return it's value as a String.
54 String find(String key, String default_value) {
55 return _config->Find(key.c_str(), default_value.c_str());
56 }
57
58 /// Find a file and return it's value as a String.
59 String find_file(String key, String default_value) {
60 return _config->FindFile(key.c_str(), default_value.c_str());
61 }
62
63 /// Find a directory and return it's value as a String.
64 String find_dir(String key, String default_value) {
65 return _config->FindDir(key.c_str(), default_value.c_str());
66 }
67
68 /// Same as find, but for boolean values.
69 bool find_bool(String key, bool default_value) {
70 return _config->FindB(key.c_str(), default_value);
71 }
72
73 /// Same as find, but for i32 values.
74 int find_int(String key, i32 default_value) { return _config->FindI(key.c_str(), default_value); }
75
76 /// Return a vector for an Apt configuration list.
77 Vec<String> find_vector(String key) {
78 std::vector<std::string> vector = _config->FindVector(key.c_str());
79 Vec<String> rust_vector;
80
81 for (const std::string& str : vector) {
82 rust_vector.push_back(str);
83 }
84
85 return rust_vector;
86 }
87
88 /// Return a vector of supported architectures on this system.
89 /// The main architecture is the first in the list.
90 Vec<String> get_architectures() {
91 Vec<String> rust_vector;
92
93 for (const std::string& str : APT::Configuration::getArchitectures()) {
94 rust_vector.push_back(str);
95 }
96
97 return rust_vector;
98 }
99
100 /// Set the given key to the specified value.
101 void set(String key, String value) { _config->Set(key.c_str(), value.c_str()); }
102
103 /// Simply check if a key exists.
104 bool exists(String key) { return _config->Exists(key.c_str()); }
105
106 /// Clears all values from a key.
107 ///
108 /// If the value is a list, the entire list is cleared.
109 /// If you need to clear 1 value from a list see `clear_value`
110 void clear(String key) { _config->Clear(key.c_str()); }
111
112 /// Clear all configurations.
113 void clear_all() { _config->Clear(); }
114
115 /// Clear a single value from a list.
116 void clear_value(String key, String value) { _config->Clear(key.c_str(), value.c_str()); }