- Adapt to virtual ostream operator<< provided by ReferenceCounted.
[platform/upstream/libzypp.git] / zypp / Resolvable.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
10  *
11 */
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/NonCopyable.h"
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/ResTraits.h"
22
23 #include "zypp/Edition.h"
24 #include "zypp/Arch.h"
25 #include "zypp/Dependencies.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31   ///////////////////////////////////////////////////////////////////
32   //
33   //    CLASS NAME : Resolvable
34   //
35   /** Interface base for resolvable objects (identification and dependencies).
36   */
37   class Resolvable : public base::ReferenceCounted, private base::NonCopyable
38   {
39   public:
40     typedef Resolvable               Self;
41     typedef ResTraits<Self>          TraitsType;
42     typedef TraitsType::KindType     Kind;
43     typedef TraitsType::PtrType      Ptr;
44     typedef TraitsType::constPtrType constPtr;
45
46   public:
47     /**  */
48     const Kind & kind() const;
49     /**  */
50     const std::string & name() const;
51     /**  */
52     const Edition & edition() const;
53     /**  */
54     const Arch & arch() const;
55     /**  */
56     const Dependencies & deps() const;
57     /** */
58     void setDeps( const Dependencies & val_r );
59
60   protected:
61     /** Ctor */
62     Resolvable( const Kind & kind_r,
63                 const std::string & name_r,
64                 const Edition & edition_r,
65                 const Arch & arch_r );
66     /** Dtor */
67     virtual ~Resolvable();
68     /** Helper for stream output */
69     virtual std::ostream & dumpOn( std::ostream & str ) const;
70
71   private:
72     /** Implementation */
73     struct Impl;
74     /** Pointer to implementation */
75     RW_pointer<Impl> _pimpl;
76   };
77   ///////////////////////////////////////////////////////////////////
78
79   /** Test whether a Resolvable::Ptr is of a certain Kind.
80    * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
81    * of the specified Kind.
82    * \relates Resolvable
83    * \code
84    * isKind<Package>(resPtr);
85    * \endcode
86   */
87   template<class _Res>
88     inline bool isKind( const Resolvable::constPtr & p )
89     { return p && p->kind() == ResTraits<_Res>::kind; }
90
91   // Specialization for Resolvable: Always true.
92   template<>
93     inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
94     { return p; }
95
96   // Specialization for ResObject: Always true.
97   template<>
98     inline bool isKind<ResObject>( const Resolvable::constPtr & p )
99     { return p; }
100
101
102   /** Convert Resolvable::Ptr into Ptr of a certain Kind.
103    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
104    * not of the specified Kind.
105    * \relates Resolvable
106    * \code
107    * asKind<Package>(resPtr);
108    * \endcode
109   */
110   template<class _Res>
111     inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
112     { return dynamic_pointer_cast<_Res>(p); }
113
114   template<class _Res>
115     inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
116     { return dynamic_pointer_cast<const _Res>(p); }
117
118   /////////////////////////////////////////////////////////////////
119 } // namespace zypp
120 ///////////////////////////////////////////////////////////////////
121 #endif // ZYPP_RESOLVABLE_H