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