~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/HistoryLogData.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
 
 
10
/** \file zypp/HistoryLogData.h
 
11
 *
 
12
 */
 
13
#ifndef ZYPP_HISTORYLOGDATA_H_
 
14
#define ZYPP_HISTORYLOGDATA_H_
 
15
 
 
16
#include <iosfwd>
 
17
 
 
18
#include "zypp/APIConfig.h"
 
19
#include "zypp/Date.h"
 
20
#include "zypp/Edition.h"
 
21
#include "zypp/Arch.h"
 
22
#include "zypp/CheckSum.h"
 
23
#include "zypp/Url.h"
 
24
 
 
25
#define HISTORY_LOG_DATE_FORMAT "%Y-%m-%d %H:%M:%S"
 
26
 
 
27
///////////////////////////////////////////////////////////////////
 
28
namespace zypp
 
29
{
 
30
  ///////////////////////////////////////////////////////////////////
 
31
  /// \class HistoryActionID
 
32
  /// \brief Enumeration of known history actions.
 
33
  /// \ingroup g_EnumerationClass
 
34
  /// \ingroup g_ZyppHistory
 
35
  ///////////////////////////////////////////////////////////////////
 
36
  struct HistoryActionID
 
37
  {
 
38
    static const HistoryActionID NONE;
 
39
 
 
40
    static const HistoryActionID INSTALL;
 
41
    static const HistoryActionID REMOVE;
 
42
    static const HistoryActionID REPO_ADD;
 
43
    static const HistoryActionID REPO_REMOVE;
 
44
    static const HistoryActionID REPO_CHANGE_ALIAS;
 
45
    static const HistoryActionID REPO_CHANGE_URL;
 
46
 
 
47
    enum ID
 
48
    {
 
49
      NONE_e,
 
50
 
 
51
      INSTALL_e,
 
52
      REMOVE_e,
 
53
      REPO_ADD_e,
 
54
      REPO_REMOVE_e,
 
55
      REPO_CHANGE_ALIAS_e,
 
56
      REPO_CHANGE_URL_e
 
57
    };
 
58
 
 
59
    HistoryActionID() : _id(NONE_e) {}
 
60
 
 
61
    HistoryActionID(ID id) : _id(id) {}
 
62
 
 
63
    explicit HistoryActionID(const std::string & strval_r);
 
64
 
 
65
    ID toEnum() const { return _id; }
 
66
 
 
67
    static HistoryActionID::ID parse(const std::string & strval_r);
 
68
 
 
69
    const std::string & asString(bool pad = false) const;
 
70
 
 
71
    private:
 
72
    ID _id;
 
73
  };
 
74
 
 
75
  /** \relates HistoryActionID */
 
76
  inline bool operator==( const HistoryActionID & lhs, const HistoryActionID & rhs )
 
77
  { return lhs.toEnum() == rhs.toEnum(); }
 
78
 
 
79
  /** \relates HistoryActionID */
 
80
  inline bool operator!=( const HistoryActionID & lhs, const HistoryActionID & rhs )
 
81
  { return lhs.toEnum() != rhs.toEnum(); }
 
82
 
 
83
  /** \relates HistoryActionID */
 
84
  std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
 
85
  ///////////////////////////////////////////////////////////////////
 
86
 
 
87
  ///////////////////////////////////////////////////////////////////
 
88
  /// \class HistoryLogData
 
89
  /// \brief A zypp history log line split into fields
 
90
  /// \ingroup g_ZyppHistory
 
91
  ///
 
92
  /// Each valid history log line starts with a date and HistoryActionID
 
93
  /// field. Subsequent fields depend on the kind of action. See derived
 
94
  /// classes for convenient access to those flields.
 
95
  ///
 
96
  /// HistoryLogData itself provides mostly generic access to the fields
 
97
  /// plain string values. Derived classes for well known entries tell
 
98
  ///
 
99
  ///////////////////////////////////////////////////////////////////
 
100
  class HistoryLogData
 
101
  {
 
102
  public:
 
103
    typedef shared_ptr<HistoryLogData>          Ptr;
 
104
    typedef shared_ptr<const HistoryLogData>    constPtr;
 
105
 
 
106
    typedef std::vector<std::string>    FieldVector;
 
107
    typedef FieldVector::size_type      size_type;
 
108
    typedef FieldVector::const_iterator const_iterator;
 
109
 
 
110
  public:
 
111
    /** Ctor \b moving \a FieldVector (via swap).
 
112
     * \throws ParseException if \a fields_r has not at least \a expect_r entries
 
113
     * \note 2 fields (date and action) are always required.
 
114
     */
 
115
    explicit HistoryLogData( FieldVector & fields_r, size_type expect_r = 2 );
 
116
 
 
117
    /** Ctor \b moving \a FieldVector (via swap).
 
118
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or not at least \a expect_r entries.
 
119
     * \note 2 fields (date and action) are always required.
 
120
     */
 
121
    HistoryLogData( FieldVector & fields_r, HistoryActionID action_r, size_type expect_r = 2 );
 
122
 
 
123
    /** Dtor */
 
124
    virtual ~HistoryLogData();
 
125
 
 
126
    /** Factory method creating HistoryLogData classes.
 
127
     *
 
128
     * Moves \a fields_r into a HistoryLogData or derived object, depending on the
 
129
     * HistoryActionID. For known action ids a coresponing HistoryLogData class
 
130
     * is created, to allow convenient access to the field values. For unknown
 
131
     * action ids a plain HistoryLogData object is created. \ref HistoryActionID
 
132
     * \ref NONE_e id used in this case.
 
133
     *
 
134
     * \throws ParseException if \a fields_r does not contain the required format.
 
135
     */
 
136
    static Ptr create( FieldVector & fields_r );
 
137
 
 
138
  public:
 
139
    /** Whether FieldVector is empty. */
 
140
    bool empty() const;
 
141
 
 
142
    /** Number of fields in vector. */
 
143
    size_type size() const;
 
144
 
 
145
    /** Iterator pointing to 1st element in vector (or end()). */
 
146
    const_iterator begin() const;
 
147
 
 
148
    /** Iterator pointing behind the last element in vector. */
 
149
    const_iterator end() const;
 
150
 
 
151
    /** Access (optional) field by number.
 
152
     * \returns an empty string if \a idx_r is out of range.
 
153
     * \see \ref at
 
154
     */
 
155
    const std::string & optionalAt( size_type idx_r ) const;
 
156
    /** \overload */
 
157
    const std::string & operator[]( size_type idx_r ) const
 
158
    { return optionalAt( idx_r ); }
 
159
 
 
160
    /** Access (required) field by number.
 
161
     * \throws std::out_of_range if \a idx_r is out of range.
 
162
     * \see \ref optionalAt
 
163
     */
 
164
    const std::string & at( size_type idx_r ) const;
 
165
 
 
166
  public:
 
167
    enum Index                  ///< indices of known fields
 
168
    {
 
169
      DATE_INDEX        = 0,    ///< date
 
170
      ACTION_INDEX      = 1,    ///< HistoryActionID
 
171
    };
 
172
 
 
173
  public:
 
174
    Date        date()          const;  ///< date
 
175
    HistoryActionID action()    const;  ///< HistoryActionID (or \c NONE_e if unknown)
 
176
 
 
177
  public:
 
178
    class Impl;                 ///< Implementation class
 
179
  private:
 
180
    RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation
 
181
  protected:
 
182
    HistoryLogData & operator=( const HistoryLogData & ); ///< no base class assign
 
183
  };
 
184
 
 
185
  /** \relates HistoryLogData Stream output */
 
186
  std::ostream & operator<<( std::ostream & str, const HistoryLogData & obj );
 
187
  ///////////////////////////////////////////////////////////////////
 
188
 
 
189
  ///////////////////////////////////////////////////////////////////
 
190
  /// \class HistoryLogDataInstall
 
191
  /// \brief  A zypp history log line for an installed packaged.
 
192
  /// \ingroup g_ZyppHistory
 
193
  ///////////////////////////////////////////////////////////////////
 
194
  class HistoryLogDataInstall : public HistoryLogData
 
195
  {
 
196
  public:
 
197
    typedef shared_ptr<HistoryLogDataInstall>           Ptr;
 
198
    typedef shared_ptr<const HistoryLogDataInstall>     constPtr;
 
199
    /** Ctor \b moving \a FieldVector (via swap).
 
200
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
201
     */
 
202
    HistoryLogDataInstall( FieldVector & fields_r );
 
203
 
 
204
  public:
 
205
    enum Index                  ///< indices of known fields
 
206
    {
 
207
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
208
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
209
      NAME_INDEX,               ///< package name
 
210
      EDITION_INDEX,            ///< package edition
 
211
      ARCH_INDEX,               ///< package architecture
 
212
      REQBY_INDEX,              ///< requested by (user@hostname, pid:appname, or empty (solver))
 
213
      REPOALIAS_INDEX,          ///< repository providing the package
 
214
      CHEKSUM_INDEX,            ///< package checksum
 
215
      USERDATA_INDEX,           ///< userdata/transactionID
 
216
    };
 
217
 
 
218
   public:
 
219
    std::string name()          const;  ///< package name
 
220
    Edition     edition()       const;  ///< package edition
 
221
    Arch        arch()          const;  ///< package architecture
 
222
    std::string reqby()         const;  ///< requested by (user@hostname, pid:appname, or empty (solver))
 
223
    std::string repoAlias()     const;  ///< repository providing the package
 
224
    CheckSum    checksum()      const;  ///< package checksum
 
225
    std::string userdata()      const;  ///< userdata/transactionID
 
226
  };
 
227
 
 
228
  ///////////////////////////////////////////////////////////////////
 
229
  /// \class HistoryLogDataRemove
 
230
  /// \brief A zypp history log line for a removed packge.
 
231
  /// \ingroup g_ZyppHistory
 
232
  ///////////////////////////////////////////////////////////////////
 
233
  class HistoryLogDataRemove : public HistoryLogData
 
234
  {
 
235
  public:
 
236
    typedef shared_ptr<HistoryLogDataRemove>            Ptr;
 
237
    typedef shared_ptr<const HistoryLogDataRemove>      constPtr;
 
238
    /** Ctor \b moving \a FieldVector (via swap).
 
239
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
240
     */
 
241
    HistoryLogDataRemove( FieldVector & fields_r );
 
242
 
 
243
  public:
 
244
    enum Index                  ///< indices of known fields
 
245
    {
 
246
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
247
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
248
      NAME_INDEX,               ///< package name
 
249
      EDITION_INDEX,            ///< package edition
 
250
      ARCH_INDEX,               ///< package architecture
 
251
      REQBY_INDEX,              ///< requested by (user@hostname, pid:appname, or empty (solver))
 
252
      USERDATA_INDEX,           ///< userdata/transactionID
 
253
    };
 
254
 
 
255
  public:
 
256
    std::string name()          const;  ///< package name
 
257
    Edition     edition()       const;  ///< package edition
 
258
    Arch        arch()          const;  ///< package architecture
 
259
    std::string reqby()         const;  ///< requested by (user@hostname, pid:appname, or empty (solver))
 
260
    std::string userdata()      const;  ///< userdata/transactionID
 
261
  };
 
262
 
 
263
  ///////////////////////////////////////////////////////////////////
 
264
  /// \class HistoryLogDataRepoAdd
 
265
  /// \brief A zypp history log line for an added repository.
 
266
  /// \ingroup g_ZyppHistory
 
267
  ///////////////////////////////////////////////////////////////////
 
268
  class HistoryLogDataRepoAdd : public HistoryLogData
 
269
  {
 
270
  public:
 
271
    typedef shared_ptr<HistoryLogDataRepoAdd>           Ptr;
 
272
    typedef shared_ptr<const HistoryLogDataRepoAdd>     constPtr;
 
273
    /** Ctor \b moving \a FieldVector (via swap).
 
274
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
275
     */
 
276
    HistoryLogDataRepoAdd( FieldVector & fields_r );
 
277
 
 
278
  public:
 
279
    enum Index                  ///< indices of known fields
 
280
    {
 
281
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
282
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
283
      ALIAS_INDEX,              ///< repository alias
 
284
      URL_INDEX,                ///< repository url
 
285
      USERDATA_INDEX,           ///< userdata/transactionID
 
286
    };
 
287
 
 
288
  public:
 
289
    std::string alias()         const;  ///< repository alias
 
290
    Url         url()           const;  ///< repository url
 
291
    std::string userdata()      const;  ///< userdata/transactionID
 
292
  };
 
293
 
 
294
  ///////////////////////////////////////////////////////////////////
 
295
  /// \class HistoryLogDataRepoRemove
 
296
  /// \brief A zypp history log line for a removed repository.
 
297
  /// \ingroup g_ZyppHistory
 
298
  ///////////////////////////////////////////////////////////////////
 
299
  class HistoryLogDataRepoRemove : public HistoryLogData
 
300
  {
 
301
  public:
 
302
    typedef shared_ptr<HistoryLogDataRepoRemove>        Ptr;
 
303
    typedef shared_ptr<const HistoryLogDataRepoRemove>  constPtr;
 
304
    /** Ctor \b moving \a FieldVector (via swap).
 
305
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
306
     */
 
307
    HistoryLogDataRepoRemove( FieldVector & fields_r );
 
308
 
 
309
  public:
 
310
    enum Index                  ///< indices of known fields
 
311
    {
 
312
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
313
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
314
      ALIAS_INDEX,              ///< repository alias
 
315
      USERDATA_INDEX,           ///< userdata/transactionID
 
316
    };
 
317
 
 
318
  public:
 
319
    std::string alias()         const;  ///< repository alias
 
320
    std::string userdata()      const;  ///< userdata/transactionID
 
321
  };
 
322
 
 
323
  ///////////////////////////////////////////////////////////////////
 
324
  /// \class HistoryLogDataRepoAliasChange
 
325
  /// \brief A zypp history log line for a repo alias change.
 
326
  /// \ingroup g_ZyppHistory
 
327
  ///////////////////////////////////////////////////////////////////
 
328
  class HistoryLogDataRepoAliasChange : public HistoryLogData
 
329
  {
 
330
  public:
 
331
    typedef shared_ptr<HistoryLogDataRepoAliasChange>           Ptr;
 
332
    typedef shared_ptr<const HistoryLogDataRepoAliasChange>     constPtr;
 
333
    /** Ctor \b moving \a FieldVector (via swap).
 
334
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
335
     */
 
336
    HistoryLogDataRepoAliasChange( FieldVector & fields_r );
 
337
 
 
338
  public:
 
339
    enum Index                  ///< indices of known fields
 
340
    {
 
341
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
342
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
343
      OLDALIAS_INDEX,           ///< repositories old alias
 
344
      NEWALIAS_INDEX,           ///< repositories new alias
 
345
      USERDATA_INDEX,           ///< userdata/transactionID
 
346
   };
 
347
 
 
348
  public:
 
349
    std::string oldAlias()      const;  ///< repositories old alias
 
350
    std::string newAlias()      const;  ///< repositories new alias
 
351
    std::string userdata()      const;  ///< userdata/transactionID
 
352
  };
 
353
 
 
354
  ///////////////////////////////////////////////////////////////////
 
355
  /// \class HistoryLogDataRepoUrlChange
 
356
  /// \brief A zypp history log line for a repo url change.
 
357
  /// \ingroup g_ZyppHistory
 
358
  ///////////////////////////////////////////////////////////////////
 
359
  class HistoryLogDataRepoUrlChange : public HistoryLogData
 
360
  {
 
361
  public:
 
362
    typedef shared_ptr<HistoryLogDataRepoUrlChange>             Ptr;
 
363
    typedef shared_ptr<const HistoryLogDataRepoUrlChange>       constPtr;
 
364
    /** Ctor \b moving \a FieldVector (via swap).
 
365
     * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
 
366
     */
 
367
    HistoryLogDataRepoUrlChange( FieldVector & fields_r );
 
368
 
 
369
  public:
 
370
    enum Index                  ///< indices of known fields
 
371
    {
 
372
      DATE_INDEX        = HistoryLogData::DATE_INDEX,
 
373
      ACTION_INDEX      = HistoryLogData::ACTION_INDEX,
 
374
      ALIAS_INDEX,              ///< repository alias
 
375
      NEWURL_INDEX,             ///< repositories new url
 
376
      USERDATA_INDEX,           ///< userdata/transactionID
 
377
   };
 
378
 
 
379
  public:
 
380
    std::string alias()         const;  ///< repository alias
 
381
    Url         newUrl()        const;  ///< repositories new url
 
382
    std::string userdata()      const;  ///< userdata/transactionID
 
383
  };
 
384
 
 
385
} // namespace zypp
 
386
///////////////////////////////////////////////////////////////////
 
387
#endif /* ZYPP_HISTORYLOGDATA_H_ */