LTP GCOV extension - code coverage report
Current view: | directory - ept/apt - packagerecord.h
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 65
Code covered: | 95.4 % |  | Executed lines: | 62

           1                 : #ifndef EPT_APT_PACKAGERECORD_H
           2                 : #define EPT_APT_PACKAGERECORD_H
           3                 :
           4                 : /** \file
           5                 :  * Parser for APT records, with specialised accessors for package records
           6                 :  */
           7                 :
           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                 :
          32                 : /**
          33                 :  * RecordParser specialised with access methods for common Debian package
          34                 :  * information.
          35                 :  */
          36                 : class PackageRecord : public RecordParser
          37               7 : {
          38               1 :         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               1 :                 if (str == "no" || str == "false" || str == "without" ||
          42                 :                         str == "off" || str == "disable")
          43               0 :                         return false;
          44                 :
          45               1 :                 if (str == "yes" || str == "true" || str == "with" ||
          46                 :                         str == "on" || str == "enable")
          47               1 :                         return true;
          48                 :
          49               0 :                 return def;
          50                 :         }
          51           10436 :         std::string parseString(const std::string& def, const std::string& str) const
          52                 :         {
          53           10436 :                 if (str == std::string())
          54               0 :                         return def;
          55           10436 :                 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:
          63               6 :         PackageRecord() : RecordParser() {}
          64               1 :         PackageRecord(const std::string& str) : RecordParser(str) {}
          65                 :
          66            7813 :         std::string package(const std::string& def = std::string()) const
          67                 :         {
          68            7813 :                 return parseString(def, lookup("Package"));
          69                 :         }
          70               1 :         std::string priority(const std::string& def = std::string()) const
          71                 :         {
          72               1 :                 return parseString(def, lookup("Priority"));
          73                 :         }
          74               1 :         std::string section(const std::string& def = std::string()) const
          75                 :         {
          76               1 :                 return parseString(def, lookup("Section"));
          77                 :         }
          78            2605 :         size_t installedSize(size_t def = 0) const
          79                 :         {
          80            2605 :                 return parseSize(def, lookup("Installed-Size"));
          81                 :         }
          82               1 :         std::string maintainer(const std::string& def = std::string()) const
          83                 :         {
          84               1 :                 return parseString(def, lookup("Maintainer"));
          85                 :         }
          86               1 :         std::string architecture(const std::string& def = std::string()) const
          87                 :         {
          88               1 :                 return parseString(def, lookup("Architecture"));
          89                 :         }
          90               1 :         std::string source(const std::string& def = std::string()) const
          91                 :         {
          92               1 :                 return parseString(def, lookup("Source"));
          93                 :         }
          94               1 :         std::string version(const std::string& def = std::string()) const
          95                 :         {
          96               1 :                 return parseString(def, lookup("Version"));
          97                 :         }
          98               1 :         std::string replaces(const std::string& def = std::string()) const
          99                 :         {
         100               1 :                 return parseString(def, lookup("Replaces"));
         101                 :         }
         102               1 :         std::string depends(const std::string& def = std::string()) const
         103                 :         {
         104               1 :                 return parseString(def, lookup("Depends"));
         105                 :         }
         106               1 :         std::string preDepends(const std::string& def = std::string()) const
         107                 :         {
         108               1 :                 return parseString(def, lookup("Pre-Depends"));
         109                 :         }
         110               1 :         std::string recommends(const std::string& def = std::string()) const
         111                 :         {
         112               1 :                 return parseString(def, lookup("Recommends"));
         113                 :         }
         114               1 :         std::string suggests(const std::string& def = std::string()) const
         115                 :         {
         116               1 :                 return parseString(def, lookup("Suggests"));
         117                 :         }
         118               1 :         std::string enhances(const std::string& def = std::string()) const
         119                 :         {
         120               1 :                 return parseString(def, lookup("Enhances"));
         121                 :         }
         122               1 :         std::string provides(const std::string& def = std::string()) const
         123                 :         {
         124               1 :                 return parseString(def, lookup("Provides"));
         125                 :         }
         126               1 :         std::string conflicts(const std::string& def = std::string()) const
         127                 :         {
         128               1 :                 return parseString(def, lookup("Conflicts"));
         129                 :         }
         130               1 :         std::string filename(const std::string& def = std::string()) const
         131                 :         {
         132               1 :                 return parseString(def, lookup("Filename"));
         133                 :         }
         134            2605 :         size_t packageSize(size_t def = 0) const
         135                 :         {
         136            2605 :                 return parseSize(def, lookup("Size"));
         137                 :         }
         138               1 :         std::string md5sum(const std::string& def = std::string()) const
         139                 :         {
         140               1 :                 return parseString(def, lookup("MD5sum"));
         141                 :         }
         142               1 :         std::string sha1(const std::string& def = std::string()) const
         143                 :         {
         144               1 :                 return parseString(def, lookup("SHA1"));
         145                 :         }
         146               1 :         std::string sha256(const std::string& def = std::string()) const
         147                 :         {
         148               1 :                 return parseString(def, lookup("SHA256"));
         149                 :         }
         150            2605 :         std::string description(const std::string& def = std::string()) const
         151                 :         {
         152            2605 :                 return parseString(def, lookup("Description"));
         153                 :         }
         154               1 :         std::string shortDescription(const std::string& def = std::string()) const
         155                 :         {
         156               1 :                 return parseShortDescription(def, lookup("Description"));
         157                 :         }
         158               1 :         std::string longDescription(const std::string& def = std::string()) const
         159                 :         {
         160               1 :                 return parseLongDescription(def, lookup("Description"));
         161                 :         }
         162               1 :         bool buildEssential(bool def = false) const
         163                 :         {
         164               1 :                 return parseBool(def, lookup("Build-Essential"));
         165                 :         }
         166            2605 :         std::set<std::string> tag(const std::set<std::string>& def = std::set<std::string>()) const
         167                 :         {
         168            2605 :                 return parseTags(def, lookup("Tag"));
         169                 :         }
         170                 : };
         171                 :
         172                 : }
         173                 : }
         174                 :
         175                 : // vim:set ts=4 sw=4:
         176                 : #endif

Generated by: LTP GCOV extension version 1.6