1 ////////////////////////////////////////////////////////////////////////
2 // FILE: repository.h
3 // AUTHOR: Johannes Winkelmann, jw@tks6.net
4 // COPYRIGHT: (c) 2002 by Johannes Winkelmann
5 // ---------------------------------------------------------------------
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 ////////////////////////////////////////////////////////////////////////
11
12 #ifndef _REPOSITORY_H_
13 #define _REPOSITORY_H_
14
15 #include <string>
16 #include <list>
17 #include <map>
18 #include <utility>
19 using namespace std;
20
21 #include "package.h"
22
23 /*!
24 \class Repository
25 \brief Repository of available ports
26
27 The repository is an abstraction of the available ports in the ports tree
28 */
29 class Repository
30 {
31 public:
32 Repository(bool useRegex);
33 ~Repository();
34
35 const Package* getPackage( const string& name ) const;
36 const map<string, Package*>& packages() const;
37 const list<pair<Package*, Package*> >& shadowedPackages() const;
38
39 void searchMatchingPackages( const string& pattern,
40 list<Package*>& target,
41 bool searchDesc ) const;
42
43 void getMatchingPackages( const string& pattern,
44 list<Package*>& target ) const;
45
46 void initFromFS( const list< pair<string, string> >& rootList,
47 bool listDuplicate );
48
49
50 /*! Result of a cache write operation */
51 enum CacheReadResult {
52 ACCESS_ERR, /*!< Error creating/accessing the file */
53 FORMAT_ERR, /*!< bad/old format */
54 READ_OK /*!< Success */
55 };
56 CacheReadResult initFromCache( const string& cacheFile );
57
58 /*! Result of a cache write operation */
59 enum WriteResult {
60 DIR_ERR, /*!< Error creating/accessing the directory */
61 FILE_ERR, /*!< Error creating/accessing the file */
62 SUCCESS /*!< Success */
63 };
64 WriteResult writeCache( const string& cacheFile );
65
66 static bool createOutputDir( const string& path );
67 void addDependencies( std::map<string, string>& deps );
68
69 private:
70 static int compareShadowPair(pair<Package*, Package*>& p1,
71 pair<Package*, Package*>& p2);
72
73 static const std::string CACHE_VERSION;
74 bool m_useRegex;
75
76 list<pair<Package*, Package*> > m_shadowedPackages;
77 map<string, Package*> m_packageMap;
78 };
79
80 #endif /* _REPOSITORY_H_ */
|