1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResTraits.h
12 #ifndef ZYPP_RESTRAITS_H
13 #define ZYPP_RESTRAITS_H
15 #include <zypp/base/PtrTypes.h>
16 #include <zypp/ResKind.h>
18 ///////////////////////////////////////////////////////////////////
20 { /////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
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 ); }
31 /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 /** \defgroup ZYPP_RESOLVABLE_SMART_POINTER_TYPES
36 * Resolvable smart pointer types.
38 * Forward declaration of all Resolvable smart pointer
39 * types provided in \c ResTraits.h (recommended in header files):
41 * #include "zypp/ResTraits.h"
43 * Resolvable_Ptr // Resolvable *
44 * ResTraits<Resolvable>::PtrType // same as above
46 * Resolvable_constPtr // const Resolvable *
47 * ResTraits<Resolvable>::constPtrType // same as above
50 * Synonym, but requires \c Resolvable.h being included:
52 * #include "zypp/Resolvable.h"
54 * Resolvable::Ptr // same as Resolvable_Ptr but requires Resolvable.h
55 * Resolvable::constPtr // same as Resolvable_constPtr but requires Resolvable.h
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 * Also check class \ref ResKind, ResKind.cc, ResObject.cc(makeResObject)
63 DEFINE_PTR_TYPE( Resolvable );
64 DEFINE_PTR_TYPE( ResObject );
66 DEFINE_PTR_TYPE( Package );
67 DEFINE_PTR_TYPE( SrcPackage );
68 DEFINE_PTR_TYPE( Pattern );
69 DEFINE_PTR_TYPE( Product );
70 DEFINE_PTR_TYPE( Patch );
71 DEFINE_PTR_TYPE( Application );
74 /** Frequently associated. */
77 /** ResTraits. Defines common types and the ResKind value. */
78 template<typename TRes>
81 typedef ResKind KindType;
82 typedef intrusive_ptr<TRes> PtrType;
83 typedef intrusive_ptr<const TRes> constPtrType;
85 static const ResKind kind; ///< Defined in ResKind.cc
87 /** Those are denoted to be installed, if the
88 * solver verifies them as being satisfied. */
89 static bool isPseudoInstalled() { return traits::isPseudoInstalled( kind ); }
92 // Defined in ResKind.cc
93 template<> const ResKind ResTraits<Package>::kind;
94 template<> const ResKind ResTraits<Patch>::kind;
95 template<> const ResKind ResTraits<Pattern>::kind;
96 template<> const ResKind ResTraits<Product>::kind;
97 template<> const ResKind ResTraits<SrcPackage>::kind;
98 template<> const ResKind ResTraits<Application>::kind;
100 /** ResTraits specialisation for Resolvable.
101 * Resolvable is common base and has no Kind value.
104 struct ResTraits<Resolvable>
106 typedef ResKind KindType;
107 typedef intrusive_ptr<Resolvable> PtrType;
108 typedef intrusive_ptr<const Resolvable> constPtrType;
111 /** ResTraits specialisation for ResObject.
112 * ResObject is common base and has no Kind value.
115 struct ResTraits<ResObject>
117 typedef ResKind KindType;
118 typedef intrusive_ptr<ResObject> PtrType;
119 typedef intrusive_ptr<const ResObject> constPtrType;
122 /** Convenient access to well known ResKinds.
124 * ResKind packagekind = ResKind::package;
125 * ResKind packagekind = resKind<Package>();
128 template<typename TRes>
129 inline ResKind resKind() { return ResTraits<TRes>::kind; }
131 /** Convenient test for ResKinds.
134 * if ( ResKind::package == value )
135 * if ( resKind<Package>() == value )
136 * if ( isKind<Package>( value ) )
139 template<typename TRes>
140 inline bool isKind( const ResKind & val_r )
141 { return( resKind<TRes>() == val_r ); }
143 template<typename TRes>
144 inline bool isKind( const std::string & val_r )
145 { return( resKind<TRes>() == val_r ); }
147 template<typename TRes>
148 inline bool isKind( const char * val_r )
149 { return( resKind<TRes>() == val_r ); }
152 /////////////////////////////////////////////////////////////////
154 ///////////////////////////////////////////////////////////////////
155 #endif // ZYPP_RESTRAITS_H