- Added Capability iterator to ResPool.
[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 <string>
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   ///////////////////////////////////////////////////////////////////
24   //
25   //    CLASS NAME : Arch
26   //
27   /** Architecture.
28    * \todo improve compatibleWith implementation
29    * \todo unify strings and optimize opertor==
30   */
31   class Arch
32   {
33   public:
34     /** Default ctor 'noarch' */
35     Arch();
36     /** Ctor from string. */
37     explicit
38     Arch( const std::string & rhs );
39     /** Dtor */
40     ~Arch()
41     {}
42     /** String representation of Arch. */
43     const std::string & asString() const
44     { return _value; }
45
46   public:
47     /** Compatibility relation.
48      * \return \c True iff \c this is compatible with \a rhs.
49     */
50     bool compatibleWith( const Arch & rhs ) const;
51
52     /** Order on Arch (arbitrary).
53      * \todo Adjust logical operators below to follow compare.
54     */
55     int compare( const Arch & rhs ) const
56     { return _value.compare( rhs._value ); }
57
58     /** Architecture of the current working system
59      * \return \c Arch.
60      * \todo Eliminate this, it's not task of a data type to
61      * detect and define what the system architecture is.
62     */
63     static const Arch System;
64
65   private:
66     /** String representation of Arch. */
67     std::string _value;
68   };
69   ///////////////////////////////////////////////////////////////////
70
71   /** \name Builtin architecture constants.
72    *
73    * Defined outside Arch as e.g. \c Arch_i386, because some names,
74    * like \c i388, are used as \c #define, thus unusable as identifier
75    * like \c Arch::i386.
76   */
77   //@{
78   /** \relates Arch */
79   extern const Arch Arch_noarch;
80
81   /** \relates Arch */
82   extern const Arch Arch_x86_64;
83   /** \relates Arch */
84   extern const Arch Arch_athlon;
85   /** \relates Arch */
86   extern const Arch Arch_i686;
87   /** \relates Arch */
88   extern const Arch Arch_i586;
89   /** \relates Arch */
90   extern const Arch Arch_i486;
91   /** \relates Arch */
92   extern const Arch Arch_i386;
93
94   /** \relates Arch */
95   extern const Arch Arch_s390x;
96   /** \relates Arch */
97   extern const Arch Arch_s390;
98
99   /** \relates Arch */
100   extern const Arch Arch_ppc64;
101   /** \relates Arch */
102   extern const Arch Arch_ppc;
103
104   /** \relates Arch */
105   extern const Arch Arch_ia64;
106   //@}
107
108   ///////////////////////////////////////////////////////////////////
109
110   inline Arch::Arch()
111   : _value( Arch_noarch._value )
112   {}
113
114   ///////////////////////////////////////////////////////////////////
115
116   /** \relates Arch stream output. */
117   inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
118   { return str << obj.asString(); }
119
120   /** \name Comparison based on string value. */
121   //@{
122   /** \relates Arch */
123   inline bool operator==( const Arch & lhs, const Arch & rhs )
124   { return lhs.asString() == rhs.asString(); }
125
126   /** \relates Arch */
127   inline bool operator==( const Arch & lhs, const std::string & rhs )
128   { return lhs.asString() == rhs; }
129
130   /** \relates Arch */
131   inline bool operator==( const std::string & lhs, const Arch & rhs )
132   { return lhs == rhs.asString(); }
133
134   /** \relates Arch */
135   inline bool operator!=( const Arch & lhs, const Arch & rhs )
136   { return !( lhs == rhs ); }
137
138   /** \relates Arch */
139   inline bool operator!=( const Arch & lhs, const std::string & rhs )
140   { return !( lhs == rhs ); }
141
142   /** \relates Arch */
143   inline bool operator!=( const std::string & lhs, const Arch & rhs )
144   { return !( lhs == rhs ); }
145   //@}
146
147   ///////////////////////////////////////////////////////////////////
148
149   /** Functor finding compatible architectures.
150    * \see Arch::compatibleWith
151   */
152   struct ArchCompatibleWith : public std::unary_function<Arch,bool>
153   {
154     /** The target architecture */
155     Arch _targetArch;
156     /** Ctor taking the target architecture */
157     ArchCompatibleWith( const Arch & targetArch_r )
158     : _targetArch( targetArch_r )
159     {}
160     /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
161     bool operator()( const Arch & rhs ) const
162     { return rhs.compatibleWith( _targetArch ); }
163   };
164
165   /////////////////////////////////////////////////////////////////
166 } // namespace zypp
167 ///////////////////////////////////////////////////////////////////
168
169 ///////////////////////////////////////////////////////////////////
170 namespace std
171 { /////////////////////////////////////////////////////////////////
172   /** \relates Arch Default order for std::container based on string value.*/
173   template<>
174     inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
175     { return lhs.asString() < rhs.asString(); }
176   /////////////////////////////////////////////////////////////////
177 } // namespace zypp
178 ///////////////////////////////////////////////////////////////////
179 #endif // ZYPP_ARCH_H