Workaround ZConfig access causing ZYppLock creation.
[platform/upstream/libzypp.git] / zypp / sat / Pool.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.h
10  *
11 */
12 #ifndef ZYPP_SAT_POOL_H
13 #define ZYPP_SAT_POOL_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/Repo.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   class SerialNumber;
27
28   ///////////////////////////////////////////////////////////////////
29   namespace sat
30   { /////////////////////////////////////////////////////////////////
31
32     ///////////////////////////////////////////////////////////////////
33     //
34     //  CLASS NAME : Pool
35     //
36     /** Global sat-pool.
37      *
38      * Explicitly shared singleton \ref Pool::instance.
39      */
40     class Pool : protected detail::PoolMember
41     {
42       public:
43         typedef detail::SolvableIterator SolvableIterator;
44         typedef detail::RepoIterator     RepoIterator;
45         typedef detail::size_type        size_type;
46
47       public:
48         /** Singleton ctor. */
49         static Pool instance()
50         { return Pool(); }
51
52         /** Ctor from \ref PoolMember. */
53         Pool( const detail::PoolMember & )
54         {}
55
56       public:
57         /** Internal array size for stats only. */
58         size_type capacity() const;
59
60         /** Housekeeping data serial number. */
61         const SerialNumber & serial() const;
62
63         /** Update housekeeping data if necessary (e.g. whatprovides). */
64         void prepare();
65
66       public:
67         /** Whether \ref Pool contains repos. */
68         bool reposEmpty() const;
69
70         /** Number of repos in \ref Pool. */
71         size_type reposSize() const;
72
73         /** Iterator to the first \ref Repo. */
74         RepoIterator reposBegin() const;
75
76         /** Iterator behind the last \ref Repo. */
77         RepoIterator reposEnd() const;
78
79         /** Return a \ref Repo named \c name_r.
80          * It a such a \ref Repo does not already exist
81          * a new empty \ref Repo is created.
82          */
83         Repo reposInsert( const std::string & name_r );
84
85         /** Find a \ref Repo named \c name_r.
86          * Returns \ref norepo if there is no such \ref Repo.
87          */
88         Repo reposFind( const std::string & name_r ) const;
89
90         /** Remove a \ref Repo named \c name_r.
91          * \see \ref Repo::eraseFromPool
92          */
93         void reposErase( const std::string & name_r )
94         { reposFind( name_r ).eraseFromPool(); }
95
96       public:
97         /** Reserved system repo name \c @System. */
98         static const std::string & systemRepoName();
99
100         /** Return the system repo. */
101         Repo systemRepo()
102         { return reposInsert( systemRepoName() ); }
103
104       public:
105         /** Load \ref Solvables from a solv-file into a \ref Repo named \c name_r.
106          * In case of an exception the \ref Repo is removed from the \ref Pool.
107          * \throws Exception if loading the solv-file fails.
108          * \see \ref Repo::EraseFromPool
109         */
110         Repo addRepoSolv( const Pathname & file_r, const std::string & name_r );
111         /** \overload Using the files basename as \ref Repo name. */
112         Repo addRepoSolv( const Pathname & file_r );
113
114       public:
115         /** Whether \ref Pool contains solvables. */
116         bool solvablesEmpty() const;
117
118         /** Number of solvables in \ref Pool. */
119         size_type solvablesSize() const;
120
121         /** Iterator to the first \ref Solvable. */
122         SolvableIterator solvablesBegin() const;
123
124         /** Iterator behind the last \ref Solvable. */
125         SolvableIterator solvablesEnd() const;
126
127       public:
128         /** Expert backdoor. */
129         ::_Pool * get() const;
130       private:
131         /** Default ctor */
132         Pool() {}
133     };
134     ///////////////////////////////////////////////////////////////////
135
136     /** \relates Pool Stream output */
137     std::ostream & operator<<( std::ostream & str, const Pool & obj );
138
139     /** \relates Pool */
140     inline bool operator==( const Pool & lhs, const Pool & rhs )
141     { return lhs.get() == rhs.get(); }
142
143     /** \relates Pool */
144     inline bool operator!=( const Pool & lhs, const Pool & rhs )
145     { return lhs.get() != rhs.get(); }
146
147     /////////////////////////////////////////////////////////////////
148   } // namespace sat
149   ///////////////////////////////////////////////////////////////////
150   /////////////////////////////////////////////////////////////////
151 } // namespace zypp
152 ///////////////////////////////////////////////////////////////////
153 #endif // ZYPP_SAT_POOL_H