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 * Primary key is the number of compatible Archs, then
96 * the string representation. Thus Arch_noarch is the
99 int compare( const Arch & rhs ) const;
101 /** Arch comparison (static version). */
102 static int compare( const Arch & lhs, const Arch & rhs )
103 { return lhs.compare( rhs ); }
106 /** Reversed arch order, best Arch first. */
107 typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
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.
113 * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
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) ) )
119 * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
122 static CompatSet compatSet( const Arch & targetArch_r );
125 static std::string asString( const CompatSet & cset )
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) ) );
134 Arch( const CompatEntry & );
135 const CompatEntry * _entry;
137 ///////////////////////////////////////////////////////////////////
139 /** \name Builtin architecture constants.
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.
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
152 extern const Arch Arch_empty;
155 extern const Arch Arch_noarch;
158 extern const Arch Arch_pentium4;
160 extern const Arch Arch_pentium3;
163 extern const Arch Arch_x86_64;
165 extern const Arch Arch_athlon;
167 extern const Arch Arch_i686;
169 extern const Arch Arch_i586;
171 extern const Arch Arch_i486;
173 extern const Arch Arch_i386;
176 extern const Arch Arch_s390x;
178 extern const Arch Arch_s390;
181 extern const Arch Arch_ppc64;
183 extern const Arch Arch_ppc;
186 extern const Arch Arch_ia64;
189 extern const Arch Arch_alphaev67;
191 extern const Arch Arch_alphaev6;
193 extern const Arch Arch_alphapca56;
195 extern const Arch Arch_alphaev56;
197 extern const Arch Arch_alphaev5;
199 extern const Arch Arch_alpha;
202 extern const Arch Arch_sparc64;
204 extern const Arch Arch_sparcv9;
206 extern const Arch Arch_sparcv8;
208 extern const Arch Arch_sparc;
211 extern const Arch Arch_armv6l;
213 extern const Arch Arch_armv5tejl;
215 extern const Arch Arch_armv5tel;
217 extern const Arch Arch_armv5l;
219 extern const Arch Arch_armv4tl;
221 extern const Arch Arch_armv4l;
223 extern const Arch Arch_armv3l;
226 extern const Arch Arch_sh3;
229 extern const Arch Arch_sh4;
231 extern const Arch Arch_sh4a;
234 ///////////////////////////////////////////////////////////////////
236 /** \relates Arch stream output. */
237 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
238 { return str << obj.asString(); }
240 /** \name Equality based on string value. */
243 inline bool operator==( const Arch & lhs, const Arch & rhs )
244 { return lhs.asString() == rhs.asString(); }
247 inline bool operator==( const Arch & lhs, const std::string & rhs )
248 { return lhs.asString() == rhs; }
251 inline bool operator==( const std::string & lhs, const Arch & rhs )
252 { return lhs == rhs.asString(); }
255 inline bool operator!=( const Arch & lhs, const Arch & rhs )
256 { return !( lhs == rhs ); }
259 inline bool operator!=( const Arch & lhs, const std::string & rhs )
260 { return !( lhs == rhs ); }
263 inline bool operator!=( const std::string & lhs, const Arch & rhs )
264 { return !( lhs == rhs ); }
267 ///////////////////////////////////////////////////////////////////
269 /** Functor finding compatible architectures.
270 * \see Arch::compatibleWith
272 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
274 /** The target architecture */
276 /** Ctor taking the target architecture */
277 ArchCompatibleWith( const Arch & targetArch_r )
278 : _targetArch( targetArch_r )
280 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
281 bool operator()( const Arch & rhs ) const
282 { return rhs.compatibleWith( _targetArch ); }
285 /////////////////////////////////////////////////////////////////
287 ///////////////////////////////////////////////////////////////////
289 ///////////////////////////////////////////////////////////////////
291 { /////////////////////////////////////////////////////////////////
292 /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
294 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
295 { return lhs.compare( rhs ) < 0; }
296 /////////////////////////////////////////////////////////////////
298 ///////////////////////////////////////////////////////////////////
299 #endif // ZYPP_ARCH_H