Debian Codegraph @

apt-pkg-c/records.h

raw symbols SCIP
1 #pragma once
2 #include <apt-pkg/cachefile.h>
3 #include <apt-pkg/indexfile.h>
4 #include <apt-pkg/pkgcache.h>
5 #include <apt-pkg/pkgrecords.h>
6 #include <apt-pkg/pkgsystem.h>
7 #include <apt-pkg/sourcelist.h>
8 #include <memory>
9 #include "rust/cxx.h"
10
11 #include "package.h"
12 #include "types.h"
13
14 struct IndexFile {
15 pkgIndexFile* ptr;
16
17 String archive_uri(str filename) const { return ptr->ArchiveURI(std::string(filename)); }
18 bool is_trusted() const { return ptr->IsTrusted(); }
19
20 IndexFile(pkgIndexFile* file) : ptr(file){};
21 };
22
23 struct Parser {
24 pkgRecords::Parser& ptr;
25
26 String short_desc() const { return handle_string(ptr.ShortDesc()); }
27 String long_desc() const { return handle_string(ptr.LongDesc()); }
28 String filename() const { return ptr.FileName(); }
29
30 // TODO: Maybe look into this more if there is time. I was trying to save an allocation
31 // ptr.RecordField(field.begin())
32 // This will work with String.as_str()
33 // cache.records().get_field(&"Maintainer".to_string())
34 // This will not work with just "Maintainer" string literal
35
36 /// Return the Source package version String.
37 String get_field(String field) const { return handle_string(ptr.RecordField(field.c_str())); }
38
39 // TODO: Lets Go Ahead and Bind HashStrings while we're here ffs
40 /// Find the hash of a Version. Returns Result if there is no hash.
41 String hash_find(String hash_type) const {
42 auto hashes = ptr.Hashes();
43 auto hash = hashes.find(hash_type.c_str());
44 if (hash == NULL) { throw std::runtime_error("Hash Not Found"); }
45 return handle_string(hash->HashValue());
46 }
47
48 Parser(pkgRecords::Parser& parser) : ptr(parser){};
49 };
50
51 struct PkgRecords {
52 pkgRecords mutable records;
53
54 UniquePtr<Parser> ver_lookup(const VerFileIterator& file) const {
55 return std::make_unique<Parser>(records.Lookup(file));
56 }
57
58 /// Moves the Records into the correct place.
59 UniquePtr<Parser> desc_lookup(const DescIterator& desc) const {
60 return std::make_unique<Parser>(records.Lookup(desc.FileList()));
61 }
62
63 PkgRecords(pkgCacheFile* cache) : records(*cache->GetPkgCache()){};
64 };