1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/InstanceId.h
12 #ifndef ZYPP_INSTANCEID_H
13 #define ZYPP_INSTANCEID_H
17 #include "zypp/PoolItem.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
25 // CLASS NAME : InstanceId
28 * Build string to identify/retrieve a specific \a Solvable.
30 * <tt>"[<namespace>:]<name>-<version>-<release>.<arch>@<repoalias>"</tt>
32 * Any namespace that prepends the InstanceIds must be
33 * passed to the ctor. Conversion to/from instanceId can
34 * be done via function call \c operator().
37 * InstanceId instanceId( "SUSE:" ); // using a namespace
39 * ResPool pool( ResPool::instance() );
40 * for_( it, pool.begin(), pool.end() )
42 * std::cout << instanceId(*it) << endl;
49 /** Default ctor empty empty namespace */
53 /** Ctor taking namespace */
54 InstanceId( const std::string & namespace_r )
55 : _namespace( namespace_r )
59 /** \ref Solvable to \ref InstanceId string. */
60 std::string getIdFor( sat::Solvable slv_r ) const;
61 /** \ref PoolItem to \ref InstanceId string. */
62 std::string getIdFor( const PoolItem & pi_r ) const
63 { return getIdFor( pi_r.satSolvable() ); }
65 /** \ref InstanceId string to \ref Solvable. */
66 sat::Solvable findSolvable( const std::string str_r ) const
67 { return findPoolItem( str_r ).satSolvable(); }
68 /** \ref InstanceId string to \ref PoolItem. */
69 PoolItem findPoolItem( const std::string str_r ) const;
72 /** \ref Solvable to \ref InstanceId string. */
73 std::string operator()( sat::Solvable slv_r ) const
74 { return getIdFor( slv_r ); }
76 /** \ref PoolItem to \ref InstanceId string. */
77 std::string operator()( const PoolItem & pi_r ) const
78 { return getIdFor( pi_r ); }
80 /** \ref InstanceId string to \ref PoolItem. */
81 PoolItem operator()( const std::string str_r ) const
82 { return findPoolItem( str_r ); }
84 /** Quick test whether the InstanceId string would refer
85 * to a system (installed) Solvable. */
86 bool isSystemId( const std::string str_r ) const;
89 /** The namespace in use. */
90 const std::string & getNamespace() const
91 { return _namespace; }
93 /** Set a new namespace. */
94 void setNamespace( const std::string & namespace_r )
95 { _namespace = namespace_r; }
97 /** Set no (empty) namespace. */
99 { _namespace.clear(); }
102 std::string _namespace;
104 /////////////////////////////////////////////////////////////////
106 /////////////////////////////////////////////////////////////////
108 ///////////////////////////////////////////////////////////////////
109 #endif // ZYPP_INSTANCEID_H