1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
10
/** \file zypp/HistoryLogData.h
13
#ifndef ZYPP_HISTORYLOGDATA_H_
14
#define ZYPP_HISTORYLOGDATA_H_
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"
25
#define HISTORY_LOG_DATE_FORMAT "%Y-%m-%d %H:%M:%S"
27
///////////////////////////////////////////////////////////////////
30
///////////////////////////////////////////////////////////////////
31
/// \class HistoryActionID
32
/// \brief Enumeration of known history actions.
33
/// \ingroup g_EnumerationClass
34
/// \ingroup g_ZyppHistory
35
///////////////////////////////////////////////////////////////////
36
struct HistoryActionID
38
static const HistoryActionID NONE;
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;
59
HistoryActionID() : _id(NONE_e) {}
61
HistoryActionID(ID id) : _id(id) {}
63
explicit HistoryActionID(const std::string & strval_r);
65
ID toEnum() const { return _id; }
67
static HistoryActionID::ID parse(const std::string & strval_r);
69
const std::string & asString(bool pad = false) const;
75
/** \relates HistoryActionID */
76
inline bool operator==( const HistoryActionID & lhs, const HistoryActionID & rhs )
77
{ return lhs.toEnum() == rhs.toEnum(); }
79
/** \relates HistoryActionID */
80
inline bool operator!=( const HistoryActionID & lhs, const HistoryActionID & rhs )
81
{ return lhs.toEnum() != rhs.toEnum(); }
83
/** \relates HistoryActionID */
84
std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
85
///////////////////////////////////////////////////////////////////
87
///////////////////////////////////////////////////////////////////
88
/// \class HistoryLogData
89
/// \brief A zypp history log line split into fields
90
/// \ingroup g_ZyppHistory
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.
96
/// HistoryLogData itself provides mostly generic access to the fields
97
/// plain string values. Derived classes for well known entries tell
99
///////////////////////////////////////////////////////////////////
103
typedef shared_ptr<HistoryLogData> Ptr;
104
typedef shared_ptr<const HistoryLogData> constPtr;
106
typedef std::vector<std::string> FieldVector;
107
typedef FieldVector::size_type size_type;
108
typedef FieldVector::const_iterator const_iterator;
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.
115
explicit HistoryLogData( FieldVector & fields_r, size_type expect_r = 2 );
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.
121
HistoryLogData( FieldVector & fields_r, HistoryActionID action_r, size_type expect_r = 2 );
124
virtual ~HistoryLogData();
126
/** Factory method creating HistoryLogData classes.
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.
134
* \throws ParseException if \a fields_r does not contain the required format.
136
static Ptr create( FieldVector & fields_r );
139
/** Whether FieldVector is empty. */
142
/** Number of fields in vector. */
143
size_type size() const;
145
/** Iterator pointing to 1st element in vector (or end()). */
146
const_iterator begin() const;
148
/** Iterator pointing behind the last element in vector. */
149
const_iterator end() const;
151
/** Access (optional) field by number.
152
* \returns an empty string if \a idx_r is out of range.
155
const std::string & optionalAt( size_type idx_r ) const;
157
const std::string & operator[]( size_type idx_r ) const
158
{ return optionalAt( idx_r ); }
160
/** Access (required) field by number.
161
* \throws std::out_of_range if \a idx_r is out of range.
162
* \see \ref optionalAt
164
const std::string & at( size_type idx_r ) const;
167
enum Index ///< indices of known fields
169
DATE_INDEX = 0, ///< date
170
ACTION_INDEX = 1, ///< HistoryActionID
174
Date date() const; ///< date
175
HistoryActionID action() const; ///< HistoryActionID (or \c NONE_e if unknown)
178
class Impl; ///< Implementation class
180
RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation
182
HistoryLogData & operator=( const HistoryLogData & ); ///< no base class assign
185
/** \relates HistoryLogData Stream output */
186
std::ostream & operator<<( std::ostream & str, const HistoryLogData & obj );
187
///////////////////////////////////////////////////////////////////
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
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.
202
HistoryLogDataInstall( FieldVector & fields_r );
205
enum Index ///< indices of known fields
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
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
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
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.
241
HistoryLogDataRemove( FieldVector & fields_r );
244
enum Index ///< indices of known fields
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
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
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
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.
276
HistoryLogDataRepoAdd( FieldVector & fields_r );
279
enum Index ///< indices of known fields
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
289
std::string alias() const; ///< repository alias
290
Url url() const; ///< repository url
291
std::string userdata() const; ///< userdata/transactionID
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
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.
307
HistoryLogDataRepoRemove( FieldVector & fields_r );
310
enum Index ///< indices of known fields
312
DATE_INDEX = HistoryLogData::DATE_INDEX,
313
ACTION_INDEX = HistoryLogData::ACTION_INDEX,
314
ALIAS_INDEX, ///< repository alias
315
USERDATA_INDEX, ///< userdata/transactionID
319
std::string alias() const; ///< repository alias
320
std::string userdata() const; ///< userdata/transactionID
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
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.
336
HistoryLogDataRepoAliasChange( FieldVector & fields_r );
339
enum Index ///< indices of known fields
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
349
std::string oldAlias() const; ///< repositories old alias
350
std::string newAlias() const; ///< repositories new alias
351
std::string userdata() const; ///< userdata/transactionID
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
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.
367
HistoryLogDataRepoUrlChange( FieldVector & fields_r );
370
enum Index ///< indices of known fields
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
380
std::string alias() const; ///< repository alias
381
Url newUrl() const; ///< repositories new url
382
std::string userdata() const; ///< userdata/transactionID
386
///////////////////////////////////////////////////////////////////
387
#endif /* ZYPP_HISTORYLOGDATA_H_ */