libept
packagerecord.h
Go to the documentation of this file.
1 #ifndef EPT_APT_PACKAGERECORD_H
2 #define EPT_APT_PACKAGERECORD_H
3 
8 /*
9  * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 #include <ept/apt/recordparser.h>
27 #include <set>
28 
29 namespace ept {
30 namespace apt {
31 
37 {
38  bool parseBool(bool& def, const std::string& str) const
39  {
40  // Believe it or not, this is what apt does to interpret bool fields
41  if (str == "no" || str == "false" || str == "without" ||
42  str == "off" || str == "disable")
43  return false;
44 
45  if (str == "yes" || str == "true" || str == "with" ||
46  str == "on" || str == "enable")
47  return true;
48 
49  return def;
50  }
51  std::string parseString(const std::string& def, const std::string& str) const
52  {
53  if (str == std::string())
54  return def;
55  return str;
56  }
57  std::string parseShortDescription(const std::string& def, const std::string& str) const;
58  std::string parseLongDescription(const std::string& def, const std::string& str) const;
59  size_t parseSize(size_t def, const std::string& str) const;
60  std::set<std::string> parseTags(const std::set<std::string>& def, const std::string& str) const;
61 
62 public:
64  PackageRecord(const std::string& str) : RecordParser(str) {}
65 
66  std::string package(const std::string& def = std::string()) const
67  {
68  return parseString(def, lookup("Package"));
69  }
70  std::string priority(const std::string& def = std::string()) const
71  {
72  return parseString(def, lookup("Priority"));
73  }
74  std::string section(const std::string& def = std::string()) const
75  {
76  return parseString(def, lookup("Section"));
77  }
78  size_t installedSize(size_t def = 0) const
79  {
80  return parseSize(def, lookup("Installed-Size"));
81  }
82  std::string maintainer(const std::string& def = std::string()) const
83  {
84  return parseString(def, lookup("Maintainer"));
85  }
86  std::string architecture(const std::string& def = std::string()) const
87  {
88  return parseString(def, lookup("Architecture"));
89  }
90  std::string source(const std::string& def = std::string()) const
91  {
92  return parseString(def, lookup("Source"));
93  }
94  std::string version(const std::string& def = std::string()) const
95  {
96  return parseString(def, lookup("Version"));
97  }
98  std::string replaces(const std::string& def = std::string()) const
99  {
100  return parseString(def, lookup("Replaces"));
101  }
102  std::string depends(const std::string& def = std::string()) const
103  {
104  return parseString(def, lookup("Depends"));
105  }
106  std::string preDepends(const std::string& def = std::string()) const
107  {
108  return parseString(def, lookup("Pre-Depends"));
109  }
110  std::string recommends(const std::string& def = std::string()) const
111  {
112  return parseString(def, lookup("Recommends"));
113  }
114  std::string suggests(const std::string& def = std::string()) const
115  {
116  return parseString(def, lookup("Suggests"));
117  }
118  std::string enhances(const std::string& def = std::string()) const
119  {
120  return parseString(def, lookup("Enhances"));
121  }
122  std::string provides(const std::string& def = std::string()) const
123  {
124  return parseString(def, lookup("Provides"));
125  }
126  std::string conflicts(const std::string& def = std::string()) const
127  {
128  return parseString(def, lookup("Conflicts"));
129  }
130  std::string filename(const std::string& def = std::string()) const
131  {
132  return parseString(def, lookup("Filename"));
133  }
134  size_t packageSize(size_t def = 0) const
135  {
136  return parseSize(def, lookup("Size"));
137  }
138  std::string md5sum(const std::string& def = std::string()) const
139  {
140  return parseString(def, lookup("MD5sum"));
141  }
142  std::string sha1(const std::string& def = std::string()) const
143  {
144  return parseString(def, lookup("SHA1"));
145  }
146  std::string sha256(const std::string& def = std::string()) const
147  {
148  return parseString(def, lookup("SHA256"));
149  }
150  std::string description(const std::string& def = std::string()) const
151  {
152  return parseString(def, lookup("Description"));
153  }
154  std::string shortDescription(const std::string& def = std::string()) const
155  {
156  return parseShortDescription(def, lookup("Description"));
157  }
158  std::string longDescription(const std::string& def = std::string()) const
159  {
160  return parseLongDescription(def, lookup("Description"));
161  }
162  bool buildEssential(bool def = false) const
163  {
164  return parseBool(def, lookup("Build-Essential"));
165  }
166  std::set<std::string> tag(const std::set<std::string>& def = std::set<std::string>()) const
167  {
168  return parseTags(def, lookup("Tag"));
169  }
170 };
171 
172 }
173 }
174 
175 // vim:set ts=4 sw=4:
176 #endif
std::string conflicts(const std::string &def=std::string()) const
Definition: packagerecord.h:126
std::string recommends(const std::string &def=std::string()) const
Definition: packagerecord.h:110
std::string suggests(const std::string &def=std::string()) const
Definition: packagerecord.h:114
std::string maintainer(const std::string &def=std::string()) const
Definition: packagerecord.h:82
PackageRecord()
Definition: packagerecord.h:63
Parser for APT records.
std::string enhances(const std::string &def=std::string()) const
Definition: packagerecord.h:118
std::string version(const std::string &def=std::string()) const
Definition: packagerecord.h:94
std::string preDepends(const std::string &def=std::string()) const
Definition: packagerecord.h:106
std::string shortDescription(const std::string &def=std::string()) const
Definition: packagerecord.h:154
std::string replaces(const std::string &def=std::string()) const
Definition: packagerecord.h:98
std::string sha1(const std::string &def=std::string()) const
Definition: packagerecord.h:142
std::string priority(const std::string &def=std::string()) const
Definition: packagerecord.h:70
std::string package(const std::string &def=std::string()) const
Definition: packagerecord.h:66
String functions.
Definition: apt.cc:38
RecordParser specialised with access methods for common Debian package information.
Definition: packagerecord.h:36
std::string lookup(size_t idx) const
Return the content of a field by its index.
Definition: recordparser.cc:129
std::string longDescription(const std::string &def=std::string()) const
Definition: packagerecord.h:158
std::string description(const std::string &def=std::string()) const
Definition: packagerecord.h:150
std::string provides(const std::string &def=std::string()) const
Definition: packagerecord.h:122
Access the fields of a package record contained inside a std::string.
Definition: recordparser.h:38
std::set< std::string > tag(const std::set< std::string > &def=std::set< std::string >()) const
Definition: packagerecord.h:166
std::string section(const std::string &def=std::string()) const
Definition: packagerecord.h:74
std::string architecture(const std::string &def=std::string()) const
Definition: packagerecord.h:86
std::string sha256(const std::string &def=std::string()) const
Definition: packagerecord.h:146
std::string md5sum(const std::string &def=std::string()) const
Definition: packagerecord.h:138
PackageRecord(const std::string &str)
Definition: packagerecord.h:64
std::string filename(const std::string &def=std::string()) const
Definition: packagerecord.h:130
std::string source(const std::string &def=std::string()) const
Definition: packagerecord.h:90
bool buildEssential(bool def=false) const
Definition: packagerecord.h:162
std::string depends(const std::string &def=std::string()) const
Definition: packagerecord.h:102
size_t packageSize(size_t def=0) const
Definition: packagerecord.h:134
size_t installedSize(size_t def=0) const
Definition: packagerecord.h:78