libept
|
00001 #ifndef EPT_APT_PACKAGERECORD_H 00002 #define EPT_APT_PACKAGERECORD_H 00003 00008 /* 00009 * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org> 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Lesser General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2.1 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 */ 00025 00026 #include <ept/apt/recordparser.h> 00027 #include <set> 00028 00029 namespace ept { 00030 namespace apt { 00031 00036 class PackageRecord : public RecordParser 00037 { 00038 bool parseBool(bool& def, const std::string& str) const 00039 { 00040 // Believe it or not, this is what apt does to interpret bool fields 00041 if (str == "no" || str == "false" || str == "without" || 00042 str == "off" || str == "disable") 00043 return false; 00044 00045 if (str == "yes" || str == "true" || str == "with" || 00046 str == "on" || str == "enable") 00047 return true; 00048 00049 return def; 00050 } 00051 std::string parseString(const std::string& def, const std::string& str) const 00052 { 00053 if (str == std::string()) 00054 return def; 00055 return str; 00056 } 00057 std::string parseShortDescription(const std::string& def, const std::string& str) const; 00058 std::string parseLongDescription(const std::string& def, const std::string& str) const; 00059 size_t parseSize(size_t def, const std::string& str) const; 00060 std::set<std::string> parseTags(const std::set<std::string>& def, const std::string& str) const; 00061 00062 public: 00063 PackageRecord() : RecordParser() {} 00064 PackageRecord(const std::string& str) : RecordParser(str) {} 00065 00066 std::string package(const std::string& def = std::string()) const 00067 { 00068 return parseString(def, lookup("Package")); 00069 } 00070 std::string priority(const std::string& def = std::string()) const 00071 { 00072 return parseString(def, lookup("Priority")); 00073 } 00074 std::string section(const std::string& def = std::string()) const 00075 { 00076 return parseString(def, lookup("Section")); 00077 } 00078 size_t installedSize(size_t def = 0) const 00079 { 00080 return parseSize(def, lookup("Installed-Size")); 00081 } 00082 std::string maintainer(const std::string& def = std::string()) const 00083 { 00084 return parseString(def, lookup("Maintainer")); 00085 } 00086 std::string architecture(const std::string& def = std::string()) const 00087 { 00088 return parseString(def, lookup("Architecture")); 00089 } 00090 std::string source(const std::string& def = std::string()) const 00091 { 00092 return parseString(def, lookup("Source")); 00093 } 00094 std::string version(const std::string& def = std::string()) const 00095 { 00096 return parseString(def, lookup("Version")); 00097 } 00098 std::string replaces(const std::string& def = std::string()) const 00099 { 00100 return parseString(def, lookup("Replaces")); 00101 } 00102 std::string depends(const std::string& def = std::string()) const 00103 { 00104 return parseString(def, lookup("Depends")); 00105 } 00106 std::string preDepends(const std::string& def = std::string()) const 00107 { 00108 return parseString(def, lookup("Pre-Depends")); 00109 } 00110 std::string recommends(const std::string& def = std::string()) const 00111 { 00112 return parseString(def, lookup("Recommends")); 00113 } 00114 std::string suggests(const std::string& def = std::string()) const 00115 { 00116 return parseString(def, lookup("Suggests")); 00117 } 00118 std::string enhances(const std::string& def = std::string()) const 00119 { 00120 return parseString(def, lookup("Enhances")); 00121 } 00122 std::string provides(const std::string& def = std::string()) const 00123 { 00124 return parseString(def, lookup("Provides")); 00125 } 00126 std::string conflicts(const std::string& def = std::string()) const 00127 { 00128 return parseString(def, lookup("Conflicts")); 00129 } 00130 std::string filename(const std::string& def = std::string()) const 00131 { 00132 return parseString(def, lookup("Filename")); 00133 } 00134 size_t packageSize(size_t def = 0) const 00135 { 00136 return parseSize(def, lookup("Size")); 00137 } 00138 std::string md5sum(const std::string& def = std::string()) const 00139 { 00140 return parseString(def, lookup("MD5sum")); 00141 } 00142 std::string sha1(const std::string& def = std::string()) const 00143 { 00144 return parseString(def, lookup("SHA1")); 00145 } 00146 std::string sha256(const std::string& def = std::string()) const 00147 { 00148 return parseString(def, lookup("SHA256")); 00149 } 00150 std::string description(const std::string& def = std::string()) const 00151 { 00152 return parseString(def, lookup("Description")); 00153 } 00154 std::string shortDescription(const std::string& def = std::string()) const 00155 { 00156 return parseShortDescription(def, lookup("Description")); 00157 } 00158 std::string longDescription(const std::string& def = std::string()) const 00159 { 00160 return parseLongDescription(def, lookup("Description")); 00161 } 00162 bool buildEssential(bool def = false) const 00163 { 00164 return parseBool(def, lookup("Build-Essential")); 00165 } 00166 std::set<std::string> tag(const std::set<std::string>& def = std::set<std::string>()) const 00167 { 00168 return parseTags(def, lookup("Tag")); 00169 } 00170 }; 00171 00172 } 00173 } 00174 00175 // vim:set ts=4 sw=4: 00176 #endif