backup
[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/sat/detail/PoolMember.h"
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   class Pathname;
24
25   ///////////////////////////////////////////////////////////////////
26   namespace sat
27   { /////////////////////////////////////////////////////////////////
28
29     ///////////////////////////////////////////////////////////////////
30     //
31     //  CLASS NAME : Pool
32     //
33     /** Global sat-pool.
34      *
35      * Explicitly shared singleton \ref Pool::instance.
36      */
37     class Pool : protected detail::PoolMember
38     {
39       public:
40         typedef detail::SolvableIterator SolvableIterator;
41         typedef detail::RepoIterator     RepoIterator;
42
43       public:
44         /** Singleton ctor. */
45         static Pool instance()
46         { return Pool(); }
47
48         /** Ctor from \ref PoolMember. */
49         Pool( const detail::PoolMember & )
50         {}
51
52       public:
53         /** Whether \ref Pool contains repos. */
54         bool reposEmpty() const;
55
56         /** Number of repos in \ref Pool. */
57         unsigned reposSize() const;
58
59         /** Iterator to the first \ref Repo. */
60         RepoIterator reposBegin() const;
61
62         /** Iterator behind the last \ref Repo. */
63         RepoIterator reposEnd() const;
64
65         /** Return a \ref Repo named \c name_r.
66          * It a such a \ref Repo does not already exist
67          * a new empty \ref Repo is created.
68          */
69         Repo reposInsert( const std::string & name_r );
70
71         /** Find a \ref Repo named \c name_r.
72          * Returns \ref norepo if there is no such \ref Repo.
73          */
74         Repo reposFind( const std::string & name_r ) const;
75
76         /** Remove a \ref Repo named \c name_r.
77          * \see \ref Repo::eraseFromPool
78          */
79         void reposErase( const std::string & name_r );
80
81       public:
82         /** Load \ref Solvables from a solv-file into a \ref Repo named \c name_r.
83          * In case of an exception the \ref Repo is removed from the \ref Pool.
84          * \throws Exception if loading the solv-file fails.
85          * \see \ref Repo::EraseFromPool
86         */
87         Repo addRepoSolv( const Pathname & file_r, const std::string & name_r );
88         /** \overload Using the files basename as \ref Repo name. */
89         Repo addRepoSolv( const Pathname & file_r );
90
91       public:
92         /** Whether \ref Pool contains solvables. */
93         bool solvablesEmpty() const;
94
95         /** Number of solvables in \ref Pool. */
96         unsigned solvablesSize() const;
97
98         /** Iterator to the first \ref Solvable. */
99         SolvableIterator solvablesBegin() const;
100
101         /** Iterator behind the last \ref Solvable. */
102         SolvableIterator solvablesEnd() const;
103
104       public:
105         /** Expert backdoor. */
106         ::_Pool * get() const;
107       private:
108         /** Default ctor */
109         Pool() {}
110     };
111     ///////////////////////////////////////////////////////////////////
112
113     /** \relates Pool Stream output */
114     std::ostream & operator<<( std::ostream & str, const Pool & obj );
115
116     /** \relates Pool */
117     inline bool operator==( const Pool & lhs, const Pool & rhs )
118     { return lhs.get() == rhs.get(); }
119
120     /** \relates Pool */
121     inline bool operator!=( const Pool & lhs, const Pool & rhs )
122     { return lhs.get() != rhs.get(); }
123
124     /////////////////////////////////////////////////////////////////
125   } // namespace sat
126   ///////////////////////////////////////////////////////////////////
127   /////////////////////////////////////////////////////////////////
128 } // namespace zypp
129 ///////////////////////////////////////////////////////////////////
130 #endif // ZYPP_SAT_POOL_H