Arch: added builtin Arch variables (Arch_noarch, Arch_i386, ...)
[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   private:
53     /** String representation of Arch. */
54     std::string _value;
55   };
56   ///////////////////////////////////////////////////////////////////
57
58   //@{
59   /** \relates Arch Builtin architecture.
60    * Outside Arch, because some names, like \c i388, are used
61    * as \c #define, thus unusable as identifier.
62   */
63   extern const Arch Arch_noarch;
64
65   extern const Arch Arch_x86_64;
66   extern const Arch Arch_athlon;
67   extern const Arch Arch_i686;
68   extern const Arch Arch_i586;
69   extern const Arch Arch_i486;
70   extern const Arch Arch_i386;
71
72   extern const Arch Arch_s390x;
73   extern const Arch Arch_s390;
74
75   extern const Arch Arch_ppc64;
76   extern const Arch Arch_ppc;
77
78   extern const Arch Arch_ia64;
79   //@}
80
81   ///////////////////////////////////////////////////////////////////
82
83   inline Arch::Arch()
84   : _value( Arch_noarch._value )
85   {}
86
87   ///////////////////////////////////////////////////////////////////
88
89   //@{
90   /** \relates Arch */
91   inline std::ostream & operator<<( std::ostream & str, const Arch & obj )
92   { return str << obj.asString(); }
93
94
95   inline bool operator==( const Arch & lhs, const Arch & rhs )
96   { return lhs.asString() == rhs.asString(); }
97
98   inline bool operator==( const Arch & lhs, const std::string & rhs )
99   { return lhs.asString() == rhs; }
100
101   inline bool operator==( const std::string & lhs, const Arch & rhs )
102   { return lhs == rhs.asString(); }
103
104
105   inline bool operator!=( const Arch & lhs, const Arch & rhs )
106   { return !( lhs == rhs ); }
107
108   inline bool operator!=( const Arch & lhs, const std::string & rhs )
109   { return !( lhs == rhs ); }
110
111   inline bool operator!=( const std::string & lhs, const Arch & rhs )
112   { return !( lhs == rhs ); }
113
114   //@}
115
116   ///////////////////////////////////////////////////////////////////
117
118   /** Functor finding compatible architectures.
119    * \see Arch::compatibleWith
120   */
121   struct ArchCompatibleWith : public std::unary_function<Arch,bool>
122   {
123     /** The target architecture */
124     Arch _targetArch;
125     /** Ctor taking the target architecture */
126     ArchCompatibleWith( const Arch & targetArch_r )
127     : _targetArch( targetArch_r )
128     {}
129     /** Call Arch::compatibleWith ( \c _targetArch ) on \a rhs. */
130     bool operator()( const Arch & rhs ) const
131     { return rhs.compatibleWith( _targetArch ); }
132   };
133
134   /////////////////////////////////////////////////////////////////
135 } // namespace zypp
136 ///////////////////////////////////////////////////////////////////
137
138 ///////////////////////////////////////////////////////////////////
139 namespace std
140 { /////////////////////////////////////////////////////////////////
141   /** \relates Arch Order relation for std::container classes. */
142   template<>
143     inline bool less<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
144     { return lhs.asString() < rhs.asString(); }
145   /////////////////////////////////////////////////////////////////
146 } // namespace zypp
147 ///////////////////////////////////////////////////////////////////
148 #endif // ZYPP_ARCH_H