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;
113 extern const Arch Arch_x86_64;
115 extern const Arch Arch_athlon;
117 extern const Arch Arch_i686;
119 extern const Arch Arch_i586;
121 extern const Arch Arch_i486;
123 extern const Arch Arch_i386;
126 extern const Arch Arch_s390x;
128 extern const Arch Arch_s390;
131 extern const Arch Arch_ppc64;
133 extern const Arch Arch_ppc;
136 extern const Arch Arch_ia64;
139 ///////////////////////////////////////////////////////////////////
141 /** \relates Arch stream output. */
142 inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
143 { return str << obj.asString(); }
145 /** \name Equality based on string value. */
148 inline bool operator==( const Arch & lhs, const Arch & rhs )
149 { return lhs.asString() == rhs.asString(); }
152 inline bool operator==( const Arch & lhs, const std::string & rhs )
153 { return lhs.asString() == rhs; }
156 inline bool operator==( const std::string & lhs, const Arch & rhs )
157 { return lhs == rhs.asString(); }
160 inline bool operator!=( const Arch & lhs, const Arch & rhs )
161 { return !( lhs == rhs ); }
164 inline bool operator!=( const Arch & lhs, const std::string & rhs )
165 { return !( lhs == rhs ); }
168 inline bool operator!=( const std::string & lhs, const Arch & rhs )
169 { return !( lhs == rhs ); }
172 ///////////////////////////////////////////////////////////////////
174 /** Functor finding compatible architectures.
175 * \see Arch::compatibleWith
177 struct ArchCompatibleWith : public std::unary_function<Arch,bool>
179 /** The target architecture */
181 /** Ctor taking the target architecture */
182 ArchCompatibleWith( const Arch & targetArch_r )
183 : _targetArch( targetArch_r )
185 /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
186 bool operator()( const Arch & rhs ) const
187 { return rhs.compatibleWith( _targetArch ); }
190 /////////////////////////////////////////////////////////////////
192 ///////////////////////////////////////////////////////////////////
194 ///////////////////////////////////////////////////////////////////
196 { /////////////////////////////////////////////////////////////////
197 /** \relates Arch Default order for std::container based Arch::compare.*/
199 inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
200 { return lhs.compare( rhs ) < 0; }
201 /////////////////////////////////////////////////////////////////
203 ///////////////////////////////////////////////////////////////////
204 #endif // ZYPP_ARCH_H