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