Libzypp/Design/Resolvable/Faq

Şuraya atla: kullan, ara

Questions?

  • How do I create some resolvable?

To create a e.g. Package, you first need to write some

class MyPackageImplementation : public PackageImplIf

which implements the package interface, or you use an existing one that fits your needs. Assuming you're in namespace zypp:

#include <.../MyPackageImplementation.h> // to be able to instanciate

...
// You already parsed name, edition and architecture

base::shared_ptr<MyPackageImplementation> pi;
Package::Ptr p( detail::makeResolvableAndImpl( name, edition, arch, pi );

That's it.

makeResolvable... functions are provided including zypp/detail/ResObjectImplIf.h. As this is the base class for all resolvable implementations, .../MyPackageImplementation.h somehow has to have it included.

= makeResolvableAndImpl

=

Note: pi is passed by reference, and modified! If you don't like this, we can provide a makeResolvable... which returns a

std::pair< Package::Ptr, base::shared_ptr<MyPackageImplementation> >

But then you'll have to call it as

detail::makeResolvableAndImpl<MyPackageImplementation>( n, e, a );

Either you state the type of implementation as template argument, or it can be deduced from one of the arguments you pass. In this case pi.

makeResolvableAndImpl creates a new MyPackageImplementation (type determined by pi; MyPackageImplementation must provide a default constructor). The new implementation object is stored and returned via pi.

A new interface object matching pi (Package in this case) is created; the new implementation is connected to it, and it is returned as Package::Ptr (in this case).

Now you can fill the remaining data into pi.

NOTE: pi is the only handle to the implementation object. It's not possible to somehow retrieve it later via the Package object. If the source needs it after the Package is built; it has to store it.

NOTE: It's the Package that holds a reference to the implementation object pi. pi won't be deleted as long as the Package is in memory. If the Package goes out of scope, the backlink is reset to NULL, and pi stays in memory, if the source still holds a reference to it.

= makeResolvableFromImpl

=

Same syntax, but slightly different behavior. pi is passed by value and used as implementation object. Thus not modified.

This way you could first (partially) setup pi and at some point pass it to create the Package.

NOTE: makeResolvableFromImpl throws an exception iff pi is NULL, or pi's backlink is not NULL (already used by some other Package).

back

Last edit in Trac '11/24/05 18:35:14' by 'kkaempf'


Last edit in Trac '11/24/05 18:35:14' by 'kkaempf'


Last edit in Trac '11/24/05 18:35:14' by 'kkaempf'


Last edit in Trac '11/24/05 18:35:14' by 'kkaempf'