backup
[platform/upstream/libzypp.git] / zypp / sat / Solvable.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Solvable.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/Exception.h"
17
18 #include "zypp/sat/detail/PoolImpl.h"
19 #include "zypp/sat/IdStr.h"
20 #include "zypp/sat/Solvable.h"
21 #include "zypp/sat/Repo.h"
22
23 using std::endl;
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28   ///////////////////////////////////////////////////////////////////
29   namespace sat
30   { /////////////////////////////////////////////////////////////////
31
32     const Solvable Solvable::nosolvable;
33
34     /////////////////////////////////////////////////////////////////
35
36     ::_Solvable * Solvable::get() const
37     { return myPool().getSolvable( _id ); }
38
39 #define NO_SOLVABLE_RETURN( VAL ) \
40     ::_Solvable * _solvable( get() ); \
41     if ( ! _solvable ) return VAL
42
43     Solvable Solvable::nextInPool() const
44     { return Solvable( myPool().getNextId( _id ) ); }
45
46     Solvable Solvable::nextInRepo() const
47     {
48       NO_SOLVABLE_RETURN( nosolvable );
49       for ( detail::SolvableIdType next = _id+1; next < unsigned(_solvable->repo->end); ++next )
50       {
51         ::_Solvable * nextS( myPool().getSolvable( next ) );
52         if ( nextS && nextS->repo == _solvable->repo )
53         {
54           return Solvable( next );
55         }
56       }
57       return nosolvable;
58     }
59
60     Repo Solvable::repo() const
61     {
62       NO_SOLVABLE_RETURN( Repo::norepo );
63       return Repo( _solvable->repo );
64     }
65
66     bool Solvable::isSystem() const
67     { return repo().isSystemRepo(); }
68
69     NameId Solvable::name() const
70     {
71       NO_SOLVABLE_RETURN( NameId() );
72       return NameId( _solvable->name ); }
73
74     EvrId Solvable::evr() const
75     {
76       NO_SOLVABLE_RETURN( EvrId() );
77       return EvrId( _solvable->evr );
78     }
79
80     ArchId Solvable::arch() const
81     {
82       NO_SOLVABLE_RETURN( ArchId() );
83       return ArchId( _solvable->arch );
84     }
85
86     VendorId Solvable::vendor() const
87     {
88       NO_SOLVABLE_RETURN( VendorId() );
89       return VendorId( _solvable->vendor );
90     }
91
92     Capabilities Solvable::operator[]( Dep which_r ) const
93     {
94       NO_SOLVABLE_RETURN( Capabilities() );
95       ::Offset offs = 0;
96       switch( which_r.inSwitch() )
97       {
98         case Dep::PROVIDES_e:    offs = _solvable->provides;    break;
99         case Dep::REQUIRES_e:    offs = _solvable->requires;    break;
100         case Dep::CONFLICTS_e:   offs = _solvable->conflicts;   break;
101         case Dep::OBSOLETES_e:   offs = _solvable->obsoletes;   break;
102         case Dep::RECOMMENDS_e:  offs = _solvable->recommends;  break;
103         case Dep::SUGGESTS_e:    offs = _solvable->suggests;    break;
104         case Dep::FRESHENS_e:    offs = _solvable->freshens;    break;
105         case Dep::ENHANCES_e:    offs = _solvable->enhances;    break;
106         case Dep::SUPPLEMENTS_e: offs = _solvable->supplements; break;
107
108         case Dep::PREREQUIRES_e:
109           // prerequires are a subset of requires
110           if ( (offs = _solvable->requires) )
111             return Capabilities( _solvable->repo->idarraydata + offs, detail::solvablePrereqMarker );
112           else
113             return Capabilities();
114           break;
115       }
116
117       return offs ? Capabilities( _solvable->repo->idarraydata + offs )
118                   : Capabilities();
119     }
120
121     /******************************************************************
122     **
123     **  FUNCTION NAME : operator<<
124     **  FUNCTION TYPE : std::ostream &
125     */
126     std::ostream & operator<<( std::ostream & str, const Solvable & obj )
127     {
128       if ( ! obj )
129         return str << "sat::solvable()";
130
131       return str << "sat::solvable(" << obj.id() << "|"
132           << obj.name() << '-' << obj.evr() << '.' << obj.arch() << "){"
133           << obj.repo().name() << "}";
134     }
135
136     /******************************************************************
137     **
138     **  FUNCTION NAME : dumpOn
139     **  FUNCTION TYPE : std::ostream &
140     */
141     std::ostream & dumpOn( std::ostream & str, const Solvable & obj )
142     {
143       str << obj;
144       if ( obj )
145       {
146 #define OUTS(X) if ( ! obj[Dep::X].empty() ) str << endl << " " #X " " << obj[Dep::X]
147         OUTS(PROVIDES);
148         OUTS(PREREQUIRES);
149         OUTS(REQUIRES);
150         OUTS(CONFLICTS);
151         OUTS(OBSOLETES);
152         OUTS(RECOMMENDS);
153         OUTS(SUGGESTS);
154         OUTS(FRESHENS);
155         OUTS(ENHANCES);
156         OUTS(SUPPLEMENTS);
157 #undef OUTS
158       }
159       return str;
160     }
161
162     /////////////////////////////////////////////////////////////////
163   } // namespace sat
164   ///////////////////////////////////////////////////////////////////
165   /////////////////////////////////////////////////////////////////
166 } // namespace zypp
167 ///////////////////////////////////////////////////////////////////