1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
20 #include "zypp/base/String.h"
21 #include "zypp/base/Iterator.h"
23 #include "zypp/IdStringType.h"
24 #include "zypp/RelCompare.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
39 /** Default ctor \ref Arc_noarch. */
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 );
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*.
54 /** String representation of Arch. */
55 IdString idStr() const;
57 const std::string & asString() const;
59 const char * c_str() const
60 { return asString().c_str(); }
62 /** Test for an empty Arch (this is \ref Arch_epmty, not \ref Arch_noarch ). */
64 { return asString().empty(); }
66 /** Size of the string representation. */
68 { return asString().size(); }
70 /** Expert backdoor. */
71 IdString::IdType id() const
72 { return idStr().id(); }
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.
81 bool isBuiltIn() const;
84 /** Compatibility relation.
85 * \return \c True iff \c this is compatible with \a targetArch_r.
87 * Arch_noarch.compatibleWith( ... ) ==> always true;
88 * Arch_i686.compatibleWith( Arch_x86_64 ) ==> true;
89 * Arch_x86_64.compatibleWith( Arch_i686 ) ==> false;
92 bool compatibleWith( const Arch & targetArch_r ) const;
95 * \return the arch before noarch if it's not a multilib arch
96 * (e.g. x86_64,sparc64v,sparc64,ppc64,s390x).
98 Arch baseArch() const;
100 /** \overload static version. */
101 static Arch baseArch( const Arch & targetArch_r )
102 { return targetArch_r.baseArch(); }
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.
109 int compare( const Arch & rhs ) const;
111 /** Arch comparison (static version). */
112 static int compare( const Arch & lhs, const Arch & rhs )
113 { return lhs.compare( rhs ); }
116 /** Reversed arch order, best Arch first. */
117 typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
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.
123 * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
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) ) )
129 * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
132 static CompatSet compatSet( const Arch & targetArch_r );
135 static std::string asString( const CompatSet & cset )
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) ) );
144 Arch( const CompatEntry & );
145 const CompatEntry * _entry;
147 ///////////////////////////////////////////////////////////////////
149 /** \name Builtin architecture constants.
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.
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
162 extern const Arch Arch_empty;
165 extern const Arch Arch_noarch;
168 extern const Arch Arch_pentium4;
170 extern const Arch Arch_pentium3;
173 extern const Arch Arch_x86_64;
175 extern const Arch Arch_athlon;
177 extern const Arch Arch_i686;
179 extern const Arch Arch_i586;
181 extern const Arch Arch_i486;
183 extern const Arch Arch_i386;
186 extern const Arch Arch_s390x;
188 extern const Arch Arch_s390;
191 extern const Arch Arch_ppc64le;
194 extern const Arch Arch_ppc64p7;
196 extern const Arch Arch_ppc64;
198 extern const Arch Arch_ppc;
201 extern const Arch Arch_ia64;
204 extern const Arch Arch_alphaev67;
206 extern const Arch Arch_alphaev6;
208 extern const Arch Arch_alphapca56;
210 extern const Arch Arch_alphaev56;
212 extern const Arch Arch_alphaev5;
214 extern const Arch Arch_alpha;
217 extern const Arch Arch_sparc64v;
219 extern const Arch Arch_sparc64;
221 extern const Arch Arch_sparcv9v;
223 extern const Arch Arch_sparcv9;
225 extern const Arch Arch_sparcv8;
227 extern const Arch Arch_sparc;
230 extern const Arch Arch_aarch64;
232 extern const Arch Arch_armv7tnhl;
234 extern const Arch Arch_armv7thl;
236 extern const Arch Arch_armv7nhl;
238 extern const Arch Arch_armv7hl;
240 extern const Arch Arch_armv7l;
242 extern const Arch Arch_armv6hl;
244 extern const Arch Arch_armv6l;
246 extern const Arch Arch_armv5tejl;
248 extern const Arch Arch_armv5tel;
250 extern const Arch Arch_armv5l;
252 extern const Arch Arch_armv4tl;
254 extern const Arch Arch_armv4l;
256 extern const Arch Arch_armv3l;
259 extern const Arch Arch_sh3;
262 extern const Arch Arch_sh4;
264 extern const Arch Arch_sh4a;
267 extern const Arch Arch_m68k;
270 extern const Arch Arch_mips;
272 extern const Arch Arch_mipsel;
274 extern const Arch Arch_mips64;
276 extern const Arch Arch_mips64el;
279 ///////////////////////////////////////////////////////////////////
281 /** \relates Arch stream output. */
282 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
283 { return str << obj.asString(); }
285 /** \relates Arch XML output. */
286 inline std::ostream & dumpAsXmlOn( std::ostream & str, const Arch & obj )
287 { return str << "<arch>" << obj << "</arch>"; }
289 /** \name Equality based on string value. */
292 inline bool operator==( const Arch & lhs, const Arch & rhs )
293 { return lhs.asString() == rhs.asString(); }
296 inline bool operator==( const Arch & lhs, const std::string & rhs )
297 { return lhs.asString() == rhs; }
300 inline bool operator==( const std::string & lhs, const Arch & rhs )
301 { return lhs == rhs.asString(); }
304 inline bool operator!=( const Arch & lhs, const Arch & rhs )
305 { return !( lhs == rhs ); }
308 inline bool operator!=( const Arch & lhs, const std::string & rhs )
309 { return !( lhs == rhs ); }
312 inline bool operator!=( const std::string & lhs, const Arch & rhs )
313 { return !( lhs == rhs ); }
316 ///////////////////////////////////////////////////////////////////
318 /** Functor finding compatible architectures.
319 * \see Arch::compatibleWith
321 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
323 /** The target architecture */
325 /** Ctor taking the target architecture */
326 ArchCompatibleWith( const Arch & targetArch_r )
327 : _targetArch( targetArch_r )
329 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
330 bool operator()( const Arch & rhs ) const
331 { return rhs.compatibleWith( _targetArch ); }
334 /////////////////////////////////////////////////////////////////
336 ///////////////////////////////////////////////////////////////////
338 ///////////////////////////////////////////////////////////////////
340 { /////////////////////////////////////////////////////////////////
341 /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
343 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
344 { return lhs.compare( rhs ) < 0; }
345 /////////////////////////////////////////////////////////////////
347 ///////////////////////////////////////////////////////////////////
348 #endif // ZYPP_ARCH_H