1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
20 #include "zypp/RelCompare.h"
21 #include "zypp/base/String.h"
22 #include "zypp/base/Iterator.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
37 /** Default ctor 'noarch' */
39 /** Ctor from string. */
41 Arch( const std::string & rhs );
44 /** String representation of Arch. */
45 const std::string & asString() const;
47 /** Test for an empty Arch (this is "", not Arch_noarch). */
49 { return asString().empty(); }
51 /** Compatibility relation.
52 * \return \c True iff \c this is compatible with \a targetArch_r.
54 * Arch_noarch.compatibleWith( ... ) ==> always true;
55 * Arch_i686.compatibleWith( Arch_x86_64 ) ==> true;
56 * Arch_x86_64.compatibleWith( Arch_i686 ) ==> false;
59 bool compatibleWith( const Arch & targetArch_r ) const;
62 * Primary key is the number of compatible Archs, then
63 * the string representation. Thus Arch_noarch is the
66 int compare( const Arch & rhs ) const;
68 /** Arch comparison (static version). */
69 static int compare( const Arch & lhs, const Arch & rhs )
70 { return lhs.compare( rhs ); }
73 /** Reversed arch order, best Arch first. */
74 typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
76 /** Return a set of all Arch's \ref compatibleWith a \a targetArch_r.
77 * \note The set is ordered according to compare, thus iterating
78 * will start at \a targetArch_r and end with \c Arch_noarch.
80 * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
82 * cout << str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
83 * make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) )
86 * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
89 static CompatSet compatSet( const Arch & targetArch_r );
92 static std::string asString( const CompatSet & cset )
94 return str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
95 make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) );
101 Arch( const CompatEntry & );
102 const CompatEntry * _entry;
104 ///////////////////////////////////////////////////////////////////
106 /** \name Builtin architecture constants.
108 * Defined outside Arch as e.g. \c Arch_i386, because some names,
109 * like \c i388, are used as \c #define, thus unusable as identifier
110 * like \c Arch::i386.
114 extern const Arch Arch_noarch;
117 extern const Arch Arch_x86_64;
119 extern const Arch Arch_athlon;
121 extern const Arch Arch_i686;
123 extern const Arch Arch_i586;
125 extern const Arch Arch_i486;
127 extern const Arch Arch_i386;
130 extern const Arch Arch_s390x;
132 extern const Arch Arch_s390;
135 extern const Arch Arch_ppc64;
137 extern const Arch Arch_ppc;
140 extern const Arch Arch_ia64;
143 ///////////////////////////////////////////////////////////////////
145 /** \relates Arch stream output. */
146 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
147 { return str << obj.asString(); }
149 /** \name Equality based on string value. */
152 inline bool operator==( const Arch & lhs, const Arch & rhs )
153 { return lhs.asString() == rhs.asString(); }
156 inline bool operator==( const Arch & lhs, const std::string & rhs )
157 { return lhs.asString() == rhs; }
160 inline bool operator==( const std::string & lhs, const Arch & rhs )
161 { return lhs == rhs.asString(); }
164 inline bool operator!=( const Arch & lhs, const Arch & rhs )
165 { return !( lhs == rhs ); }
168 inline bool operator!=( const Arch & lhs, const std::string & rhs )
169 { return !( lhs == rhs ); }
172 inline bool operator!=( const std::string & lhs, const Arch & rhs )
173 { return !( lhs == rhs ); }
176 ///////////////////////////////////////////////////////////////////
178 /** Functor finding compatible architectures.
179 * \see Arch::compatibleWith
181 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
183 /** The target architecture */
185 /** Ctor taking the target architecture */
186 ArchCompatibleWith( const Arch & targetArch_r )
187 : _targetArch( targetArch_r )
189 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
190 bool operator()( const Arch & rhs ) const
191 { return rhs.compatibleWith( _targetArch ); }
194 /////////////////////////////////////////////////////////////////
196 ///////////////////////////////////////////////////////////////////
198 ///////////////////////////////////////////////////////////////////
200 { /////////////////////////////////////////////////////////////////
201 /** \relates zypp::Arch Default order for std::container based Arch::compare.*/
203 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
204 { return lhs.compare( rhs ) < 0; }
205 /////////////////////////////////////////////////////////////////
207 ///////////////////////////////////////////////////////////////////
208 #endif // ZYPP_ARCH_H