- Adapt zypp-query-pool to new product handling.
[platform/upstream/libzypp.git] / zypp / ResTraits.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResTraits.h
10  *
11 */
12 #ifndef ZYPP_RESTRAITS_H
13 #define ZYPP_RESTRAITS_H
14
15 #include "zypp/base/PtrTypes.h"
16 #include "zypp/ResKind.h"
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21
22   ///////////////////////////////////////////////////////////////////
23   namespace traits
24   { /////////////////////////////////////////////////////////////////
25
26     /** Those are denoted to be installed, if the
27      *  solver verifies them as being satisfied. */
28     inline bool isPseudoInstalled( ResKind kind_r )
29     { return( kind_r == ResKind::patch || kind_r == ResKind::pattern ); }
30
31     /////////////////////////////////////////////////////////////////
32   } // namespace traits
33   ///////////////////////////////////////////////////////////////////
34
35    /** \defgroup ZYPP_RESOLVABLE_SMART_POINTER_TYPES
36    * Resolvable smart pointer types.
37    *
38    * Forward declaration of all Resolvable smart pointer
39    * types provided in \c ResTraits.h (recommended in header files):
40    * \code
41    * #include<zypp/ResTraits.h>
42    *
43    * Resolvable_Ptr                      // Resolvable *
44    * ResTraits<Resolvable>::PtrType      // same as above
45    *
46    * Resolvable_constPtr                 // const Resolvable *
47    * ResTraits<Resolvable>::constPtrType // same as above
48    * \endcode
49    *
50    * Synonym, but requires \c Resolvable.h being included:
51    * \code
52    * #include<zypp/Resolvable.h>
53    *
54    * Resolvable::Ptr        // same as Resolvable_Ptr but requires Resolvable.h
55    * Resolvable::constPtr   // same as Resolvable_constPtr but requires Resolvable.h
56    * \endcode
57    *
58    * \note When adding a \c NewResolvable type here, dont forgett to
59    * put <tt>IMPL_PTR_TYPE(NewResolvable);</tt> into the \c NewResolvable.cc.
60    */
61   //@{
62   DEFINE_PTR_TYPE( Resolvable );
63   DEFINE_PTR_TYPE( ResObject );
64
65   DEFINE_PTR_TYPE( Package );
66   DEFINE_PTR_TYPE( SrcPackage );
67   DEFINE_PTR_TYPE( Pattern );
68   DEFINE_PTR_TYPE( Product );
69   DEFINE_PTR_TYPE( Patch );
70   //@}
71
72   /** Frequently associated. */
73   class PoolItem;
74
75   /** ResTraits. Defines common types and the ResKind value. */
76   template<typename _Res>
77     struct ResTraits
78     {
79       typedef ResKind                   KindType;
80       typedef intrusive_ptr<_Res>       PtrType;
81       typedef intrusive_ptr<const _Res> constPtrType;
82
83       static const ResKind              kind;
84
85       /** Those are denoted to be installed, if the
86        *  solver verifies them as being satisfied. */
87       static bool isPseudoInstalled()   { return traits::isPseudoInstalled( kind ); }
88     };
89
90   /** ResTraits specialisation for Resolvable.
91    * Resolvable is common base and has no Kind value.
92    */
93   template<>
94     struct ResTraits<Resolvable>
95     {
96       typedef ResKind                         KindType;
97       typedef intrusive_ptr<Resolvable>       PtrType;
98       typedef intrusive_ptr<const Resolvable> constPtrType;
99     };
100
101   /** ResTraits specialisation for ResObject.
102    * ResObject is common base and has no Kind value.
103    */
104   template<>
105     struct ResTraits<ResObject>
106     {
107       typedef ResKind                        KindType;
108       typedef intrusive_ptr<ResObject>       PtrType;
109       typedef intrusive_ptr<const ResObject> constPtrType;
110     };
111
112   /** Convenient access to well known ResKinds.
113    * \code
114    * ResKind packagekind = ResKind::package;
115    * ResKind packagekind = resKind<Package>();
116    * \endcode
117   */
118   template<typename _Res>
119     inline ResKind resKind() { return ResTraits<_Res>::kind; }
120
121   /** Convenient test for ResKinds.
122    * \code
123    * ResKind value;
124    * if ( ResKind::package == value )
125    * if ( resKind<Package>() == value )
126    * if ( isKind<Package>( value ) )
127    * \endcode
128    */
129   template<typename _Res>
130     inline bool isKind( const ResKind & val_r )
131     { return( resKind<_Res>() == val_r ); }
132   /** \overload */
133   template<typename _Res>
134     inline bool isKind( const std::string & val_r )
135     { return( resKind<_Res>() == val_r ); }
136   /** \overload */
137   template<typename _Res>
138     inline bool isKind( const char * val_r )
139     { return( resKind<_Res>() == val_r ); }
140
141
142   /////////////////////////////////////////////////////////////////
143 } // namespace zypp
144 ///////////////////////////////////////////////////////////////////
145 #endif // ZYPP_RESTRAITS_H