done LookupAttr, added ArrayAttr container to retrieve list attributes.
[platform/upstream/libzypp.git] / zypp / ResObject.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResObject.h
10  *
11 */
12 #ifndef ZYPP_RESOBJECT_H
13 #define ZYPP_RESOBJECT_H
14
15 #include "zypp/base/Deprecated.h"
16
17 #include "zypp/Resolvable.h"
18 #include "zypp/Date.h"
19 #include "zypp/Locale.h"
20 #include "zypp/Vendor.h"
21 #include "zypp/ByteCount.h"
22 #include "zypp/DiskUsage.h"
23 #include "zypp/OnMediaLocation.h"
24 #include "zypp/Repository.h"
25
26 #include "zypp/sat/LookupAttr.h"
27
28 #include "zypp/TranslatedText.h"
29
30 ///////////////////////////////////////////////////////////////////
31 namespace zypp
32 { /////////////////////////////////////////////////////////////////
33
34   ///////////////////////////////////////////////////////////////////
35   //
36   //    CLASS NAME : ResObject
37   //
38   /**
39    * Interface base for resolvable objects (common data).
40    * That is, all data not needed for solving, but common
41    * across all Resolvable kinds.
42    *
43    * \see \ref makeResObject for how to construct ResObjects.
44   */
45   class ResObject : public Resolvable
46   {
47   public:
48     typedef ResObject                Self;
49     typedef ResTraits<Self>          TraitsType;
50     typedef TraitsType::PtrType      Ptr;
51     typedef TraitsType::constPtrType constPtr;
52
53   public:
54     /** \name Locale support.
55      * \see \ref sat::Solvable
56     */
57     //@{
58     /** \see \ref sat::Solvable::supportsLocales */
59     using sat::Solvable::supportsLocales;
60     /** \see \ref sat::Solvable::supportsLocale */
61     using sat::Solvable::supportsLocale;
62     /** \see \ref sat::Solvable::supportsRequestedLocales */
63     using sat::Solvable::supportsRequestedLocales;
64     /** \see \ref sat::Solvable::getSupportedLocales */
65     using sat::Solvable::getSupportedLocales;
66     //@}
67
68   public:
69
70     /**
71      * \short Short text describing the resolvable.
72      * This attribute is usually displayed in columns.
73      */
74     std::string summary( const Locale & lang_r = Locale() ) const;
75
76     /**
77      * \short Long text describing the resolvable.
78      */
79     std::string description( const Locale & lang_r = Locale() ) const;
80
81     /**
82      * \short Installation Notification
83      *
84      * This text can be used to tell the user some notes
85      * When he selects the resovable for installation.
86      */
87     std::string insnotify( const Locale & lang_r = Locale() ) const;
88
89     /**
90      * \short De-Installation Notification
91      *
92      * This text can be used to tell the user some notes
93      * When he selects the resovable for deinstall.
94      */
95     std::string delnotify( const Locale & lang_r = Locale() ) const;
96
97     /**
98      * \short License or agreement to accept
99      *
100      * Agreement, warning or license the user should
101      * accept before installing the resolvable.
102      */
103     std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
104
105     /**
106      * \short Vendor
107      *
108      * For Example "Novell Inc."
109      */
110     Vendor vendor() const
111     { return Resolvable::vendor().asString(); }
112
113     /** Installed size. */
114     ByteCount installsize() const;
115     /** \deprecated Use installsize which is more precise. */
116     ZYPP_DEPRECATED ByteCount size() const
117     { return installsize(); }
118
119     /** Size of the rpm package. */
120     ByteCount downloadSize() const;
121
122     /** \see \ref sat::Solvable::repository */
123     using sat::Solvable::repository;
124
125      /** \ref RepoInfo associated with the repository
126       *  providing this resolvable.
127       */
128     RepoInfo repoInfo() const
129     { return repository().info(); }
130
131     /**
132      * Media number where the resolvable is located
133      * 0 if no media access is required.
134      */
135     unsigned mediaNr() const;
136
137     /**
138      * \TODO FIXME what is this?
139      * Flag in the metadata indicating this should be
140      * installed unsing '-i' (not -U).
141      */
142     bool installOnly() const;
143
144     /**
145      * \short build time of the resolvable
146      */
147     Date buildtime() const;
148
149     /**
150      * \short Installation time
151      * 0 if the resolvable is not installed.
152      */
153     Date installtime() const;
154
155     /**
156      * \short Disk usage per directory
157      * A common attribute, although mostly packages require
158      * noticeable disk space. An e.g product could try to reserve
159      * a certain ammount of diskspace by providing DiskUsage data.
160      */
161     const DiskUsage & diskusage() const;
162
163   protected:
164     /** Ctor */
165     ResObject( const sat::Solvable & solvable_r );
166     /** Dtor */
167     virtual ~ResObject();
168     /** Helper for stream output */
169     virtual std::ostream & dumpOn( std::ostream & str ) const;
170   };
171   ///////////////////////////////////////////////////////////////////
172
173   /** Create \ref ResObject from \ref sat::Solvable.
174    *
175    * This function creates the apropriate kind of ResObject
176    * depending on the sat::Solvables kind, and returns a smart
177    * pointer to it.
178    *
179    * If the sat::Solvables kind is not convertible, a NULL
180    * pointer is returned.
181    *
182    * \code
183    * sat::Solvable s;
184    * ResObject::Ptr p( makeResObject( s ) );
185    * ResObject::Ptr q( make<ResObject>( s ) );
186    * Package::Ptr   pkg( make<Package>( s ) );
187    * \endcode
188   */
189   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
190
191   /** Directly create a certain kind of ResObject from \ref sat::Solvable.
192    *
193    * If the sat::Solvables kind is not appropriate, a NULL
194    * pointer is returned.
195     * \code
196    * sat::Solvable s;
197    * ResObject::Ptr p( makeResObject( s ) );
198    * ResObject::Ptr q( make<ResObject>( s ) );
199    * Package::Ptr   pkg( make<Package>( s ) );
200    * \endcode
201   */
202   template<class _Res>
203   inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
204   { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
205   /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
206   template<>
207   inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
208   { return makeResObject( solvable_r ); }
209
210   /** Convert ResObject::Ptr into Ptr of a certain Kind.
211    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
212    * not of the specified Kind.
213    * \relates ResObject
214    * \code
215    * asKind<Package>(resPtr);
216    * \endcode
217   */
218   template<class _Res>
219   inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
220   { return dynamic_pointer_cast<_Res>(p); }
221
222   template<class _Res>
223   inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
224   { return dynamic_pointer_cast<const _Res>(p); }
225
226   /////////////////////////////////////////////////////////////////
227 } // namespace zypp
228 ///////////////////////////////////////////////////////////////////
229 #endif // ZYPP_RESOBJECT_H