remove 'Arch_src'
[platform/upstream/libzypp.git] / zypp / Arch.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Arch.h
10  *
11 */
12 #ifndef ZYPP_ARCH_H
13 #define ZYPP_ARCH_H
14
15 #include <iosfwd>
16 #include <functional>
17 #include <set>
18 #include <string>
19
20 #include "zypp/RelCompare.h"
21 #include "zypp/base/String.h"
22 #include "zypp/base/Iterator.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27
28   ///////////////////////////////////////////////////////////////////
29   //
30   //    CLASS NAME : Arch
31   //
32   /** Architecture.
33   */
34   class Arch
35   {
36   public:
37     /** Default ctor 'noarch' */
38     Arch();
39     /** Ctor from string. */
40     explicit
41     Arch( const std::string & rhs );
42
43   public:
44     /** String representation of Arch. */
45     const std::string & asString() const;
46
47     /** Compatibility relation.
48      * \return \c True iff \c this is compatible with \a targetArch_r.
49      * \code
50      * Arch_noarch.compatibleWith( ... )       ==> always true;
51      * Arch_i686.compatibleWith( Arch_x86_64 ) ==> true;
52      * Arch_x86_64.compatibleWith( Arch_i686 ) ==> false;
53      * \endcode
54     */
55     bool compatibleWith( const Arch & targetArch_r ) const;
56
57     /** Arch comparison.
58      * Primary key is the number of compatible Archs, then
59      * the string representation. Thus Arch_noarch is the
60      * least Arch.
61     */
62     int compare( const Arch & rhs ) const;
63
64     /** Arch comparison (static version). */
65     static int compare( const Arch & lhs, const Arch & rhs )
66     { return lhs.compare( rhs ); }
67
68   public:
69     /** Reversed arch order, best Arch first. */
70     typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
71
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.
75      * \code
76      * Arch::CompatSet cset( Arch::compatSet( Arch_x86_64 ) );
77      *
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) ) )
80      *      << endl;
81      *
82      * // Prints: x86_64 athlon i686 i586 i486 i386 noarch
83      * \endcode
84     */
85     static CompatSet compatSet( const Arch & targetArch_r );
86
87     /** */
88     static std::string asString( const CompatSet & cset )
89     {
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) ) );
92     }
93
94   public:
95     struct CompatEntry;
96   private:
97     Arch( const CompatEntry & );
98     const CompatEntry * _entry;
99   };
100   ///////////////////////////////////////////////////////////////////
101
102   /** \name Builtin architecture constants.
103    *
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.
107   */
108   //@{
109   /** \relates Arch */
110   extern const Arch Arch_noarch;
111
112   /** \relates Arch */
113   extern const Arch Arch_x86_64;
114   /** \relates Arch */
115   extern const Arch Arch_athlon;
116   /** \relates Arch */
117   extern const Arch Arch_i686;
118   /** \relates Arch */
119   extern const Arch Arch_i586;
120   /** \relates Arch */
121   extern const Arch Arch_i486;
122   /** \relates Arch */
123   extern const Arch Arch_i386;
124
125   /** \relates Arch */
126   extern const Arch Arch_s390x;
127   /** \relates Arch */
128   extern const Arch Arch_s390;
129
130   /** \relates Arch */
131   extern const Arch Arch_ppc64;
132   /** \relates Arch */
133   extern const Arch Arch_ppc;
134
135   /** \relates Arch */
136   extern const Arch Arch_ia64;
137   //@}
138
139   ///////////////////////////////////////////////////////////////////
140
141   /** \relates Arch stream output. */
142   inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
143   { return str << obj.asString(); }
144
145   /** \name Equality based on string value. */
146   //@{
147   /** \relates Arch */
148   inline bool operator==( const Arch & lhs, const Arch & rhs )
149   { return lhs.asString() == rhs.asString(); }
150
151   /** \relates Arch */
152   inline bool operator==( const Arch & lhs, const std::string & rhs )
153   { return lhs.asString() == rhs; }
154
155   /** \relates Arch */
156   inline bool operator==( const std::string & lhs, const Arch & rhs )
157   { return lhs == rhs.asString(); }
158
159   /** \relates Arch */
160   inline bool operator!=( const Arch & lhs, const Arch & rhs )
161   { return !( lhs == rhs ); }
162
163   /** \relates Arch */
164   inline bool operator!=( const Arch & lhs, const std::string & rhs )
165   { return !( lhs == rhs ); }
166
167   /** \relates Arch */
168   inline bool operator!=( const std::string & lhs, const Arch & rhs )
169   { return !( lhs == rhs ); }
170   //@}
171
172   ///////////////////////////////////////////////////////////////////
173
174   /** Functor finding compatible architectures.
175    * \see Arch::compatibleWith
176   */
177   struct ArchCompatibleWith : public std::unary_function<Arch,bool>
178   {
179     /** The target architecture */
180     Arch _targetArch;
181     /** Ctor taking the target architecture */
182     ArchCompatibleWith( const Arch & targetArch_r )
183     : _targetArch( targetArch_r )
184     {}
185     /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
186     bool operator()( const Arch & rhs ) const
187     { return rhs.compatibleWith( _targetArch ); }
188   };
189
190   /////////////////////////////////////////////////////////////////
191 } // namespace zypp
192 ///////////////////////////////////////////////////////////////////
193
194 ///////////////////////////////////////////////////////////////////
195 namespace std
196 { /////////////////////////////////////////////////////////////////
197   /** \relates Arch Default order for std::container based Arch::compare.*/
198   template<>
199     inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
200     { return lhs.compare( rhs ) < 0; }
201   /////////////////////////////////////////////////////////////////
202 } // namespace zypp
203 ///////////////////////////////////////////////////////////////////
204 #endif // ZYPP_ARCH_H