Imported Upstream version 17.25.3
[platform/upstream/libzypp.git] / zypp / VendorAttr.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/VendorAttr.h
10 */
11 #ifndef ZYPP_VENDORATTR_H
12 #define ZYPP_VENDORATTR_H
13
14 #include <iosfwd>
15 #include <string>
16 #include <vector>
17
18 #include <zypp/base/PtrTypes.h>
19 #include <zypp/IdString.h>
20 #include <zypp/PathInfo.h>
21 #include <zypp/Vendor.h>
22
23 #include <zypp/APIConfig.h>     // LEGACY macros
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp {
27 //////////////////////////////////////////////////////////////////
28
29   class PoolItem;
30   namespace sat
31   {
32     class Solvable;
33   }
34
35 /** Definition of vendor equivalence.
36  *
37  * Packages with equivalent vendor strings may replace themselves without
38  * creating a solver error.
39  *
40  * Per default vendor strings starting with \c "suse" are treated as
41  * being equivalent. This may be tuned by providing customized
42  * vendor description files in \c /etc/zypp/vendors.d.
43  *
44  * \code
45  * [main]
46  * vendors = MyVendor,AlternateName
47  * \endcode
48  *
49  * By this vendor strings starting with "MyVendor" or "AlternateName"
50  * are considered to be equivalent. Packages from equivalent vendors
51  * may replace each other without being considered as a 'vendor change'.
52  *
53  * \note bnc#812608: Within the "opensuse*" namespace exact matches
54  * (case insensitive) are required. "vendors = suse,opensuse" will
55  * allow switching between "suse*" and "opensuse", but not e.g.
56  * "opensuse build service".
57  *
58  * \see \ref pg_zypp-solv-vendorchange
59 */
60 class VendorAttr
61 {
62     friend std::ostream & operator<<( std::ostream & str, const VendorAttr & obj );
63
64   public:
65     /** (Pseudo)Singleton, mapped to the current \ref Target::vendorAttr settings or to \ref noTargetInstance. */
66     static const VendorAttr & instance();
67
68     /** Singleton, settings used if no \ref Target is active.
69      * The instance is initialized with the settings found in the system below /.
70      * The active Targets settings can be changed via \ref Target::vendorAttr.
71      */
72     static VendorAttr & noTargetInstance();
73
74   public:
75     /** Ctor providing the default set. */
76     VendorAttr();
77
78     /** Ctor reading the \a initial_r definitions from a dir or file. */
79     VendorAttr( const Pathname & initial_r );
80
81     /** Dtor */
82     ~VendorAttr();
83
84     /**
85      * Adding new equivalent vendors described in a directory
86      **/
87     bool addVendorDirectory( const Pathname & dirname_r );
88 #if LEGACY(1722)
89     /** \deprecated This is NOT a CONST operation. */
90     bool addVendorDirectory( const Pathname & dirname_r ) const ZYPP_DEPRECATED;
91 #endif
92
93     /**
94      * Adding new equivalent vendors described in a file
95      **/
96     bool addVendorFile( const Pathname & filename_r );
97 #if LEGACY(1722)
98     /** \deprecated This is NOT a CONST operation. */
99     bool addVendorFile( const Pathname & filename_r ) const ZYPP_DEPRECATED;
100 #endif
101
102     /** Preferred type to pass equivalent vendor strings. */
103     typedef std::vector<std::string> VendorList;
104
105     /**
106      * Adding new equivalent vendor strings container.
107      **/
108     void addVendorList( VendorList && list_r )
109     { _addVendorList( std::move(list_r) ); }
110     /** \overload copying the data */
111     void addVendorList( const VendorList & list_r )
112     { _addVendorList( VendorList(list_r) ); }
113     /** \overload from arbitrary string container */
114     template <class TContainer>
115     void addVendorList( const TContainer & container_r )
116     {
117       VendorList tmp;
118       for ( const auto & el : container_r )
119         tmp.push_back( std::string(el) );
120       _addVendorList( std::move(tmp) );
121     }
122     /** \overload from std::initializer_list */
123     template <class TStr>
124     void addVendorList( const std::initializer_list<TStr> & container_r )
125     {
126       VendorList tmp;
127       for ( const auto & el : container_r )
128         tmp.push_back( std::string(el) );
129       _addVendorList( std::move(tmp) );
130     }
131
132     /** Return whether two vendor strings should be treated as the same vendor.
133      * Usually the solver is allowed to automatically select a package of an
134      * equivalent vendor when updating. Replacing a package with one of a
135      * different vendor usually must be confirmed by the user.
136     */
137     bool equivalent( const Vendor & lVendor, const Vendor & rVendor ) const;
138     /** \overload using \ref IdStrings */
139     bool equivalent( IdString lVendor, IdString rVendor ) const;
140     /** \overload using \ref sat::Solvable */
141     bool equivalent( sat::Solvable lVendor, sat::Solvable rVendor ) const;
142     /** \overload using \ref PoolItem */
143     bool equivalent( const PoolItem & lVendor, const PoolItem & rVendor ) const;
144
145   public:
146     /** Call \a fnc_r for each equivalent vendor list (return \c false to break).
147      * \return The number of calls to \a fnc_r.
148      */
149     unsigned foreachVendorList( std::function<bool(VendorList)> fnc_r ) const;
150
151   public:
152     class Impl;                 ///< Implementation class.
153     RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation.
154
155 #if LEGACY(1722)
156     /** \deprecated */
157     void _addVendorList( std::vector<std::string> & list_r ) const ZYPP_DEPRECATED;
158     /** \deprecated */
159     void _addVendorList( std::vector<IdString> && list_r );
160 #endif
161     void _addVendorList( VendorList && list_r );
162 };
163
164 /** \relates VendorAttr Stream output */
165 std::ostream & operator<<( std::ostream & str, const VendorAttr & obj );
166
167 ///////////////////////////////////////////////////////////////////
168 }; // namespace zypp
169 ///////////////////////////////////////////////////////////////////
170
171 #endif // ZYPP_VENDORATTR_H