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