Remove obsolete ResStatus bits.
[platform/upstream/libzypp.git] / zypp / Arch.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Arch.h
10  *
11 */
12 #ifndef ZYPP_ARCH_H
13 #define ZYPP_ARCH_H
14
15 #include <iosfwd>
16 #include <functional>
17 #include <set>
18 #include <string>
19
20 #include "zypp/base/String.h"
21 #include "zypp/base/Iterator.h"
22
23 #include "zypp/IdStringType.h"
24 #include "zypp/RelCompare.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30   ///////////////////////////////////////////////////////////////////
31   //
32   //    CLASS NAME : Arch
33   //
34   /** Architecture.
35   */
36   class Arch
37   {
38   public:
39     /** Default ctor \ref Arc_noarch. */
40     Arch();
41
42     /** Ctor taking Arch as string. */
43     explicit Arch( IdString::IdType id_r );
44     explicit Arch( const IdString & idstr_r );
45     explicit Arch( const std::string & str_r );
46     explicit Arch( const char * cstr_r );
47
48   public:
49     /** \name IdStringType like interface.
50      * We can't use the complete \ref IdStringType mixin until
51      * _doCompare can be redefined on any level, not just as char*.
52     */
53     //@{
54     /** String representation of Arch. */
55     IdString idStr() const;
56      /** \overload */
57     const std::string & asString() const;
58     /** \overload */
59     const char * c_str() const
60     { return asString().c_str(); }
61
62     /** Test for an empty Arch (this is \ref Arch_epmty, not \ref Arch_noarch ). */
63     bool empty() const
64     { return asString().empty(); }
65
66     /** Size of the string representation. */
67     unsigned size() const
68     { return asString().size(); }
69
70     /** Expert backdoor. */
71     IdString::IdType id() const
72     { return idStr().id(); }
73     //@}
74
75   public:
76     /** Whether this is a buitin (or known) architecture.
77      * Used e.g. in \ref Capability to determine whether
78      * some trailing \c ".string" is part ot the name or
79      * restriction to an architecture.
80     */
81     bool isBuiltIn() const;
82
83   public:
84     /** Compatibility relation.
85      * \return \c True iff \c this is compatible with \a targetArch_r.
86      * \code
87      * Arch_noarch.compatibleWith( ... )       ==> always true;
88      * Arch_i686.compatibleWith( Arch_x86_64 ) ==> true;
89      * Arch_x86_64.compatibleWith( Arch_i686 ) ==> false;
90      * \endcode
91     */
92     bool compatibleWith( const Arch & targetArch_r ) const;
93
94     /** Arch comparison.
95      * Primary key is the number of compatible Archs, then
96      * the string representation. Thus Arch_noarch is the
97      * least Arch.
98     */
99     int compare( const Arch & rhs ) const;
100
101     /** Arch comparison (static version). */
102     static int compare( const Arch & lhs, const Arch & rhs )
103     { return lhs.compare( rhs ); }
104
105   public:
106     /** Reversed arch order, best Arch first. */
107     typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
108
109     /** Return a set of all Arch's \ref compatibleWith a \a targetArch_r.
110      * \note The set is ordered according to compare, thus iterating
111      * will start at \a targetArch_r and end with \c Arch_noarch.
112      * \code
113      * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
114      *
115      * cout << str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
116      *                    make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) )
117      *      << endl;
118      *
119      * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
120      * \endcode
121     */
122     static CompatSet compatSet( const Arch & targetArch_r );
123
124     /** */
125     static std::string asString( const CompatSet & cset )
126     {
127       return str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
128                         make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) );
129     }
130
131   public:
132     struct CompatEntry;
133   private:
134     Arch( const CompatEntry & );
135     const CompatEntry * _entry;
136   };
137   ///////////////////////////////////////////////////////////////////
138
139   /** \name Builtin architecture constants.
140    *
141    * Defined outside Arch as e.g. \c Arch_i386, because some names,
142    * like \c i388, are used as \c #define, thus unusable as identifier
143    * like \c Arch::i386.
144   */
145   //@{
146   /** \relates Arch
147    * This is an empty \ref Arch represented by an empty string.
148    * Sometimes used to indicate an any or an unknown Arch. Don't
149    * confuse this with \ref Arch_noarch, which is in fact an
150    * architecture.
151   */
152   extern const Arch Arch_empty;
153
154   /** \relates Arch */
155   extern const Arch Arch_noarch;
156
157   /** \relates Arch */
158   extern const Arch Arch_pentium4;
159   /** \relates Arch */
160   extern const Arch Arch_pentium3;
161
162   /** \relates Arch */
163   extern const Arch Arch_x86_64;
164   /** \relates Arch */
165   extern const Arch Arch_athlon;
166   /** \relates Arch */
167   extern const Arch Arch_i686;
168   /** \relates Arch */
169   extern const Arch Arch_i586;
170   /** \relates Arch */
171   extern const Arch Arch_i486;
172   /** \relates Arch */
173   extern const Arch Arch_i386;
174
175   /** \relates Arch */
176   extern const Arch Arch_s390x;
177   /** \relates Arch */
178   extern const Arch Arch_s390;
179
180   /** \relates Arch */
181   extern const Arch Arch_ppc64;
182   /** \relates Arch */
183   extern const Arch Arch_ppc;
184
185   /** \relates Arch */
186   extern const Arch Arch_ia64;
187
188   /** \relates Arch */
189   extern const Arch Arch_alphaev67;
190   /** \relates Arch */
191   extern const Arch Arch_alphaev6;
192   /** \relates Arch */
193   extern const Arch Arch_alphapca56;
194   /** \relates Arch */
195   extern const Arch Arch_alphaev56;
196   /** \relates Arch */
197   extern const Arch Arch_alphaev5;
198   /** \relates Arch */
199   extern const Arch Arch_alpha;
200
201   /** \relates Arch */
202   extern const Arch Arch_sparc64;
203   /** \relates Arch */
204   extern const Arch Arch_sparcv9;
205   /** \relates Arch */
206   extern const Arch Arch_sparcv8;
207   /** \relates Arch */
208   extern const Arch Arch_sparc;
209
210   /** \relates Arch */
211   extern const Arch Arch_armv6l;
212   /** \relates Arch */
213   extern const Arch Arch_armv5tejl;
214   /** \relates Arch */
215   extern const Arch Arch_armv5tel;
216   /** \relates Arch */
217   extern const Arch Arch_armv5l;
218   /** \relates Arch */
219   extern const Arch Arch_armv4tl;
220   /** \relates Arch */
221   extern const Arch Arch_armv4l;
222   /** \relates Arch */
223   extern const Arch Arch_armv3l;
224
225    /** \relates Arch */
226   extern const Arch Arch_sh3;
227
228   /** \relates Arch */
229   extern const Arch Arch_sh4;
230   /** \relates Arch */
231   extern const Arch Arch_sh4a;
232   //@}
233
234   ///////////////////////////////////////////////////////////////////
235
236   /** \relates Arch stream output. */
237   inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
238   { return str << obj.asString(); }
239
240   /** \name Equality based on string value. */
241   //@{
242   /** \relates Arch */
243   inline bool operator==( const Arch & lhs, const Arch & rhs )
244   { return lhs.asString() == rhs.asString(); }
245
246   /** \relates Arch */
247   inline bool operator==( const Arch & lhs, const std::string & rhs )
248   { return lhs.asString() == rhs; }
249
250   /** \relates Arch */
251   inline bool operator==( const std::string & lhs, const Arch & rhs )
252   { return lhs == rhs.asString(); }
253
254   /** \relates Arch */
255   inline bool operator!=( const Arch & lhs, const Arch & rhs )
256   { return !( lhs == rhs ); }
257
258   /** \relates Arch */
259   inline bool operator!=( const Arch & lhs, const std::string & rhs )
260   { return !( lhs == rhs ); }
261
262   /** \relates Arch */
263   inline bool operator!=( const std::string & lhs, const Arch & rhs )
264   { return !( lhs == rhs ); }
265   //@}
266
267   ///////////////////////////////////////////////////////////////////
268
269   /** Functor finding compatible architectures.
270    * \see Arch::compatibleWith
271   */
272   struct ArchCompatibleWith : public std::unary_function<Arch,bool>
273   {
274     /** The target architecture */
275     Arch _targetArch;
276     /** Ctor taking the target architecture */
277     ArchCompatibleWith( const Arch & targetArch_r )
278     : _targetArch( targetArch_r )
279     {}
280     /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
281     bool operator()( const Arch & rhs ) const
282     { return rhs.compatibleWith( _targetArch ); }
283   };
284
285   /////////////////////////////////////////////////////////////////
286 } // namespace zypp
287 ///////////////////////////////////////////////////////////////////
288
289 ///////////////////////////////////////////////////////////////////
290 namespace std
291 { /////////////////////////////////////////////////////////////////
292   /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
293   template<>
294     inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
295     { return lhs.compare( rhs ) < 0; }
296   /////////////////////////////////////////////////////////////////
297 } // namespace zypp
298 ///////////////////////////////////////////////////////////////////
299 #endif // ZYPP_ARCH_H