- initial multilib support (only packages in the same repository are considered)
[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,int,hash_string> MultiArchPackages;
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,int> MultiArchPackages;
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    vector<regex_t*> MultiArchPatterns;
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    public:
71
72    inline pkgCache::State::VerPriority VerPriority(const string &Package) 
73    {
74       if (Priorities.find(Package) != Priorities.end())
75          return Priorities[Package];
76       return pkgCache::State::Standard;
77    };
78    inline pkgCache::Flag::PkgFlags PkgFlags(const string &Package) 
79         {return Flags[Package];};
80
81    bool HoldPackage(const char *name);
82    bool IgnorePackage(const string &Name)
83         {return IgnorePackages.find(Name) != IgnorePackages.end();};
84
85    bool IgnoreDep(pkgVersioningSystem &VS,pkgCache::DepIterator &Dep);
86
87    void TranslateBinary(string &FullURI, map<string,string> &Dict)
88         {return GenericTranslate(BinaryTranslations, FullURI, Dict);};
89    void TranslateSource(string &FullURI, map<string,string> &Dict)
90         {return GenericTranslate(SourceTranslations, FullURI, Dict);};
91    void TranslateIndex(string &FullURI, map<string,string> &Dict)
92         {return GenericTranslate(IndexTranslations, FullURI, Dict);};
93
94    bool HasBinaryTranslation()
95         {return !BinaryTranslations.empty();};
96    bool HasSourceTranslation()
97         {return !SourceTranslations.empty();};
98    bool HasIndexTranslation()
99         {return !IndexTranslations.empty();};
100
101    int ArchScore(const char *Arch)
102    {
103       ArchScoresType::const_iterator I = ArchScores.find(Arch);
104       if (I != ArchScores.end())
105          return I->second;
106       int Ret = RpmArchScore(Arch);
107       // Must iterate and free when deallocating.
108       ArchScores[strdup(Arch)] = Ret;
109       return Ret;
110    }
111    void InitMinArchScore();
112
113    void SetDupPackage(const string &Name)
114         {DuplicatedPackages[Name] = 1;};
115    bool IsDupPackage(const string &Name);
116    void SetMultiArchPackage(const string &Name)
117         {MultiArchPackages[Name] = 1;};
118    bool IsMultiArchPackage(const string &Name);
119
120    static RPMPackageData *Singleton();
121
122    void SetVersion(string ID, unsigned long Offset,
123                    pkgCache::VerIterator &Version)
124    {
125       VerMap[Offset][ID] = Version;
126    };
127    const pkgCache::VerIterator *GetVersion(string ID, unsigned long Offset)
128    {
129        VerMapType::const_iterator I1 = VerMap.find(Offset);
130        if (I1 != VerMap.end()) {
131                VerMapValueType::const_iterator I2 =
132                        I1->second.find(ID);
133                if (I2 != I1->second.end())
134                        return &I2->second;
135        }
136        return NULL;
137    };
138
139    void CacheBuilt() {VerMap.clear();};
140
141    RPMPackageData();
142 };
143
144
145 #endif
146
147 // vim:sts=3:sw=3