Support for armv6hl
[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     /**
95      * \return the arch before noarch if it's not a multilib arch
96      * (e.g. x86_64,sparc64v,sparc64,ppc64,s390x).
97     */
98     Arch baseArch() const;
99
100     /** \overload static version. */
101     static Arch baseArch( const Arch & targetArch_r )
102     { return targetArch_r.baseArch(); }
103
104     /** Arch comparison.
105      * Compatible architectures are treated as \c less (i.e. <tt>i686>i386>noarch</tt>).
106      * So \c Arch_noarch is the least Arch. Equivalent architectures
107      * (compatible in both directions) are ordered arbitrary.
108      */
109     int compare( const Arch & rhs ) const;
110
111     /** Arch comparison (static version). */
112     static int compare( const Arch & lhs, const Arch & rhs )
113     { return lhs.compare( rhs ); }
114
115   public:
116     /** Reversed arch order, best Arch first. */
117     typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
118
119     /** Return a set of all Arch's \ref compatibleWith a \a targetArch_r.
120      * \note The set is ordered according to compare, thus iterating
121      * will start at \a targetArch_r and end with \c Arch_noarch.
122      * \code
123      * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
124      *
125      * cout << str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
126      *                    make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) )
127      *      << endl;
128      *
129      * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
130      * \endcode
131     */
132     static CompatSet compatSet( const Arch & targetArch_r );
133
134     /** */
135     static std::string asString( const CompatSet & cset )
136     {
137       return str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
138                         make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) );
139     }
140
141   public:
142     struct CompatEntry;
143   private:
144     Arch( const CompatEntry & );
145     const CompatEntry * _entry;
146   };
147   ///////////////////////////////////////////////////////////////////
148
149   /** \name Builtin architecture constants.
150    *
151    * Defined outside Arch as e.g. \c Arch_i386, because some names,
152    * like \c i388, are used as \c #define, thus unusable as identifier
153    * like \c Arch::i386.
154   */
155   //@{
156   /** \relates Arch
157    * This is an empty \ref Arch represented by an empty string.
158    * Sometimes used to indicate an any or an unknown Arch. Don't
159    * confuse this with \ref Arch_noarch, which is in fact an
160    * architecture.
161   */
162   extern const Arch Arch_empty;
163
164   /** \relates Arch */
165   extern const Arch Arch_noarch;
166
167   /** \relates Arch */
168   extern const Arch Arch_pentium4;
169   /** \relates Arch */
170   extern const Arch Arch_pentium3;
171
172   /** \relates Arch */
173   extern const Arch Arch_x86_64;
174   /** \relates Arch */
175   extern const Arch Arch_athlon;
176   /** \relates Arch */
177   extern const Arch Arch_i686;
178   /** \relates Arch */
179   extern const Arch Arch_i586;
180   /** \relates Arch */
181   extern const Arch Arch_i486;
182   /** \relates Arch */
183   extern const Arch Arch_i386;
184
185   /** \relates Arch */
186   extern const Arch Arch_s390x;
187   /** \relates Arch */
188   extern const Arch Arch_s390;
189
190   /** \relates Arch */
191   extern const Arch Arch_ppc64p7;
192   /** \relates Arch */
193   extern const Arch Arch_ppc64;
194   /** \relates Arch */
195   extern const Arch Arch_ppc;
196
197   /** \relates Arch */
198   extern const Arch Arch_ia64;
199
200   /** \relates Arch */
201   extern const Arch Arch_alphaev67;
202   /** \relates Arch */
203   extern const Arch Arch_alphaev6;
204   /** \relates Arch */
205   extern const Arch Arch_alphapca56;
206   /** \relates Arch */
207   extern const Arch Arch_alphaev56;
208   /** \relates Arch */
209   extern const Arch Arch_alphaev5;
210   /** \relates Arch */
211   extern const Arch Arch_alpha;
212
213    /** \relates Arch */
214   extern const Arch Arch_sparc64v;
215   /** \relates Arch */
216   extern const Arch Arch_sparc64;
217   /** \relates Arch */
218   extern const Arch Arch_sparcv9v;
219   /** \relates Arch */
220   extern const Arch Arch_sparcv9;
221   /** \relates Arch */
222   extern const Arch Arch_sparcv8;
223   /** \relates Arch */
224   extern const Arch Arch_sparc;
225
226   /** \relates Arch */
227   extern const Arch Arch_aarch64;
228   /** \relates Arch */
229   extern const Arch Arch_armv7tnhl;
230   /** \relates Arch */
231   extern const Arch Arch_armv7thl;
232   /** \relates Arch */
233   extern const Arch Arch_armv7nhl;
234   /** \relates Arch */
235   extern const Arch Arch_armv7hl;
236   /** \relates Arch */
237   extern const Arch Arch_armv7l;
238   /** \relates Arch */
239   extern const Arch Arch_armv6hl;
240   /** \relates Arch */
241   extern const Arch Arch_armv6l;
242   /** \relates Arch */
243   extern const Arch Arch_armv5tejl;
244   /** \relates Arch */
245   extern const Arch Arch_armv5tel;
246   /** \relates Arch */
247   extern const Arch Arch_armv5l;
248   /** \relates Arch */
249   extern const Arch Arch_armv4tl;
250   /** \relates Arch */
251   extern const Arch Arch_armv4l;
252   /** \relates Arch */
253   extern const Arch Arch_armv3l;
254
255    /** \relates Arch */
256   extern const Arch Arch_sh3;
257
258   /** \relates Arch */
259   extern const Arch Arch_sh4;
260   /** \relates Arch */
261   extern const Arch Arch_sh4a;
262   //@}
263
264   ///////////////////////////////////////////////////////////////////
265
266   /** \relates Arch stream output. */
267   inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
268   { return str << obj.asString(); }
269
270   /** \name Equality based on string value. */
271   //@{
272   /** \relates Arch */
273   inline bool operator==( const Arch & lhs, const Arch & rhs )
274   { return lhs.asString() == rhs.asString(); }
275
276   /** \relates Arch */
277   inline bool operator==( const Arch & lhs, const std::string & rhs )
278   { return lhs.asString() == rhs; }
279
280   /** \relates Arch */
281   inline bool operator==( const std::string & lhs, const Arch & rhs )
282   { return lhs == rhs.asString(); }
283
284   /** \relates Arch */
285   inline bool operator!=( const Arch & lhs, const Arch & rhs )
286   { return !( lhs == rhs ); }
287
288   /** \relates Arch */
289   inline bool operator!=( const Arch & lhs, const std::string & rhs )
290   { return !( lhs == rhs ); }
291
292   /** \relates Arch */
293   inline bool operator!=( const std::string & lhs, const Arch & rhs )
294   { return !( lhs == rhs ); }
295   //@}
296
297   ///////////////////////////////////////////////////////////////////
298
299   /** Functor finding compatible architectures.
300    * \see Arch::compatibleWith
301   */
302   struct ArchCompatibleWith : public std::unary_function<Arch,bool>
303   {
304     /** The target architecture */
305     Arch _targetArch;
306     /** Ctor taking the target architecture */
307     ArchCompatibleWith( const Arch & targetArch_r )
308     : _targetArch( targetArch_r )
309     {}
310     /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
311     bool operator()( const Arch & rhs ) const
312     { return rhs.compatibleWith( _targetArch ); }
313   };
314
315   /////////////////////////////////////////////////////////////////
316 } // namespace zypp
317 ///////////////////////////////////////////////////////////////////
318
319 ///////////////////////////////////////////////////////////////////
320 namespace std
321 { /////////////////////////////////////////////////////////////////
322   /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
323   template<>
324     inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
325     { return lhs.compare( rhs ) < 0; }
326   /////////////////////////////////////////////////////////////////
327 } // namespace zypp
328 ///////////////////////////////////////////////////////////////////
329 #endif // ZYPP_ARCH_H