Arch: added builtin Arch variables (Arch_noarch, Arch_i386, ...)
[platform/upstream/libzypp.git] / zypp / Arch.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Arch.cc
10  *
11 */
12 #include <iostream>
13 #include <set>
14
15 #include "zypp/Arch.h"
16
17 using namespace std;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace
21 { /////////////////////////////////////////////////////////////////
22
23   /** Dumb Arch compat table
24    * \todo improve
25   */
26   struct CompatTable
27   {
28     static set<string> _compatTable;
29
30     /** \return Whether \a lhs is compatible with \a rhs. */
31     static bool compatible( const zypp::Arch & lhs, const zypp::Arch & rhs )
32     {
33       if ( lhs == zypp::Arch_noarch )
34         return true;
35
36       if ( _compatTable.empty() )
37         {
38           // initialize
39 #define DEF_COMPAT(L,R) _compatTable.insert( #L "|" #R )
40           DEF_COMPAT( noarch,   i386 );
41           DEF_COMPAT( noarch,   i486 );
42           DEF_COMPAT( i386,     i486 );
43           DEF_COMPAT( noarch,   i586 );
44           DEF_COMPAT( i386,     i586 );
45           DEF_COMPAT( i486,     i586 );
46           DEF_COMPAT( noarch,   i686 );
47           DEF_COMPAT( i386,     i686 );
48           DEF_COMPAT( i486,     i686 );
49           DEF_COMPAT( i586,     i686 );
50           DEF_COMPAT( noarch,   athlon );
51           DEF_COMPAT( i386,     athlon );
52           DEF_COMPAT( i486,     athlon );
53           DEF_COMPAT( i586,     athlon );
54           DEF_COMPAT( i686,     athlon );
55           DEF_COMPAT( noarch,   x86_64 );
56           DEF_COMPAT( i386,     x86_64 );
57           DEF_COMPAT( i486,     x86_64 );
58           DEF_COMPAT( i586,     x86_64 );
59           DEF_COMPAT( i686,     x86_64 );
60           DEF_COMPAT( athlon,   x86_64 );
61
62           DEF_COMPAT( noarch,   s390 );
63           DEF_COMPAT( noarch,   s390x );
64           DEF_COMPAT( s390,     s390x );
65
66           DEF_COMPAT( noarch,   ppc );
67           DEF_COMPAT( noarch,   ppc64 );
68           DEF_COMPAT( ppc,      ppc64 );
69
70           DEF_COMPAT( noarch,   ia64 );
71 #undef DEF_COMPAT
72         }
73
74       return _compatTable.find( lhs.asString()+"|"+rhs.asString() )
75              != _compatTable.end();
76     }
77   };
78
79   set<string> CompatTable::_compatTable;
80
81   /////////////////////////////////////////////////////////////////
82 } // namespace
83 ///////////////////////////////////////////////////////////////////
84
85 ///////////////////////////////////////////////////////////////////
86 namespace zypp
87 { /////////////////////////////////////////////////////////////////
88
89   ///////////////////////////////////////////////////////////////////
90 #define DEF_BUILTIN(A) const Arch Arch_##A( #A )
91
92   DEF_BUILTIN( noarch );
93
94   DEF_BUILTIN( x86_64 );
95   DEF_BUILTIN( athlon );
96   DEF_BUILTIN( i686 );
97   DEF_BUILTIN( i586 );
98   DEF_BUILTIN( i486 );
99   DEF_BUILTIN( i386 );
100
101   DEF_BUILTIN( s390x );
102   DEF_BUILTIN( s390 );
103
104   DEF_BUILTIN( ppc64 );
105   DEF_BUILTIN( ppc );
106
107   DEF_BUILTIN( ia64 );
108
109 #undef DEF_BUILTIN
110   ///////////////////////////////////////////////////////////////////
111
112   ///////////////////////////////////////////////////////////////////
113   //
114   //    METHOD NAME : Arch::Arch
115   //    METHOD TYPE : Ctor
116   //
117   Arch::Arch( const std::string & rhs )
118   : _value( rhs )
119   {}
120
121   ///////////////////////////////////////////////////////////////////
122   //
123   //    METHOD NAME : Arch::compatibleWith
124   //    METHOD TYPE : bool
125   //
126   bool Arch::compatibleWith( const Arch & rhs ) const
127   {
128     return CompatTable::compatible( *this, rhs );
129   }
130
131   /////////////////////////////////////////////////////////////////
132 } // namespace zypp
133 ///////////////////////////////////////////////////////////////////