apt: apt-pkg/pkgrecords.h Source File

apt 3.3.0 commandline package manager

pkgrecords.h
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Package Records - Allows access to complete package description records
6 directly from the file.
7
8 The package record system abstracts the actual parsing of the
9 package files. This is different than the generators parser in that
10 it is used to access information not generate information. No
11 information touched by the generator should be parable from here as
12 it can always be retrieved directly from the cache.
13
14 ##################################################################### */
15 /*}}}*/
16#ifndef PKGLIB_PKGRECORDS_H
17#define PKGLIB_PKGRECORDS_H
18
19#include <apt-pkg/hashes.h>
20#include <apt-pkg/macros.h>
21#include <apt-pkg/pkgcache.h>
22
23#include <memory>
24#include <string>
25#include <vector>
26
27 class APT_PUBLIC pkgRecords /*{{{*/
28{
29 public:
30 class Parser;
31
32 private:
34 void * const d;
35
36 pkgCache &Cache;
37 std::vector<std::unique_ptr<Parser>>Files;
38
39 public:
40 // Lookup function
41 Parser &Lookup(pkgCache::VerFileIterator const &Ver);
42 Parser &Lookup(pkgCache::DescFileIterator const &Desc);
43
44 // Construct destruct
45 explicit pkgRecords(pkgCache &Cache);
46 virtual ~pkgRecords();
47};
48 /*}}}*/
49 class APT_PUBLIC pkgRecords::Parser /*{{{*/
50{
51 protected:
52
53 virtual bool Jump(pkgCache::VerFileIterator const &Ver) = 0;
54 virtual bool Jump(pkgCache::DescFileIterator const &Desc) = 0;
55
56 public:
57 friend class pkgRecords;
58
59 // These refer to the archive file for the Version
60 virtual std::string FileName() {return std::string();};
61 virtual std::string SourcePkg() {return std::string();};
62 virtual std::string SourceVer() {return std::string();};
63
70 virtual HashStringList Hashes() const { return HashStringList(); };
71
72 // These are some general stats about the package
73 virtual std::string Maintainer() {return std::string();};
78 virtual std::string ShortDesc(std::string const &/*lang*/) {return std::string();};
86 virtual std::string LongDesc(std::string const &/*lang*/) {return std::string();};
87 std::string ShortDesc() {return ShortDesc("");};
88 std::string LongDesc() {return LongDesc("");};
89
90 virtual std::string Name() {return std::string();};
91 virtual std::string Homepage() {return std::string();}
92
93 // An arbitrary custom field
94 virtual std::string RecordField(const char * /*fieldName*/) { return std::string();};
95
96 // The record in binary form
97 virtual void GetRec(const char *&Start,const char *&Stop) {Start = Stop = 0;};
98
99 Parser();
100 virtual ~Parser();
101
102 private:
103 void * const d;
104 APT_HIDDEN std::string GetHashFromHashes(char const * const type) const
105 {
106 HashStringList const hashes = Hashes();
107 HashString const * const hs = hashes.find(type);
108 return hs != NULL ? hs->HashValue() : "";
109 };
110};
111 /*}}}*/
112#endif
HashStringList
Definition hashes.h:79
HashStringList::find
HashString const * find(char const *const type) const
Definition hashes.cc:192
pkgCache::DescFileIterator
Definition cacheiterators.h:548
pkgCache::VerFileIterator
Definition cacheiterators.h:530
pkgCache
Definition pkgcache.h:126
pkgRecords::Parser
Definition pkgrecords.h:50
pkgRecords::Parser::LongDesc
virtual std::string LongDesc(std::string const &)
Definition pkgrecords.h:86
pkgRecords::Parser::ShortDesc
virtual std::string ShortDesc(std::string const &)
Definition pkgrecords.h:78
pkgRecords::Parser::Hashes
virtual HashStringList Hashes() const
Definition pkgrecords.h:70
pkgRecords::pkgRecords
pkgRecords(pkgCache &Cache)
Definition pkgrecords.cc:27
pkgcache.h
pkgCache - Structure definitions for the cache file