- fixed some typos
[platform/upstream/libzypp.git] / zypp / PoolItem.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PoolItem.h
10  *
11 */
12 #ifndef ZYPP_POOLITEM_H
13 #define ZYPP_POOLITEM_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/ResObject.h"
20 #include "zypp/ResStatus.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   ///////////////////////////////////////////////////////////////////
27   //
28   //    CLASS NAME : PoolItem_Ref
29   //
30   /** Reference to a PoolItem conecting ResObject and ResStatus.
31    *
32    * The "real" PoolItem is usg. somewhere in the ResPool. This is
33    * a reference to it. All copies made will reference (and modify)
34    * the same PoolItem. All changes via a PoolItem_Ref are immediately
35    * visible in all copies (now COW).
36    *
37    * \note Constnes: Like pointer types, a <tt>const PoolItem_Ref</tt>
38    * does \b not refer to a <tt>const PoolItem</tt>. The reference is
39    * \c const, i.e. you can't change the refered PoolItem. The PoolItem
40    * (i.e. the status) is always mutable.
41    *
42   */
43   class PoolItem_Ref
44   {
45     friend std::ostream & operator<<( std::ostream & str, const PoolItem_Ref & obj );
46
47   public:
48     /** Implementation  */
49     class Impl;
50
51   public:
52     /** Default ctor for use in std::container. */
53     PoolItem_Ref();
54
55     /** Ctor */
56     explicit
57     PoolItem_Ref( ResObject::constPtr res_r );
58
59     /** Ctor */
60     PoolItem_Ref( ResObject::constPtr res_r, const ResStatus & status_r );
61
62     /** Dtor */
63     ~PoolItem_Ref();
64
65   public:
66     /** Returns the current status. */
67     ResStatus & status() const;
68
69     /** Reset status (applies autoprotection). */
70     ResStatus & statusReset() const;
71
72     /** Returns the ResObject::constPtr.
73      * \see \ref operator->
74     */
75     ResObject::constPtr resolvable() const;
76
77   public:
78     /** Implicit conversion into ResObject::constPtr to
79      *  support query filters operating on ResObject.
80     */
81     operator ResObject::constPtr() const
82     { return resolvable(); }
83
84     /** Forward \c -> access to ResObject. */
85     ResObject::constPtr operator->() const
86     { return resolvable(); }
87
88     /** Conversion to bool to allow pointer style tests
89      *  for nonNULL \ref resolvable. */
90     operator ResObject::constPtr::unspecified_bool_type() const
91     { return resolvable(); }
92
93   private:
94     /** Pointer to implementation */
95     RW_pointer<Impl> _pimpl;
96
97   private:
98     /** \name tmp hack for save/restore state. */
99     /** \todo get rid of it. */
100     //@{
101     friend class PoolItemSaver;
102     void saveState() const;
103     void restoreState() const;
104     bool sameState() const;
105     //@}
106   };
107   ///////////////////////////////////////////////////////////////////
108
109   typedef PoolItem_Ref PoolItem;
110
111   /** \relates PoolItem_Ref Stream output */
112   std::ostream & operator<<( std::ostream & str, const PoolItem_Ref & obj );
113
114   /** \relates PoolItem_Ref */
115   inline bool operator==( const PoolItem_Ref & lhs, const PoolItem_Ref & rhs )
116   { return lhs.resolvable() == rhs.resolvable(); }
117
118   /** \relates PoolItem_Ref */
119   inline bool operator==( const PoolItem_Ref & lhs, const ResObject::constPtr & rhs )
120   { return lhs.resolvable() == rhs; }
121
122   /** \relates PoolItem_Ref */
123   inline bool operator==( const ResObject::constPtr & lhs, const PoolItem_Ref & rhs )
124   { return lhs == rhs.resolvable(); }
125
126
127   /** \relates PoolItem_Ref */
128   inline bool operator!=( const PoolItem_Ref & lhs, const PoolItem_Ref & rhs )
129   { return ! (lhs==rhs); }
130
131   /** \relates PoolItem_Ref */
132   inline bool operator!=( const PoolItem_Ref & lhs, const ResObject::constPtr & rhs )
133   { return ! (lhs==rhs); }
134
135   /** \relates PoolItem_Ref */
136   inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem_Ref & rhs )
137   { return ! (lhs==rhs); }
138
139   /////////////////////////////////////////////////////////////////
140 } // namespace zypp
141 ///////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////
143 namespace std
144 { /////////////////////////////////////////////////////////////////
145
146   /** \relates zypp::PoolItem_Ref Order in std::container follows ResObject::constPtr.*/
147   template<>
148     inline bool less<zypp::PoolItem_Ref>::operator()( const zypp::PoolItem_Ref & lhs, const zypp::PoolItem_Ref & rhs ) const
149     { return lhs.resolvable() < rhs.resolvable(); }
150
151   /////////////////////////////////////////////////////////////////
152 } // namespace zypp
153 ///////////////////////////////////////////////////////////////////
154 #endif // ZYPP_POOLITEM_H