- initial import of revision 374 from cnc
[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    typedef map<string,pkgCache::VerIterator> VerMapValueType;
31    typedef hash_map<unsigned long,VerMapValueType> VerMapType;
32    typedef hash_map<const char*,int,
33                     hash<const char*>,cstr_eq_pred> ArchScoresType;
34 #else
35    map<string,pkgCache::State::VerPriority> Priorities;
36    map<string,pkgCache::Flag::PkgFlags> Flags;
37    map<string,vector<string>*> FakeProvides;
38    map<string,int> IgnorePackages;
39    map<string,int> DuplicatedPackages;
40    typedef map<string,pkgCache::VerIterator> VerMapValueType;
41    typedef map<unsigned long,VerMapValueType> VerMapType;
42    typedef map<const char*,int,cstr_lt_pred> ArchScoresType;
43 #endif
44
45    vector<regex_t*> HoldPackages;   
46    vector<regex_t*> DuplicatedPatterns;
47
48    struct Translate {
49            regex_t Pattern;
50            string Template;
51    };
52    
53    vector<Translate*> BinaryTranslations;
54    vector<Translate*> SourceTranslations;
55    vector<Translate*> IndexTranslations;
56
57    VerMapType VerMap;
58
59    void GenericTranslate(vector<Translate*> &TList, string &FullURI,
60                          map<string,string> &Dict);
61
62    int MinArchScore;
63
64    ArchScoresType ArchScores;
65    int RpmArchScore(const char *Arch);
66
67    public:
68
69    inline pkgCache::State::VerPriority VerPriority(const string &Package) 
70    {
71       if (Priorities.find(Package) != Priorities.end())
72          return Priorities[Package];
73       return pkgCache::State::Standard;
74    };
75    inline pkgCache::Flag::PkgFlags PkgFlags(const string &Package) 
76         {return Flags[Package];};
77
78    bool HoldPackage(const char *name);
79    bool IgnorePackage(const string &Name)
80         {return IgnorePackages.find(Name) != IgnorePackages.end();};
81
82    bool IgnoreDep(pkgVersioningSystem &VS,pkgCache::DepIterator &Dep);
83
84    void TranslateBinary(string &FullURI, map<string,string> &Dict)
85         {return GenericTranslate(BinaryTranslations, FullURI, Dict);};
86    void TranslateSource(string &FullURI, map<string,string> &Dict)
87         {return GenericTranslate(SourceTranslations, FullURI, Dict);};
88    void TranslateIndex(string &FullURI, map<string,string> &Dict)
89         {return GenericTranslate(IndexTranslations, FullURI, Dict);};
90
91    bool HasBinaryTranslation()
92         {return !BinaryTranslations.empty();};
93    bool HasSourceTranslation()
94         {return !SourceTranslations.empty();};
95    bool HasIndexTranslation()
96         {return !IndexTranslations.empty();};
97
98    int ArchScore(const char *Arch)
99    {
100       ArchScoresType::const_iterator I = ArchScores.find(Arch);
101       if (I != ArchScores.end())
102          return I->second;
103       int Ret = RpmArchScore(Arch);
104       // Must iterate and free when deallocating.
105       ArchScores[strdup(Arch)] = Ret;
106       return Ret;
107    }
108    void InitMinArchScore();
109
110    void SetDupPackage(const string &Name)
111         {DuplicatedPackages[Name] = 1;};
112    bool IsDupPackage(const string &Name);
113
114    static RPMPackageData *Singleton();
115
116    void SetVersion(string ID, unsigned long Offset,
117                    pkgCache::VerIterator &Version)
118    {
119       VerMap[Offset][ID] = Version;
120    };
121    const pkgCache::VerIterator *GetVersion(string ID, unsigned long Offset)
122    {
123        VerMapType::const_iterator I1 = VerMap.find(Offset);
124        if (I1 != VerMap.end()) {
125                VerMapValueType::const_iterator I2 =
126                        I1->second.find(ID);
127                if (I2 != I1->second.end())
128                        return &I2->second;
129        }
130        return NULL;
131    };
132
133    void CacheBuilt() {VerMap.clear();};
134
135    RPMPackageData();
136 };
137
138
139 #endif
140
141 // vim:sts=3:sw=3