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_ppc64p7;
193 extern const Arch Arch_ppc64;
195 extern const Arch Arch_ppc;
198 extern const Arch Arch_ia64;
201 extern const Arch Arch_alphaev67;
203 extern const Arch Arch_alphaev6;
205 extern const Arch Arch_alphapca56;
207 extern const Arch Arch_alphaev56;
209 extern const Arch Arch_alphaev5;
211 extern const Arch Arch_alpha;
214 extern const Arch Arch_sparc64v;
216 extern const Arch Arch_sparc64;
218 extern const Arch Arch_sparcv9v;
220 extern const Arch Arch_sparcv9;
222 extern const Arch Arch_sparcv8;
224 extern const Arch Arch_sparc;
227 extern const Arch Arch_aarch64;
229 extern const Arch Arch_armv7tnhl;
231 extern const Arch Arch_armv7thl;
233 extern const Arch Arch_armv7nhl;
235 extern const Arch Arch_armv7hl;
237 extern const Arch Arch_armv7l;
239 extern const Arch Arch_armv6hl;
241 extern const Arch Arch_armv6l;
243 extern const Arch Arch_armv5tejl;
245 extern const Arch Arch_armv5tel;
247 extern const Arch Arch_armv5l;
249 extern const Arch Arch_armv4tl;
251 extern const Arch Arch_armv4l;
253 extern const Arch Arch_armv3l;
256 extern const Arch Arch_sh3;
259 extern const Arch Arch_sh4;
261 extern const Arch Arch_sh4a;
264 ///////////////////////////////////////////////////////////////////
266 /** \relates Arch stream output. */
267 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
268 { return str << obj.asString(); }
270 /** \name Equality based on string value. */
273 inline bool operator==( const Arch & lhs, const Arch & rhs )
274 { return lhs.asString() == rhs.asString(); }
277 inline bool operator==( const Arch & lhs, const std::string & rhs )
278 { return lhs.asString() == rhs; }
281 inline bool operator==( const std::string & lhs, const Arch & rhs )
282 { return lhs == rhs.asString(); }
285 inline bool operator!=( const Arch & lhs, const Arch & rhs )
286 { return !( lhs == rhs ); }
289 inline bool operator!=( const Arch & lhs, const std::string & rhs )
290 { return !( lhs == rhs ); }
293 inline bool operator!=( const std::string & lhs, const Arch & rhs )
294 { return !( lhs == rhs ); }
297 ///////////////////////////////////////////////////////////////////
299 /** Functor finding compatible architectures.
300 * \see Arch::compatibleWith
302 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
304 /** The target architecture */
306 /** Ctor taking the target architecture */
307 ArchCompatibleWith( const Arch & targetArch_r )
308 : _targetArch( targetArch_r )
310 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
311 bool operator()( const Arch & rhs ) const
312 { return rhs.compatibleWith( _targetArch ); }
315 /////////////////////////////////////////////////////////////////
317 ///////////////////////////////////////////////////////////////////
319 ///////////////////////////////////////////////////////////////////
321 { /////////////////////////////////////////////////////////////////
322 /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
324 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
325 { return lhs.compare( rhs ) < 0; }
326 /////////////////////////////////////////////////////////////////
328 ///////////////////////////////////////////////////////////////////
329 #endif // ZYPP_ARCH_H