Fix typo affecting cases where gnu hash map is not available (David Halik)
[apt.git] / apt-pkg / rpm / rpmpackagedata.h
1 #ifndef RPMPACKAGEDATA_H
2 #define RPMPACKAGEDATA_H
3
4 #include <apt-pkg/aptconf.h>
5 #include <apt-pkg/tagfile.h>
6 #include <apt-pkg/pkgcache.h>
7 #include <apt-pkg/rpmmisc.h>
8
9 #include <map>
10 #include <vector>
11 #include <regex.h>
12
13 using namespace std;
14
15 struct LessPred
16 {
17    bool operator()(const char* s1, const char* s2) const
18      { return strcmp(s1, s2) < 0; }
19 };
20
21 class RPMPackageData 
22 {
23    protected:
24
25 #ifdef APT_WITH_GNU_HASH_MAP
26    hash_map<string,pkgCache::State::VerPriority,hash_string> Priorities;
27    hash_map<string,pkgCache::Flag::PkgFlags,hash_string> Flags;
28    hash_map<string,vector<string>*,hash_string> FakeProvides;
29    hash_map<string,int,hash_string> IgnorePackages;
30    hash_map<string,int,hash_string> DuplicatedPackages;
31    hash_map<string,bool,hash_string> CompatArch;
32    typedef map<string,pkgCache::VerIterator> VerMapValueType;
33    typedef hash_map<unsigned long,VerMapValueType> VerMapType;
34    typedef hash_map<const char*,int,
35                     hash<const char*>,cstr_eq_pred> ArchScoresType;
36 #else
37    map<string,pkgCache::State::VerPriority> Priorities;
38    map<string,pkgCache::Flag::PkgFlags> Flags;
39    map<string,vector<string>*> FakeProvides;
40    map<string,int> IgnorePackages;
41    map<string,int> DuplicatedPackages;
42    map<string,bool> CompatArch;
43    typedef map<string,pkgCache::VerIterator> VerMapValueType;
44    typedef map<unsigned long,VerMapValueType> VerMapType;
45    typedef map<const char*,int,cstr_lt_pred> ArchScoresType;
46 #endif
47
48    vector<regex_t*> HoldPackages;   
49    vector<regex_t*> DuplicatedPatterns;
50
51    struct Translate {
52            regex_t Pattern;
53            string Template;
54    };
55    
56    vector<Translate*> BinaryTranslations;
57    vector<Translate*> SourceTranslations;
58    vector<Translate*> IndexTranslations;
59
60    VerMapType VerMap;
61
62    void GenericTranslate(vector<Translate*> &TList, string &FullURI,
63                          map<string,string> &Dict);
64
65    int MinArchScore;
66
67    ArchScoresType ArchScores;
68    int RpmArchScore(const char *Arch);
69
70    string BaseArch;
71    string PreferredArch;
72    string CompatArchSuffix;
73    bool MultilibSys;
74
75    public:
76
77    inline pkgCache::State::VerPriority VerPriority(const string &Package) 
78    {
79       if (Priorities.find(Package) != Priorities.end())
80          return Priorities[Package];
81       return pkgCache::State::Standard;
82    };
83    inline pkgCache::Flag::PkgFlags PkgFlags(const string &Package) 
84         {return Flags[Package];};
85
86    bool HoldPackage(const char *name);
87    bool IgnorePackage(const string &Name)
88         {return IgnorePackages.find(Name) != IgnorePackages.end();};
89
90    bool IgnoreDep(pkgVersioningSystem &VS,pkgCache::DepIterator &Dep);
91
92    void TranslateBinary(string &FullURI, map<string,string> &Dict)
93         {return GenericTranslate(BinaryTranslations, FullURI, Dict);};
94    void TranslateSource(string &FullURI, map<string,string> &Dict)
95         {return GenericTranslate(SourceTranslations, FullURI, Dict);};
96    void TranslateIndex(string &FullURI, map<string,string> &Dict)
97         {return GenericTranslate(IndexTranslations, FullURI, Dict);};
98
99    bool HasBinaryTranslation()
100         {return !BinaryTranslations.empty();};
101    bool HasSourceTranslation()
102         {return !SourceTranslations.empty();};
103    bool HasIndexTranslation()
104         {return !IndexTranslations.empty();};
105
106    int ArchScore(const char *Arch)
107    {
108       ArchScoresType::const_iterator I = ArchScores.find(Arch);
109       if (I != ArchScores.end())
110          return I->second;
111       int Ret = RpmArchScore(Arch);
112       // Must iterate and free when deallocating.
113       ArchScores[strdup(Arch)] = Ret;
114       return Ret;
115    }
116    void InitMinArchScore();
117
118    bool IsCompatArch(string Arch);
119    bool IsMultilibSys() { return MultilibSys; };
120    string GetCompatArchSuffix() { return CompatArchSuffix; };
121
122    void SetDupPackage(const string &Name)
123         {DuplicatedPackages[Name] = 1;};
124    bool IsDupPackage(const string &Name);
125
126    static RPMPackageData *Singleton();
127
128    void SetVersion(string ID, unsigned long Offset,
129                    pkgCache::VerIterator &Version)
130    {
131       VerMap[Offset][ID] = Version;
132    };
133    const pkgCache::VerIterator *GetVersion(string ID, unsigned long Offset)
134    {
135        VerMapType::const_iterator I1 = VerMap.find(Offset);
136        if (I1 != VerMap.end()) {
137                VerMapValueType::const_iterator I2 =
138                        I1->second.find(ID);
139                if (I2 != I1->second.end())
140                        return &I2->second;
141        }
142        return NULL;
143    };
144
145    void CacheBuilt() {VerMap.clear();};
146
147    RPMPackageData();
148 };
149
150
151 #endif
152
153 // vim:sts=3:sw=3