Debian Codegraph @

apt-pkg-c/package.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #pragma once
2 #include <apt-pkg/cachefile.h>
3 #include <apt-pkg/policy.h>
4 #include <memory>
5 #include "util.h"
6
7 #include "types.h"
8
9 struct VerIterator;
10 struct PkgIterator;
11
12 struct DepIterator : public pkgCache::DepIterator {
13 void raw_next() { (*this)++; }
14
15 UniquePtr<DepIterator> unique() const { return std::make_unique<DepIterator>(*this); }
16
17 u8 dep_type() const { return (*this)->Type; }
18 str comp_type() const { return handle_str(this->CompType()); }
19 str target_ver() const { return handle_str(this->TargetVer()); }
•20 std::size_t index() const { return this->Index(); }
21
22 inline bool or_dep() const {
23 return ((*this)->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
24 }
25
26 UniquePtr<PkgIterator> parent_pkg() const;
27 UniquePtr<PkgIterator> target_pkg() const;
28 UniquePtr<VerIterator> parent_ver() const;
29 UniquePtr<std::vector<VerIterator>> all_targets() const;
30
31 DepIterator(const pkgCache::DepIterator& base) : pkgCache::DepIterator(base){};
32 };
33
34 struct PrvIterator : public pkgCache::PrvIterator {
35 void raw_next() { (*this)++; }
36
37 str name() const { return this->Name(); }
38 str version_str() const { return handle_str(this->ProvideVersion()); }
•39 std::size_t index() const { return this->Index(); }
40
41 UniquePtr<PkgIterator> target_pkg() const;
42 UniquePtr<VerIterator> target_ver() const;
43
44 UniquePtr<PrvIterator> unique() const { return std::make_unique<PrvIterator>(*this); }
45
46 PrvIterator(const pkgCache::PrvIterator& base) : pkgCache::PrvIterator(base){};
47 };
48
49 struct PkgFileIterator : public pkgCache::PkgFileIterator {
50 void raw_next() { (*this)++; }
51
52 str filename() const { return handle_str(this->FileName()); }
53 str archive() const { return handle_str(this->Archive()); }
54 str origin() const { return handle_str(this->Origin()); }
55 str codename() const { return handle_str(this->Codename()); }
56 str label() const { return handle_str(this->Label()); }
57 str site() const { return handle_str(this->Site()); }
58 str component() const { return handle_str(this->Component()); }
59 str arch() const { return handle_str(this->Architecture()); }
60 str index_type() const { return handle_str(this->IndexType()); }
•61 std::size_t index() const { return this->Index(); }
62
63 bool is_downloadable() const { return !this->Flagged(pkgCache::Flag::NotSource); }
64
65 UniquePtr<PkgFileIterator> unique() const { return std::make_unique<PkgFileIterator>(*this); }
66
67 PkgFileIterator(const pkgCache::PkgFileIterator& base) : pkgCache::PkgFileIterator(base){};
68 };
69
70 struct VerFileIterator : public pkgCache::VerFileIterator {
71 void raw_next() { (*this)++; }
•72 std::size_t index() const { return this->Index(); }
73
74 UniquePtr<VerFileIterator> unique() const { return std::make_unique<VerFileIterator>(*this); }
75
76 UniquePtr<PkgFileIterator> package_file() const {
77 return std::make_unique<PkgFileIterator>(this->File());
78 };
79
80 VerFileIterator(const pkgCache::VerFileIterator& base) : pkgCache::VerFileIterator(base){};
81 };
82
83 struct DescIterator : public pkgCache::DescIterator {
84 void raw_next() { (*this)++; }
•85 std::size_t index() const { return this->Index(); }
86
87 UniquePtr<DescIterator> unique() const { return std::make_unique<DescIterator>(*this); }
88
89 DescIterator(const pkgCache::DescIterator& base) : pkgCache::DescIterator(base){};
90 };
91
92 struct VerIterator : public pkgCache::VerIterator {
93 void raw_next() { (*this)++; }
94
95 str version() const { return this->VerStr(); }
96 str arch() const { return this->Arch(); }
97 str section() const { return handle_str(this->Section()); }
98 str priority_str() const { return handle_str(this->PriorityType()); }
99 str source_name() const { return this->SourcePkgName(); }
100 str source_version() const { return this->SourceVerStr(); }
101 u64 size() const { return (*this)->Size; }
102 u64 installed_size() const { return (*this)->InstalledSize; }
103 // TODO: Move this into rust?
104 bool is_installed() const { return this->ParentPkg().CurrentVer() == *this; }
•105 std::size_t index() const { return this->Index(); }
106
107 UniquePtr<PkgIterator> parent_pkg() const;
108
109 // This is for backend records lookups.
110 UniquePtr<DescIterator> translated_desc() const {
111 return std::make_unique<DescIterator>(this->TranslatedDescription());
112 }
113
114 // This is for backend records lookups.
115 // You go through here to get the package files.
116 UniquePtr<VerFileIterator> version_files() const {
117 return std::make_unique<VerFileIterator>(this->FileList());
118 }
119
120 UniquePtr<DepIterator> depends() const {
121 return std::make_unique<DepIterator>(this->DependsList());
122 }
123
124 UniquePtr<PrvIterator> provides() const {
125 return std::make_unique<PrvIterator>(this->ProvidesList());
126 }
127
128 UniquePtr<VerIterator> unique() const { return std::make_unique<VerIterator>(*this); }
129
130 VerIterator(const pkgCache::VerIterator& base) : pkgCache::VerIterator(base){};
131 };
132
•133
134 struct PkgIterator : public pkgCache::PkgIterator {
135 void raw_next() { (*this)++; }
136
137 str name() const { return this->Name(); }
138 str arch() const { return this->Arch(); }
139 String fullname(bool Pretty) const { return this->FullName(Pretty); }
140 u8 current_state() const { return (*this)->CurrentState; }
141 u8 inst_state() const { return (*this)->InstState; }
142 u8 selected_state() const { return (*this)->SelectedState; }
•143 std::size_t index() const { return this->Index(); }
144
145 /// True if the package is essential.
146 bool is_essential() const { return ((*this)->Flags & pkgCache::Flag::Essential) != 0; }
147
148 UniquePtr<VerIterator> current_version() const {
149 return std::make_unique<VerIterator>(this->CurrentVer());
150 }
151
152 UniquePtr<VerIterator> versions() const {
153 return std::make_unique<VerIterator>(this->VersionList());
154 }
155
156 UniquePtr<PrvIterator> provides() const {
157 return std::make_unique<PrvIterator>(this->ProvidesList());
158 }
159
160 UniquePtr<DepIterator> rdepends() const {
161 return std::make_unique<DepIterator>(this->RevDependsList());
162 }
163
164 UniquePtr<PkgIterator> unique() const { return std::make_unique<PkgIterator>(*this); }
165
166 PkgIterator(const pkgCache::PkgIterator& base) : pkgCache::PkgIterator(base){};
167 };
168
169 inline UniquePtr<PkgIterator> PrvIterator::target_pkg() const {
170 return std::make_unique<PkgIterator>(this->OwnerPkg());
171 }
172
173 inline UniquePtr<VerIterator> PrvIterator::target_ver() const {
174 return std::make_unique<VerIterator>(this->OwnerVer());
175 }
176
177 inline UniquePtr<PkgIterator> DepIterator::parent_pkg() const {
178 return std::make_unique<PkgIterator>(this->ParentPkg());
179 }
180
181 inline UniquePtr<VerIterator> DepIterator::parent_ver() const {
182 return std::make_unique<VerIterator>(this->ParentVer());
183 }
184
185 inline UniquePtr<PkgIterator> DepIterator::target_pkg() const {
186 return std::make_unique<PkgIterator>(this->TargetPkg());
187 }
188
189 inline UniquePtr<std::vector<VerIterator>> DepIterator::all_targets() const {
190 // pkgPrioSortList for sorting by priority?
191 //
192 // The version list returned is not a VerIterator.
193 // They are the lowest level Version structs. We need to iter these
194 // Convert them into our VerIterator, and then we can handle that in rust.
195 UniquePtr<pkgCache::Version*[]> VList(this->AllTargets());
196 std::vector<VerIterator> list;
197
198 for (pkgCache::Version** I = VList.get(); *I != 0; ++I) {
199 list.push_back(VerIterator(pkgCache::VerIterator(*this->Cache(), *I)));
200 }
201
202 return std::make_unique<std::vector<VerIterator>>(list);
203 }
204
205 inline UniquePtr<PkgIterator> VerIterator::parent_pkg() const {
206 return std::make_unique<PkgIterator>(this->ParentPkg());
207 }