id based Edition
[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     const SerialNumber & Pool::serial() const
47     { return myPool().serial(); }
48
49     void Pool::setDirty()
50     { return myPool().setDirty(); }
51
52     void Pool::prepare()
53     { return myPool().prepare(); }
54
55     bool Pool::reposEmpty() const
56     { return myPool()->nrepos; }
57
58     unsigned 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     unsigned Pool::solvablesSize() const
81     {
82       // return myPool()->nsolvables;
83       // nsolvables is the array size including
84       // invalid Solvables.
85       unsigned 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       myPool().setDirty();
105       return Repo( ::repo_create( get(), name_r.c_str() ) );
106     }
107
108     Repo Pool::reposFind( const std::string & name_r ) const
109     {
110       for_( it, reposBegin(), reposEnd() )
111       {
112         if ( name_r == it->name() )
113           return *it;
114       }
115       return Repo();
116     }
117
118     Repo Pool::addRepoSolv( const Pathname & file_r, const std::string & name_r )
119     {
120       // Using a temporay repo! (The additional parenthesis are required.)
121       AutoDispose<Repo> tmprepo( (Repo::EraseFromPool()) );
122       *tmprepo = reposInsert( name_r );
123       tmprepo->addSolv( file_r );
124
125       // no exceptions so we keep it:
126       tmprepo.resetDispose();
127       return tmprepo;
128     }
129
130     Repo Pool::addRepoSolv( const Pathname & file_r )
131     { return addRepoSolv( file_r, file_r.basename() ); }
132
133     /******************************************************************
134     **
135     **  FUNCTION NAME : operator<<
136     **  FUNCTION TYPE : std::ostream &
137     */
138     std::ostream & operator<<( std::ostream & str, const Pool & obj )
139     {
140       return str << "sat::pool(" << obj.serial() << "){"
141           << obj.reposSize() << "repos|"
142           << obj.solvablesSize() << "slov}";
143     }
144
145     /////////////////////////////////////////////////////////////////
146   } // namespace sat
147   ///////////////////////////////////////////////////////////////////
148   /////////////////////////////////////////////////////////////////
149 } // namespace zypp
150 ///////////////////////////////////////////////////////////////////