move into trunk
[platform/upstream/libzypp.git] / zypp / sat / Pool.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.cc
10  *
11 */
12
13 extern "C"
14 {
15 #include <satsolver/pool.h>
16 #include <satsolver/repo.h>
17 }
18 #include <iostream>
19
20 #include "zypp/base/Easy.h"
21 #include "zypp/base/Logger.h"
22 #include "zypp/base/Gettext.h"
23 #include "zypp/base/Exception.h"
24
25 #include "zypp/AutoDispose.h"
26
27 #include "zypp/sat/detail/PoolImpl.h"
28 #include "zypp/sat/Pool.h"
29
30 ///////////////////////////////////////////////////////////////////
31 namespace zypp
32 { /////////////////////////////////////////////////////////////////
33   ///////////////////////////////////////////////////////////////////
34   namespace sat
35   { /////////////////////////////////////////////////////////////////
36
37     const std::string & Pool::systemRepoName()
38     {
39       static const std::string _val( "@System" );
40       return _val;
41     }
42
43     ::_Pool * Pool::get() const
44     { return myPool().getPool(); }
45
46     Pool::size_type Pool::capacity() const
47     { return myPool()->nsolvables; }
48
49     const SerialNumber & Pool::serial() const
50     { return myPool().serial(); }
51
52     void Pool::prepare() const
53     { return myPool().prepare(); }
54
55     bool Pool::reposEmpty() const
56     { return myPool()->nrepos; }
57
58     Pool::size_type Pool::reposSize() const
59     { return myPool()->nrepos; }
60
61     Pool::RepoIterator Pool::reposBegin() const
62     { return RepoIterator( myPool()->repos ); }
63
64     Pool::RepoIterator Pool::reposEnd() const
65     { return RepoIterator( myPool()->repos+myPool()->nrepos ); }
66
67     bool Pool::solvablesEmpty() const
68     {
69       // return myPool()->nsolvables;
70       // nsolvables is the array size including
71       // invalid Solvables.
72       for_( it, reposBegin(), reposEnd() )
73       {
74         if ( ! it->solvablesEmpty() )
75           return false;
76       }
77       return true;
78     }
79
80     Pool::size_type Pool::solvablesSize() const
81     {
82       // Do not return myPool()->nsolvables;
83       // nsolvables is the array size including
84       // invalid Solvables.
85       size_type ret = 0;
86       for_( it, reposBegin(), reposEnd() )
87       {
88         ret += it->solvablesSize();
89       }
90       return ret;
91     }
92
93     Pool::SolvableIterator Pool::solvablesBegin() const
94     { return SolvableIterator( myPool().getFirstId() ); }
95
96     Pool::SolvableIterator Pool::solvablesEnd() const
97     { return SolvableIterator(); }
98
99     Repo Pool::reposInsert( const std::string & name_r )
100     {
101       Repo ret( reposFind( name_r ) );
102       if ( ret )
103         return ret;
104
105       ret = Repo( myPool()._createRepo( name_r ) );
106       if ( name_r == systemRepoName() )
107       {
108         // autoprovide (dummy) RepoInfo
109         ret.setInfo( RepoInfo()
110                      .setAlias( name_r )
111                      .setName( name_r )
112                      .setAutorefresh( true )
113                      .setEnabled( true ) );
114       }
115       return ret;
116     }
117
118     Repo Pool::reposFind( const std::string & name_r ) const
119     {
120       for_( it, reposBegin(), reposEnd() )
121       {
122         if ( name_r == it->name() )
123           return *it;
124       }
125       return Repo();
126     }
127
128     Repo Pool::addRepoSolv( const Pathname & file_r, const std::string & name_r )
129     {
130       // Using a temporay repo! (The additional parenthesis are required.)
131       AutoDispose<Repo> tmprepo( (Repo::EraseFromPool()) );
132       *tmprepo = reposInsert( name_r );
133       tmprepo->addSolv( file_r );
134
135       // no exceptions so we keep it:
136       tmprepo.resetDispose();
137       return tmprepo;
138     }
139
140     Repo Pool::addRepoSolv( const Pathname & file_r )
141     { return addRepoSolv( file_r, file_r.basename() ); }
142
143     Repo Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
144     {
145       Repo ret( addRepoSolv( file_r, info_r.alias() ) );
146       ret.setInfo( info_r );
147       return ret;
148     }
149
150     /////////////////////////////////////////////////////////////////
151
152     void Pool::setRequestedLocales( const LocaleSet & locales_r )
153     { myPool().setRequestedLocales( locales_r ); }
154
155     bool Pool::addRequestedLocale( const Locale & locale_r )
156     { return myPool().addRequestedLocale( locale_r ); }
157
158     bool Pool::eraseRequestedLocale( const Locale & locale_r )
159     { return myPool().eraseRequestedLocale( locale_r ); }
160
161     const LocaleSet & Pool::getRequestedLocales() const
162     { return myPool().getRequestedLocales(); }
163
164     bool Pool::isRequestedLocale( const Locale & locale_r ) const
165     { return myPool().isRequestedLocale( locale_r ); }
166
167     const LocaleSet & Pool::getAvailableLocales() const
168     {  return myPool().getAvailableLocales(); }
169
170     bool Pool::isAvailableLocale( const Locale & locale_r ) const
171     { return myPool().isAvailableLocale( locale_r ); }
172
173    /******************************************************************
174     **
175     **  FUNCTION NAME : operator<<
176     **  FUNCTION TYPE : std::ostream &
177     */
178     std::ostream & operator<<( std::ostream & str, const Pool & obj )
179     {
180       return str << "sat::pool(" << obj.serial() << ")["
181           << obj.capacity() << "]{"
182           << obj.reposSize() << "repos|"
183           << obj.solvablesSize() << "slov}";
184     }
185
186     /////////////////////////////////////////////////////////////////
187   } // namespace sat
188   ///////////////////////////////////////////////////////////////////
189   /////////////////////////////////////////////////////////////////
190 } // namespace zypp
191 ///////////////////////////////////////////////////////////////////