File: package.h

package info (click to toggle)
rust-rust-apt 0.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 620 kB
  • sloc: cpp: 703; makefile: 8
file content (207 lines) | stat: -rw-r--r-- 7,358 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#pragma once
#include <apt-pkg/cachefile.h>
#include <apt-pkg/policy.h>
#include <memory>
#include "util.h"

#include "types.h"

struct VerIterator;
struct PkgIterator;

struct DepIterator : public pkgCache::DepIterator {
	void raw_next() { (*this)++; }

	UniquePtr<DepIterator> unique() const { return std::make_unique<DepIterator>(*this); }

	u8 dep_type() const { return (*this)->Type; }
	str comp_type() const { return handle_str(this->CompType()); }
	str target_ver() const { return handle_str(this->TargetVer()); }
        std::size_t index() const { return this->Index(); }

	inline bool or_dep() const {
		return ((*this)->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
	}

	UniquePtr<PkgIterator> parent_pkg() const;
	UniquePtr<PkgIterator> target_pkg() const;
	UniquePtr<VerIterator> parent_ver() const;
	UniquePtr<std::vector<VerIterator>> all_targets() const;

	DepIterator(const pkgCache::DepIterator& base) : pkgCache::DepIterator(base){};
};

struct PrvIterator : public pkgCache::PrvIterator {
	void raw_next() { (*this)++; }

	str name() const { return this->Name(); }
	str version_str() const { return handle_str(this->ProvideVersion()); }
        std::size_t index() const { return this->Index(); }

	UniquePtr<PkgIterator> target_pkg() const;
	UniquePtr<VerIterator> target_ver() const;

	UniquePtr<PrvIterator> unique() const { return std::make_unique<PrvIterator>(*this); }

	PrvIterator(const pkgCache::PrvIterator& base) : pkgCache::PrvIterator(base){};
};

struct PkgFileIterator : public pkgCache::PkgFileIterator {
	void raw_next() { (*this)++; }

	str filename() const { return handle_str(this->FileName()); }
	str archive() const { return handle_str(this->Archive()); }
	str origin() const { return handle_str(this->Origin()); }
	str codename() const { return handle_str(this->Codename()); }
	str label() const { return handle_str(this->Label()); }
	str site() const { return handle_str(this->Site()); }
	str component() const { return handle_str(this->Component()); }
	str arch() const { return handle_str(this->Architecture()); }
	str index_type() const { return handle_str(this->IndexType()); }
        std::size_t index() const { return this->Index(); }

	bool is_downloadable() const { return !this->Flagged(pkgCache::Flag::NotSource); }

	UniquePtr<PkgFileIterator> unique() const { return std::make_unique<PkgFileIterator>(*this); }

	PkgFileIterator(const pkgCache::PkgFileIterator& base) : pkgCache::PkgFileIterator(base){};
};

struct VerFileIterator : public pkgCache::VerFileIterator {
	void raw_next() { (*this)++; }
        std::size_t index() const { return this->Index(); }

	UniquePtr<VerFileIterator> unique() const { return std::make_unique<VerFileIterator>(*this); }

	UniquePtr<PkgFileIterator> package_file() const {
		return std::make_unique<PkgFileIterator>(this->File());
	};

	VerFileIterator(const pkgCache::VerFileIterator& base) : pkgCache::VerFileIterator(base){};
};

struct DescIterator : public pkgCache::DescIterator {
	void raw_next() { (*this)++; }
        std::size_t index() const { return this->Index(); }

	UniquePtr<DescIterator> unique() const { return std::make_unique<DescIterator>(*this); }

	DescIterator(const pkgCache::DescIterator& base) : pkgCache::DescIterator(base){};
};

struct VerIterator : public pkgCache::VerIterator {
	void raw_next() { (*this)++; }

	str version() const { return this->VerStr(); }
	str arch() const { return this->Arch(); }
	str section() const { return handle_str(this->Section()); }
	str priority_str() const { return handle_str(this->PriorityType()); }
	str source_name() const { return this->SourcePkgName(); }
	str source_version() const { return this->SourceVerStr(); }
	u64 size() const { return (*this)->Size; }
	u64 installed_size() const { return (*this)->InstalledSize; }
	// TODO: Move this into rust?
	bool is_installed() const { return this->ParentPkg().CurrentVer() == *this; }
        std::size_t index() const { return this->Index(); }

