Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / devel / devel.ma / main.h
1 #ifndef main_h
2 #define main_h
3
4 #include <iosfwd>
5 #include <string>
6 #include "zypp/base/ReferenceCounted.h"
7 #include "zypp/base/NonCopyable.h"
8 #include <zypp/base/PtrTypes.h>
9
10 using std::string;
11
12 ///////////////////////////////////////////////////////////////////
13
14 class Resolvable : public zypp::base::ReferenceCounted, private zypp::base::NonCopyable
15 {
16   friend std::ostream & operator<<( std::ostream & str, const Resolvable & res );
17   public:
18     string kind() const;
19     string name() const;
20   public:
21     typedef Resolvable Self;
22     typedef zypp::base::intrusive_ptr<Self>       Ptr;
23     typedef zypp::base::intrusive_ptr<const Self> constPtr;
24   protected:
25     Resolvable( const string kind_r /*NVRA*/ );
26     virtual ~Resolvable();
27     virtual std::ostream & dumpOn( std::ostream & str ) const;
28   private:
29     struct Impl;
30     zypp::base::ImplPtr<Impl> _impl;
31 };
32
33 inline void intrusive_ptr_add_ref( const Resolvable * ptr_r )
34 { zypp::base::ReferenceCounted::add_ref( ptr_r ); }
35 inline void intrusive_ptr_release( const Resolvable * ptr_r )
36 { zypp::base::ReferenceCounted::release( ptr_r ); }
37
38 inline std::ostream & operator<<( std::ostream & str, const Resolvable & res )
39 { return res.dumpOn( str ); }
40
41 ///////////////////////////////////////////////////////////////////
42
43 // connect resolvables interface and implementation.
44 template<class _Res>
45   struct ResImplConnect : public _Res
46   {
47   public:
48     typedef ResImplConnect               Self;
49     typedef typename _Res::Impl          Impl;
50     typedef zypp::base::shared_ptr<Impl> ImplPtr;
51     typedef zypp::base::intrusive_ptr<Self>       Ptr;
52     typedef zypp::base::intrusive_ptr<const Self> constPtr;
53   public:
54     ResImplConnect( /*NVRA*/ ImplPtr impl_r )
55     : _impl( impl_r ? impl_r : ImplPtr(new Impl /*NVRA*/) )
56     { _impl->_backRef = this; }
57     virtual ~ResImplConnect() {}
58   private:
59     ImplPtr _impl;
60     virtual Impl &       impl()       { return *_impl; }
61     virtual const Impl & impl() const { return *_impl; }
62   };
63
64
65 template<class _Impl>
66   typename _Impl::ResType::Ptr
67   makeResolvable( /*NVRA*/ zypp::base::shared_ptr<_Impl> & impl_r )
68   {
69     impl_r.reset( new _Impl );
70     return new ResImplConnect<typename _Impl::ResType>( /*NVRA*/ impl_r );
71   }
72
73 ///////////////////////////////////////////////////////////////////
74 #include <list>
75 using std::list;
76
77 struct ObjectImpl
78 {
79   const Resolvable * self() const { return _backRef; }
80   Resolvable *       self()       { return _backRef; }
81
82   virtual string       summary()         const { return string(); }
83   virtual list<string> description()     const { return list<string>(); }
84   //virtual FSize        size()            const { return 0; }
85   //virtual bool         providesSources() const { return false; }
86
87   ObjectImpl()
88   : _backRef( 0 )
89   {}
90   virtual ~ObjectImpl() {};
91
92   private:
93     template<class _Res>
94       friend class ResImpl;
95     Resolvable * _backRef;
96 };
97
98 class Object : public Resolvable
99 {
100   public:
101     string       summary()         const;
102     list<string> description()     const;
103     //FSize        size()            const;
104     //bool         providesSources() const;
105   public:
106     typedef Object     Self;
107     typedef ObjectImpl Impl;
108     typedef zypp::base::intrusive_ptr<Self>       Ptr;
109     typedef zypp::base::intrusive_ptr<const Self> constPtr;
110   protected:
111     Object( const string kind_r /*NVRA*/ );
112     virtual ~Object();
113   private:
114     virtual Impl &       impl()       = 0;
115     virtual const Impl & impl() const = 0;
116 };
117
118 ///////////////////////////////////////////////////////////////////
119 class Package;
120 struct PackageImpl : public ObjectImpl
121 {
122   typedef Package ResType;
123   virtual string packagedata() const { return string(); }
124 };
125
126 class Package : public Object
127 {
128   public:
129     string packagedata() const;
130   public:
131     typedef Package     Self;
132     typedef PackageImpl Impl;
133     typedef zypp::base::intrusive_ptr<Self>       Ptr;
134     typedef zypp::base::intrusive_ptr<const Self> constPtr;
135   protected:
136     Package( /*NVRA*/ );
137     virtual ~Package();
138   private:
139     virtual Impl &       impl()       = 0;
140     virtual const Impl & impl() const = 0;
141 };
142
143 ///////////////////////////////////////////////////////////////////
144
145 class Selection;
146 struct SelectionImpl : public ObjectImpl
147 {
148   typedef Selection ResType;
149   virtual string selectiondata() const { return string(); }
150 };
151
152 class Selection : public Object
153 {
154   public:
155     string selectiondata() const;
156   public:
157     typedef Selection     Self;
158     typedef SelectionImpl Impl;
159     typedef zypp::base::intrusive_ptr<Self>       Ptr;
160     typedef zypp::base::intrusive_ptr<const Self> constPtr;
161   protected:
162     Selection( /*NVRA*/ );
163     virtual ~Selection();
164   private:
165     virtual Impl &       impl()       = 0;
166     virtual const Impl & impl() const = 0;
167 };
168
169 ///////////////////////////////////////////////////////////////////
170 #endif // main_h