- Fix computation of Product::flavor.
[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     /** Vendor specific string denoting the product line. */
56     std::string productLine() const;
57
58   public:
59     /** Untranslated short name like <tt>SLES 10</tt>*/
60     std::string shortName() const;
61
62     /** The product flavor (LiveCD Demo, FTP edition,...). */
63     std::string flavor() const;
64
65     /** Get the product type (base, add-on)
66      * Well, in an ideal world there is only one base product.
67      * It's the installed product denoted by a symlink in
68      * \c /etc/products.d.
69      * \deprecated Use isTargetDistribution to test for the installed base product,
70      * other wise type is empty for almost all products.
71     */
72     std::string type() const ZYPP_DEPRECATED;
73
74     /** The product flags */
75     std::list<std::string> flags() const;
76
77   public:
78     /** This is the \b installed product that is also targeted by the
79      *  \c /etc/products.d/baseproduct symlink.
80     */
81     bool isTargetDistribution() const;
82
83     /** This is \c register.target attribute of an \b installed product.
84       * Used for registration.
85       */
86     std::string registerTarget() const;
87
88     /** This is \c register.release attribute of an \b installed product.
89       * Used for registration.
90       */
91     std::string registerRelease() const;
92
93   public:
94     /***/
95     class UrlList;
96
97     /** Rerieve urls flagged with \c key_r for this product.
98      *
99      * This is the most common interface. There are convenience methods for
100      * wellknown flags like \c "releasenotes", \c "register", \c "updateurls",
101      * \c "extraurls", \c "optionalurls" and \c "smolt" below.
102      */
103     UrlList urls( const std::string & key_r ) const;
104
105     /** The URL to download the release notes for this product. */
106     UrlList releaseNotesUrls() const;
107
108     /** The URL for registration. */
109     UrlList registerUrls() const;
110
111     /** The URL for SMOLT \see http://smolts.org/wiki/Main_Page. */
112     UrlList smoltUrls() const;
113
114     /**
115      * Online updates for the product.
116      * They are complementary, not alternatives. #163192
117      */
118     UrlList updateUrls() const;
119
120     /**
121      * Additional software for the product
122      * They are complementary, not alternatives.
123      */
124     UrlList extraUrls() const;
125
126     /**
127      * Optional software for the product.
128      * (for example. Non OSS repositories)
129      * They are complementary, not alternatives.
130      */
131     UrlList optionalUrls() const;
132
133   protected:
134     friend Ptr make<Self>( const sat::Solvable & solvable_r );
135     /** Ctor */
136     Product( const sat::Solvable & solvable_r );
137     /** Dtor */
138     virtual ~Product();
139   };
140
141   /** Helper to iterate a products URL lists.
142    * \ref first is a convenience for 'lists' with just
143    * one entry (e.g. releaseNotesUrls)
144    */
145   class Product::UrlList
146   {
147     private:
148       /** \todo Change to directly iterate the .solv */
149       typedef std::list<Url> ListType;
150
151     public:
152       typedef ListType::value_type     value_type;
153       typedef ListType::size_type      size_type;
154       typedef ListType::const_iterator const_iterator;
155
156       bool empty() const
157       { return _list.empty(); }
158
159       size_type size() const
160       { return _list.size(); }
161
162       const_iterator begin() const
163       { return _list.begin(); }
164
165       const_iterator end() const
166       { return _list.end(); }
167
168       /** The first Url or an empty Url. */
169       Url first() const
170       { return empty() ? value_type() : _list.front(); }
171
172     public:
173       /** The key used to retrieve this list (for debug) */
174       std::string key() const
175       { return _key; }
176
177     private:
178       friend class Product;
179       /** Change to directly iterate the .solv */
180       std::string _key;
181       ListType    _list;
182   };
183
184   /** \relates Product::UrlList Stream output. */
185   std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj );
186
187   /////////////////////////////////////////////////////////////////
188 } // namespace zypp
189 ///////////////////////////////////////////////////////////////////
190 #endif // ZYPP_PRODUCT_H