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 /** Compatibility relation.
48 * \return \c True iff \c this is compatible with \a targetArch_r.
50 * Arch_noarch.compatibleWith( ... ) ==> always true;
51 * Arch_i686.compatibleWith( Arch_x86_64 ) ==> true;
52 * Arch_x86_64.compatibleWith( Arch_i686 ) ==> false;
55 bool compatibleWith( const Arch & targetArch_r ) const;
58 * Primary key is the number of compatible Archs, then
59 * the string representation. Thus Arch_noarch is the
62 int compare( const Arch & rhs ) const;
64 /** Arch comparison (static version). */
65 static int compare( const Arch & lhs, const Arch & rhs )
66 { return lhs.compare( rhs ); }
69 /** Reversed arch order, best Arch first. */
70 typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
72 /** Return a set of all Arch's \compatible with a targetArch_r.
73 * \note The set is ordered according to compare, thus iterating
74 * will start at Arch_noarch.
76 * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
78 * cout << str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
79 * make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) )
82 * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
85 static CompatSet compatSet( const Arch & targetArch_r );
88 static std::string asString( const CompatSet & cset )
90 return str::join( make_transform_iterator( cset.begin(), std::mem_fun_ref(&Arch::asString) ),
91 make_transform_iterator( cset.end(), std::mem_fun_ref(&Arch::asString) ) );
97 Arch( const CompatEntry & );
98 const CompatEntry * _entry;
100 ///////////////////////////////////////////////////////////////////
102 /** \name Builtin architecture constants.
104 * Defined outside Arch as e.g. \c Arch_i386, because some names,
105 * like \c i388, are used as \c #define, thus unusable as identifier
106 * like \c Arch::i386.
110 extern const Arch Arch_noarch;
111 /** \todo actually not an Arch but kind of resolvable. */
112 extern const Arch Arch_src;
115 extern const Arch Arch_x86_64;
117 extern const Arch Arch_athlon;
119 extern const Arch Arch_i686;
121 extern const Arch Arch_i586;
123 extern const Arch Arch_i486;
125 extern const Arch Arch_i386;
128 extern const Arch Arch_s390x;
130 extern const Arch Arch_s390;
133 extern const Arch Arch_ppc64;
135 extern const Arch Arch_ppc;
138 extern const Arch Arch_ia64;
141 ///////////////////////////////////////////////////////////////////
143 /** \relates Arch stream output. */
144 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
145 { return str << obj.asString(); }
147 /** \name Equality based on string value. */
150 inline bool operator==( const Arch & lhs, const Arch & rhs )
151 { return lhs.asString() == rhs.asString(); }
154 inline bool operator==( const Arch & lhs, const std::string & rhs )
155 { return lhs.asString() == rhs; }
158 inline bool operator==( const std::string & lhs, const Arch & rhs )
159 { return lhs == rhs.asString(); }
162 inline bool operator!=( const Arch & lhs, const Arch & rhs )
163 { return !( lhs == rhs ); }
166 inline bool operator!=( const Arch & lhs, const std::string & rhs )
167 { return !( lhs == rhs ); }
170 inline bool operator!=( const std::string & lhs, const Arch & rhs )
171 { return !( lhs == rhs ); }
174 ///////////////////////////////////////////////////////////////////
176 /** Functor finding compatible architectures.
177 * \see Arch::compatibleWith
179 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
181 /** The target architecture */
183 /** Ctor taking the target architecture */
184 ArchCompatibleWith( const Arch & targetArch_r )
185 : _targetArch( targetArch_r )
187 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
188 bool operator()( const Arch & rhs ) const
189 { return rhs.compatibleWith( _targetArch ); }
192 /////////////////////////////////////////////////////////////////
194 ///////////////////////////////////////////////////////////////////
196 ///////////////////////////////////////////////////////////////////
198 { /////////////////////////////////////////////////////////////////
199 /** \relates Arch Default order for std::container based Arch::compare.*/
201 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
202 { return lhs.compare( rhs ) < 0; }
203 /////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////
206 #endif // ZYPP_ARCH_H