Deprecate MediaAccess::downloads (accidentally deleted)
[platform/upstream/libzypp.git] / zypp / InstanceId.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/InstanceId.h
10  *
11 */
12 #ifndef ZYPP_INSTANCEID_H
13 #define ZYPP_INSTANCEID_H
14
15 #include <string>
16
17 #include "zypp/PoolItem.h"
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   ///////////////////////////////////////////////////////////////////
24   //
25   //    CLASS NAME : InstanceId
26   //
27   /**
28    * Build string to identify/retrieve a specific \a Solvable.
29    *
30    * <tt>"[<namespace>:]<name>-<version>-<release>.<arch>@<repoalias>"</tt>
31    *
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().
35    *
36    * \code
37    *   InstanceId instanceId( "SUSE:" ); // using a namespace
38    *
39    *   ResPool pool( ResPool::instance() );
40    *   for_( it, pool.begin(), pool.end() )
41    *   {
42    *     std::cout << instanceId(*it) << endl;
43    *   }
44    * \endcode
45    */
46   class InstanceId
47   {
48     public:
49       /** Default ctor empty empty namespace */
50       InstanceId()
51       {}
52
53       /** Ctor taking namespace */
54       InstanceId( const std::string & namespace_r )
55       : _namespace( namespace_r )
56       {}
57
58     public:
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() ); }
64
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;
70
71     public:
72       /** \ref Solvable to \ref InstanceId string. */
73       std::string operator()( sat::Solvable slv_r ) const
74       { return getIdFor( slv_r ); }
75
76       /** \ref PoolItem to \ref InstanceId string. */
77       std::string operator()( const PoolItem & pi_r ) const
78       { return getIdFor( pi_r ); }
79
80       /** \ref InstanceId string to \ref PoolItem. */
81       PoolItem operator()( const std::string str_r ) const
82       { return findPoolItem( str_r ); }
83
84       /** Quick test whether the InstanceId string would refer
85        * to a system (installed) Solvable. */
86       bool isSystemId( const std::string str_r ) const;
87
88     public:
89       /** The namespace in use. */
90       const std::string & getNamespace() const
91       { return _namespace; }
92
93       /** Set a new namespace. */
94       void setNamespace( const std::string & namespace_r )
95       { _namespace = namespace_r; }
96
97       /** Set no (empty) namespace. */
98       void unsetNamespace()
99       { _namespace.clear(); }
100
101    private:
102       std::string _namespace;
103   };
104   /////////////////////////////////////////////////////////////////
105
106   /////////////////////////////////////////////////////////////////
107 } // namespace zypp
108 ///////////////////////////////////////////////////////////////////
109 #endif // ZYPP_INSTANCEID_H