On Friday 27 July 2012 13:36:04 Saurabh Sood wrote:
> Hi,
> I had some queries regarding some libzypp functions.
>
> 1.) I want to retrieve information regarding packages such as size,
> version of the package. How can I get this information?Common attributes are available via class ResObject[Resolvable].
To acces if from a PoolItem you can use:
ResObject::constPtr PooolItem::resolvable() const;
or ResObject::constPtr operator->() const;
Example:
PooolItem pi;
pi.resolvable()->size();
or pi->size();
(or from a sat::Solvable:
sat::Solvable s;
PooolItem pi( s );
...)
Attributes specific to packages/patch/pattern/product are available via the
coresponding classes Package[ResObject[Resolvable]]. To test whether a
ResObject actually refers to a e.g. Package use 'isKind':
ResObject::constPtr obj;
if ( isKind<Package>( obj ) )
or if ( obj->isKind<Package>() )
or if ( obj->isKind( ResKind::package ) )
PooolItem pi;
if ( pi->isKind<Package>() )
or if ( pi->isKind( ResKind::package )
To convert use 'asKind':
ResObject::constPtr obj;
Package::constPtr pkg( asKind<Package>( obj ) );
or Package::constPtr pkg( obj->asKind<Package>() );
PooolItem pi;
Package::constPtr pkg( asKind<Package>( pi.resolvable() ) );
or Package::constPtr pkg( pi->asKind<Package>() );
'asKind' performs a dynamic cast, so it returns a nullptr if the object is not
of the right type. 'isKind' simply tests whether 'asKinf' returned a nullptr.
In doubt use asKind and test for a nullptr.
ResObject::constPtr obj;
Package::constPtr pkg( asKind<Package>( obj ) ); // one cast
if ( pkg )
{
...
ResObject::constPtr obj;
if ( isKind<Package>( obj ) ) // 1st cast
{
Package::constPtr pkg( asKind<Package>( obj ) ); // 2nd cast
...> 2.) I am using defaultLoadSystem( "/" ) for a particular function. I
> am getting the error 'zypp instance already created'. I havent called
> getZypp() anywhere before this line. I just loaded some repositories
> into the pool using RepoManager, and that was in some other module.There are a actions which may call getZypp() internally. You should call
defaultLoadSystem before doing anything else, or do the setup manually.