~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/SysContent.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*---------------------------------------------------------------------\
 
2
|                          ____ _   __ __ ___                          |
 
3
|                         |__  / \ / / . \ . \                         |
 
4
|                           / / \ V /|  _/  _/                         |
 
5
|                          / /__ | | | | | |                           |
 
6
|                         /_____||_| |_| |_|                           |
 
7
|                                                                      |
 
8
\---------------------------------------------------------------------*/
 
9
/** \file       zypp/SysContent.h
 
10
 *
 
11
*/
 
12
#ifndef ZYPP_SYSCONTENT_H
 
13
#define ZYPP_SYSCONTENT_H
 
14
 
 
15
#include <iosfwd>
 
16
#include <string>
 
17
#include <set>
 
18
 
 
19
#include "zypp/base/PtrTypes.h"
 
20
 
 
21
#include "zypp/PoolItem.h"
 
22
#include "zypp/Edition.h"
 
23
#include "zypp/Date.h"
 
24
 
 
25
///////////////////////////////////////////////////////////////////
 
26
namespace zypp
 
27
{ /////////////////////////////////////////////////////////////////
 
28
  ///////////////////////////////////////////////////////////////////
 
29
  namespace syscontent
 
30
  { /////////////////////////////////////////////////////////////////
 
31
 
 
32
    ///////////////////////////////////////////////////////////////////
 
33
    //
 
34
    //  CLASS NAME : Writer
 
35
    //
 
36
    /** Collect and serialize a set of \ref ResObject.
 
37
     * \code
 
38
     * <?xml version="1.0" encoding="UTF-8"?>
 
39
     * <syscontent>
 
40
     *   <ident>
 
41
     *     <name>mycollection</name>
 
42
     *     <version epoch="0" ver="1.0" rel="1"/>
 
43
     *     <description>All the cool stuff...</description>
 
44
     *     <created>1165270942</created>
 
45
     *   </ident>
 
46
     *   <onsys>
 
47
     *     <entry kind="package" name="pax" epoch="0" ver="3.4" rel="12" arch="x86_64"/>
 
48
     *     <entry kind="product" name="SUSE_SLES" epoch="0" ver="10" arch="x86_64"/>
 
49
     *     <entry ...
 
50
     *   </onsys>
 
51
     * </syscontent>
 
52
     * \endcode
 
53
     * \see Reader
 
54
    */
 
55
    class Writer
 
56
    {
 
57
      typedef std::set<ResObject::constPtr> StorageT;
 
58
    public:
 
59
      typedef StorageT::value_type     value_type;
 
60
      typedef StorageT::size_type      size_type;
 
61
      typedef StorageT::iterator       iterator;
 
62
      typedef StorageT::const_iterator const_iterator;
 
63
 
 
64
    public:
 
65
      /** Default Ctor. */
 
66
      Writer();
 
67
 
 
68
    public:
 
69
      /** \name Identification.
 
70
       * User provided optional data to identify the collection.
 
71
      */
 
72
      //@{
 
73
      /** Get name. */
 
74
      const std::string & name() const;
 
75
 
 
76
      /** Set name. */
 
77
      Writer & name( const std::string & val_r );
 
78
 
 
79
      /** Get edition. */
 
80
      const Edition & edition() const;
 
81
 
 
82
      /** Set edition. */
 
83
      Writer & edition( const Edition & val_r );
 
84
 
 
85
      /** Get description. */
 
86
      const std::string & description() const;
 
87
 
 
88
      /** Set description.*/
 
89
      Writer & description( const std::string & val_r );
 
90
      //@}
 
91
 
 
92
    public:
 
93
      /** \name Collecting data.
 
94
       * \code
 
95
       * syscontent::Writer contentW;
 
96
       * contentW.name( "mycollection" )
 
97
       *         .edition( Edition( "1.0" ) )
 
98
       *         .description( "All the cool stuff..." );
 
99
       *
 
100
       * ResPool pool( getZYpp()->pool() );
 
101
       * for_each( pool.begin(), pool.end(),
 
102
       *           bind( &syscontent::Writer::addIf, ref(contentW), _1 ) );
 
103
       *
 
104
       * std::ofstream my_file( "some_file" );
 
105
       * my_file << contentW;
 
106
       * my_file.close();
 
107
       * \endcode
 
108
      */
 
109
      //@{
 
110
      /** Collect currently installed \ref PoolItem. */
 
111
      void addInstalled( const PoolItem & obj_r );
 
112
 
 
113
      /** Collect \ref PoolItem if it stays on the system.
 
114
       * I.e. it stays installed or is tagged to be installed.
 
115
       * Solver selected items are omitted.
 
116
      */
 
117
      void addIf( const PoolItem & obj_r );
 
118
 
 
119
      /** Unconditionally add this \ref ResObject (or \ref PoolItem). */
 
120
      void add( const ResObject::constPtr & obj_r );
 
121
      //@}
 
122
 
 
123
    public:
 
124
      /** \name Collected data. */
 
125
      //@{
 
126
      /** Whether no data collected so far. */
 
127
      bool empty() const;
 
128
 
 
129
      /** Number of items collected. */
 
130
      size_type size() const;
 
131
 
 
132
      /** Iterator to the begin of collected data. */
 
133
      const_iterator begin() const;
 
134
 
 
135
      /** Iterator to the end of collected data. */
 
136
      const_iterator end() const;
 
137
      //@}
 
138
 
 
139
    public:
 
140
      /** Write collected data as XML.
 
141
       * Read them back using \ref Reader.
 
142
      */
 
143
      std::ostream & writeXml( std::ostream & str ) const;
 
144
 
 
145
    private:
 
146
      class Impl;
 
147
      RWCOW_pointer<Impl> _pimpl;
 
148
    };
 
149
    ///////////////////////////////////////////////////////////////////
 
150
 
 
151
    /** \relates Writer Stream output */
 
152
    inline std::ostream & operator<<( std::ostream & str, const Writer & obj )
 
153
    { return obj.writeXml( str ); }
 
154
 
 
155
    ///////////////////////////////////////////////////////////////////
 
156
    //
 
157
    //  CLASS NAME : Reader
 
158
    //
 
159
    /** Retrieve \ref ResObject data serialized by \ref Writer.
 
160
     * \see Writer
 
161
    */
 
162
    class Reader
 
163
    {
 
164
    public:
 
165
      /** Restored \ref ResObject data. */
 
166
      class Entry;
 
167
 
 
168
    private:
 
169
      typedef std::list<Entry> StorageT;
 
170
 
 
171
    public:
 
172
      typedef StorageT::value_type     value_type;
 
173
      typedef StorageT::size_type      size_type;
 
174
      typedef StorageT::iterator       iterator;
 
175
      typedef StorageT::const_iterator const_iterator;
 
176
 
 
177
    public:
 
178
      /** Default Ctor. */
 
179
      Reader();
 
180
 
 
181
      /** Ctor parsing data from \a input_r.
 
182
       * \throws Exception on read or parse error.
 
183
      */
 
184
      Reader( std::istream & input_r );
 
185
 
 
186
    public:
 
187
      /** \name Identification.
 
188
       * User provided optional data to identify the collection.
 
189
      */
 
190
      //@{
 
191
      /** Get name. */
 
192
      const std::string & name() const;
 
193
 
 
194
      /** Get edition. */
 
195
      const Edition & edition() const;
 
196
 
 
197
      /** Get description. */
 
198
      const std::string & description() const;
 
199
 
 
200
      /** Get creation date. */
 
201
      const Date & ctime() const;
 
202
 
 
203
    public:
 
204
      /** \name Collected data. */
 
205
      //@{
 
206
      /** Whether no data collected so far. */
 
207
      bool empty() const;
 
208
 
 
209
      /** Number of items collected. */
 
210
      size_type size() const;
 
211
 
 
212
      /** Iterator to the begin of collected data. */
 
213
      const_iterator begin() const;
 
214
 
 
215
      /** Iterator to the end of collected data. */
 
216
      const_iterator end() const;
 
217
      //@}
 
218
 
 
219
    private:
 
220
      class Impl;
 
221
      RWCOW_pointer<Impl> _pimpl;
 
222
    };
 
223
 
 
224
    /** \relates Reader Stream output */
 
225
    std::ostream & operator<<( std::ostream & str, const Reader & obj );
 
226
 
 
227
    ///////////////////////////////////////////////////////////////////
 
228
 
 
229
    ///////////////////////////////////////////////////////////////////
 
230
    //
 
231
    //  CLASS NAME : Reader::Entry
 
232
    //
 
233
    /** Restored \ref ResObject data. */
 
234
    class Reader::Entry
 
235
    {
 
236
    public:
 
237
      Entry();
 
238
      const std::string & kind() const;
 
239
      const std::string & name() const;
 
240
      const Edition & edition() const;
 
241
      const Arch & arch() const;
 
242
    public:
 
243
      class Impl;
 
244
      Entry( const shared_ptr<Impl> & pimpl_r );
 
245
    private:
 
246
      RW_pointer<Impl> _pimpl;
 
247
    };
 
248
    ///////////////////////////////////////////////////////////////////
 
249
 
 
250
    /////////////////////////////////////////////////////////////////
 
251
  } // namespace syscontent
 
252
  ///////////////////////////////////////////////////////////////////
 
253
  /////////////////////////////////////////////////////////////////
 
254
} // namespace zypp
 
255
///////////////////////////////////////////////////////////////////
 
256
#endif // ZYPP_SYSCONTENT_H