	UniquePtr<PkgIterator> parent_pkg() const;

	// This is for backend records lookups.
	UniquePtr<DescIterator> translated_desc() const {
		return std::make_unique<DescIterator>(this->TranslatedDescription());
	}

	// This is for backend records lookups.
	// You go through here to get the package files.
	UniquePtr<VerFileIterator> version_files() const {
		return std::make_unique<VerFileIterator>(this->FileList());
	}

	UniquePtr<DepIterator> depends() const {
		return std::make_unique<DepIterator>(this->DependsList());
	}

	UniquePtr<PrvIterator> provides() const {
		return std::make_unique<PrvIterator>(this->ProvidesList());
	}

	UniquePtr<VerIterator> unique() const { return std::make_unique<VerIterator>(*this); }

	VerIterator(const pkgCache::VerIterator& base) : pkgCache::VerIterator(base){};
};


struct PkgIterator : public pkgCache::PkgIterator {
	void raw_next() { (*this)++; }

	str name() const { return this->Name(); }
	str arch() const { return this->Arch(); }
	String fullname(bool Pretty) const { return this->FullName(Pretty); }
	u8 current_state() const { return (*this)->CurrentState; }
	u8 inst_state() const { return (*this)->InstState; }
	u8 selected_state() const { return (*this)->SelectedState; }
	std::size_t index() const { return this->Index(); }

	/// True if the package is essential.
	bool is_essential() const { return ((*this)->Flags & pkgCache::Flag::Essential) != 0; }

	UniquePtr<VerIterator> current_version() const {
		return std::make_unique<VerIterator>(this->CurrentVer());
	}

	UniquePtr<VerIterator> versions() const {
		return std::make_unique<VerIterator>(this->VersionList());
	}

	UniquePtr<PrvIterator> provides() const {
		return std::make_unique<PrvIterator>(this->ProvidesList());
	}

	UniquePtr<DepIterator> rdepends() const {
		return std::make_unique<DepIterator>(this->RevDependsList());
	}

	UniquePtr<PkgIterator> unique() const { return std::make_unique<PkgIterator>(*this); }

	PkgIterator(const pkgCache::PkgIterator& base) : pkgCache::PkgIterator(base){};
};

inline UniquePtr<PkgIterator> PrvIterator::target_pkg() const {
	return std::make_unique<PkgIterator>(this->OwnerPkg());
}

inline UniquePtr<VerIterator> PrvIterator::target_ver() const {
	return std::make_unique<VerIterator>(this->OwnerVer());
}

inline UniquePtr<PkgIterator> DepIterator::parent_pkg() const {
	return std::make_unique<PkgIterator>(this->ParentPkg());
}

inline UniquePtr<VerIterator> DepIterator::parent_ver() const {
	return std::make_unique<VerIterator>(this->ParentVer());
}

inline UniquePtr<PkgIterator> DepIterator::target_pkg() const {
	return std::make_unique<PkgIterator>(this->TargetPkg());
}

inline UniquePtr<std::vector<VerIterator>> DepIterator::all_targets() const {
	// pkgPrioSortList for sorting by priority?
	//
	// The version list returned is not a VerIterator.
	// They are the lowest level Version structs. We need to iter these
	// Convert them into our VerIterator, and then we can handle that in rust.
	UniquePtr<pkgCache::Version*[]> VList(this->AllTargets());
	std::vector<VerIterator> list;

	for (pkgCache::Version** I = VList.get(); *I != 0; ++I) {
		list.push_back(VerIterator(pkgCache::VerIterator(*this->Cache(), *I)));
	}

	return std::make_unique<std::vector<VerIterator>>(list);
}

inline UniquePtr<PkgIterator> VerIterator::parent_pkg() const {
	return std::make_unique<PkgIterator>(this->ParentPkg());
}