3bb0610ad9472b4c4cb1b3c9649443bee13d6073
[platform/upstream/libzypp.git] / zypp / Product.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.h
10  *
11 */
12 #ifndef ZYPP_PRODUCT_H
13 #define ZYPP_PRODUCT_H
14
15 #include <list>
16 #include <string>
17
18 #include "zypp/ResObject.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   DEFINE_PTR_TYPE(Product);
25
26   ///////////////////////////////////////////////////////////////////
27   //
28   //    CLASS NAME : Product
29   //
30   /** Product interface.
31   */
32   class Product : public ResObject
33   {
34   public:
35     typedef Product                  Self;
36     typedef ResTraits<Self>          TraitsType;
37     typedef TraitsType::PtrType      Ptr;
38     typedef TraitsType::constPtrType constPtr;
39
40   public:
41     /** The reference package providing the product metadata,
42      *  if such a package exists.
43      */
44     sat::Solvable referencePackage() const;
45
46   public:
47     /***/
48     typedef std::vector<constPtr> ReplacedProducts;
49
50     /** Array of \b installed Products that would be replaced by
51      *  installing this one.
52      */
53     ReplacedProducts replacedProducts() const;
54
55   public:
56     /** Untranslated short name like <tt>SLES 10</tt>*/
57     std::string shortName() const;
58
59     /** The product flavor (LiveCD Demo, FTP edition,...). */
60     std::string flavor() const;
61
62     /** Get the product type (base, add-on)
63      * Well, in an ideal world there is only one base product.
64      * It's the installed product denoted by a symlink in
65      * \c /etc/products.d.
66      * \deprecated Use isTargetDistribution to test for the installed base product,
67      * other wise type is empty for almost all products.
68     */
69     std::string type() const ZYPP_DEPRECATED;
70
71     /** The product flags */
72     std::list<std::string> flags() const;
73
74   public:
75     /** This is the \b installed product that is also targeted by the
76      *  \c /etc/products.d/baseproduct symlink.
77     */
78     bool isTargetDistribution() const;
79
80     /** This is \c register.target attribute of an \b installed product.
81       * Used for registration.
82       */
83     std::string registerTarget() const;
84
85     /** This is \c register.release attribute of an \b installed product.
86       * Used for registration.
87       */
88     std::string registerRelease() const;
89
90   public:
91     /***/
92     class UrlList;
93
94     /** Rerieve urls flagged with \c key_r for this product.
95      *
96      * This is the most common interface. There are convenience methods for
97      * wellknown flags like \c "releasenotes", \c "register", \c "updateurls",
98      * \c "extraurls", \c "optionalurls" and \c "smolt" below.
99      */
100     UrlList urls( const std::string & key_r ) const;
101
102     /** The URL to download the release notes for this product. */
103     UrlList releaseNotesUrls() const;
104
105     /** The URL for registration. */
106     UrlList registerUrls() const;
107
108     /** The URL for SMOLT \see http://smolts.org/wiki/Main_Page. */
109     UrlList smoltUrls() const;
110
111     /**
112      * Online updates for the product.
113      * They are complementary, not alternatives. #163192
114      */
115     UrlList updateUrls() const;
116
117     /**
118      * Additional software for the product
119      * They are complementary, not alternatives.
120      */
121     UrlList extraUrls() const;
122
123     /**
124      * Optional software for the product.
125      * (for example. Non OSS repositories)
126      * They are complementary, not alternatives.
127      */
128     UrlList optionalUrls() const;
129
130   protected:
131     friend Ptr make<Self>( const sat::Solvable & solvable_r );
132     /** Ctor */
133     Product( const sat::Solvable & solvable_r );
134     /** Dtor */
135     virtual ~Product();
136   };
137
138   /** Helper to iterate a products URL lists.
139    * \ref first is a convenience for 'lists' with just
140    * one entry (e.g. releaseNotesUrls)
141    */
142   class Product::UrlList
143   {
144     private:
145       /** \todo Change to directly iterate the .solv */
146       typedef std::list<Url> ListType;
147
148     public:
149       typedef ListType::value_type     value_type;
150       typedef ListType::size_type      size_type;
151       typedef ListType::const_iterator const_iterator;
152
153       bool empty() const
154       { return _list.empty(); }
155
156       size_type size() const
157       { return _list.size(); }
158
159       const_iterator begin() const
160       { return _list.begin(); }
161
162       const_iterator end() const
163       { return _list.end(); }
164
165       /** The first Url or an empty Url. */
166       Url first() const
167       { return empty() ? value_type() : _list.front(); }
168
169     public:
170       /** The key used to retrieve this list (for debug) */
171       std::string key() const
172       { return _key; }
173
174     private:
175       friend class Product;
176       /** Change to directly iterate the .solv */
177       std::string _key;
178       ListType    _list;
179   };
180
181   /** \relates Product::UrlList Stream output. */
182   std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj );
183
184   /////////////////////////////////////////////////////////////////
185 } // namespace zypp
186 ///////////////////////////////////////////////////////////////////
187 #endif // ZYPP_PRODUCT_H