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;
46 static const HistoryActionID STAMP_COMMAND;
61 HistoryActionID() : _id(NONE_e) {}
63 HistoryActionID(ID id) : _id(id) {}
65 explicit HistoryActionID(const std::string & strval_r);
67 ID toEnum() const { return _id; }
69 static HistoryActionID::ID parse(const std::string & strval_r);
71 const std::string & asString(bool pad = false) const;
77 /** \relates HistoryActionID */
78 inline bool operator==( const HistoryActionID & lhs, const HistoryActionID & rhs )
79 { return lhs.toEnum() == rhs.toEnum(); }
81 /** \relates HistoryActionID */
82 inline bool operator!=( const HistoryActionID & lhs, const HistoryActionID & rhs )
83 { return lhs.toEnum() != rhs.toEnum(); }
85 /** \relates HistoryActionID */
86 std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
87 ///////////////////////////////////////////////////////////////////
89 ///////////////////////////////////////////////////////////////////
90 /// \class HistoryLogData
91 /// \brief A zypp history log line split into fields
92 /// \ingroup g_ZyppHistory
94 /// Each valid history log line starts with a date and HistoryActionID
95 /// field. Subsequent fields depend on the kind of action. See derived
96 /// classes for convenient access to those flields.
98 /// HistoryLogData itself provides mostly generic access to the fields
99 /// plain string values. Derived classes for well known entries tell
101 ///////////////////////////////////////////////////////////////////
105 typedef shared_ptr<HistoryLogData> Ptr;
106 typedef shared_ptr<const HistoryLogData> constPtr;
108 typedef std::vector<std::string> FieldVector;
109 typedef FieldVector::size_type size_type;
110 typedef FieldVector::const_iterator const_iterator;
113 /** Ctor \b moving \a FieldVector (via swap).
114 * \throws ParseException if \a fields_r has not at least \a expect_r entries
115 * \note 2 fields (date and action) are always required.
117 explicit HistoryLogData( FieldVector & fields_r, size_type expect_r = 2 );
119 /** Ctor \b moving \a FieldVector (via swap).
120 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or not at least \a expect_r entries.
121 * \note 2 fields (date and action) are always required.
123 HistoryLogData( FieldVector & fields_r, HistoryActionID action_r, size_type expect_r = 2 );
126 virtual ~HistoryLogData();
128 /** Factory method creating HistoryLogData classes.
130 * Moves \a fields_r into a HistoryLogData or derived object, depending on the
131 * HistoryActionID. For known action ids a coresponing HistoryLogData class
132 * is created, to allow convenient access to the field values. For unknown
133 * action ids a plain HistoryLogData object is created. \ref HistoryActionID
134 * \ref NONE_e id used in this case.
136 * \throws ParseException if \a fields_r does not contain the required format.
138 static Ptr create( FieldVector & fields_r );
141 /** Whether FieldVector is empty. */
144 /** Number of fields in vector. */
145 size_type size() const;
147 /** Iterator pointing to 1st element in vector (or end()). */
148 const_iterator begin() const;
150 /** Iterator pointing behind the last element in vector. */
151 const_iterator end() const;
153 /** Access (optional) field by number.
154 * \returns an empty string if \a idx_r is out of range.
157 const std::string & optionalAt( size_type idx_r ) const;
159 const std::string & operator[]( size_type idx_r ) const
160 { return optionalAt( idx_r ); }
162 /** Access (required) field by number.
163 * \throws std::out_of_range if \a idx_r is out of range.
164 * \see \ref optionalAt
166 const std::string & at( size_type idx_r ) const;
169 enum Index ///< indices of known fields
171 DATE_INDEX = 0, ///< date
172 ACTION_INDEX = 1, ///< HistoryActionID
176 Date date() const; ///< date
177 HistoryActionID action() const; ///< HistoryActionID (or \c NONE_e if unknown)
180 class Impl; ///< Implementation class
182 RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation
184 HistoryLogData & operator=( const HistoryLogData & ); ///< no base class assign
187 /** \relates HistoryLogData Stream output */
188 std::ostream & operator<<( std::ostream & str, const HistoryLogData & obj );
189 ///////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////
192 /// \class HistoryLogDataInstall
193 /// \brief A zypp history log line for an installed packaged.
194 /// \ingroup g_ZyppHistory
195 ///////////////////////////////////////////////////////////////////
196 class HistoryLogDataInstall : public HistoryLogData
199 typedef shared_ptr<HistoryLogDataInstall> Ptr;
200 typedef shared_ptr<const HistoryLogDataInstall> constPtr;
201 /** Ctor \b moving \a FieldVector (via swap).
202 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
204 HistoryLogDataInstall( FieldVector & fields_r );
207 enum Index ///< indices of known fields
209 DATE_INDEX = HistoryLogData::DATE_INDEX,
210 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
211 NAME_INDEX, ///< package name
212 EDITION_INDEX, ///< package edition
213 ARCH_INDEX, ///< package architecture
214 REQBY_INDEX, ///< requested by (user@hostname, pid:appname, or empty (solver))
215 REPOALIAS_INDEX, ///< repository providing the package
216 CHEKSUM_INDEX, ///< package checksum
217 USERDATA_INDEX, ///< userdata/transactionID
221 std::string name() const; ///< package name
222 Edition edition() const; ///< package edition
223 Arch arch() const; ///< package architecture
224 std::string reqby() const; ///< requested by (user@hostname, pid:appname, or empty (solver))
225 std::string repoAlias() const; ///< repository providing the package
226 CheckSum checksum() const; ///< package checksum
227 std::string userdata() const; ///< userdata/transactionID
230 ///////////////////////////////////////////////////////////////////
231 /// \class HistoryLogDataRemove
232 /// \brief A zypp history log line for a removed packge.
233 /// \ingroup g_ZyppHistory
234 ///////////////////////////////////////////////////////////////////
235 class HistoryLogDataRemove : public HistoryLogData
238 typedef shared_ptr<HistoryLogDataRemove> Ptr;
239 typedef shared_ptr<const HistoryLogDataRemove> constPtr;
240 /** Ctor \b moving \a FieldVector (via swap).
241 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
243 HistoryLogDataRemove( FieldVector & fields_r );
246 enum Index ///< indices of known fields
248 DATE_INDEX = HistoryLogData::DATE_INDEX,
249 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
250 NAME_INDEX, ///< package name
251 EDITION_INDEX, ///< package edition
252 ARCH_INDEX, ///< package architecture
253 REQBY_INDEX, ///< requested by (user@hostname, pid:appname, or empty (solver))
254 USERDATA_INDEX, ///< userdata/transactionID
258 std::string name() const; ///< package name
259 Edition edition() const; ///< package edition
260 Arch arch() const; ///< package architecture
261 std::string reqby() const; ///< requested by (user@hostname, pid:appname, or empty (solver))
262 std::string userdata() const; ///< userdata/transactionID
265 ///////////////////////////////////////////////////////////////////
266 /// \class HistoryLogDataRepoAdd
267 /// \brief A zypp history log line for an added repository.
268 /// \ingroup g_ZyppHistory
269 ///////////////////////////////////////////////////////////////////
270 class HistoryLogDataRepoAdd : public HistoryLogData
273 typedef shared_ptr<HistoryLogDataRepoAdd> Ptr;
274 typedef shared_ptr<const HistoryLogDataRepoAdd> constPtr;
275 /** Ctor \b moving \a FieldVector (via swap).
276 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
278 HistoryLogDataRepoAdd( FieldVector & fields_r );
281 enum Index ///< indices of known fields
283 DATE_INDEX = HistoryLogData::DATE_INDEX,
284 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
285 ALIAS_INDEX, ///< repository alias
286 URL_INDEX, ///< repository url
287 USERDATA_INDEX, ///< userdata/transactionID
291 std::string alias() const; ///< repository alias
292 Url url() const; ///< repository url
293 std::string userdata() const; ///< userdata/transactionID
296 ///////////////////////////////////////////////////////////////////
297 /// \class HistoryLogDataRepoRemove
298 /// \brief A zypp history log line for a removed repository.
299 /// \ingroup g_ZyppHistory
300 ///////////////////////////////////////////////////////////////////
301 class HistoryLogDataRepoRemove : public HistoryLogData
304 typedef shared_ptr<HistoryLogDataRepoRemove> Ptr;
305 typedef shared_ptr<const HistoryLogDataRepoRemove> constPtr;
306 /** Ctor \b moving \a FieldVector (via swap).
307 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
309 HistoryLogDataRepoRemove( FieldVector & fields_r );
312 enum Index ///< indices of known fields
314 DATE_INDEX = HistoryLogData::DATE_INDEX,
315 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
316 ALIAS_INDEX, ///< repository alias
317 USERDATA_INDEX, ///< userdata/transactionID
321 std::string alias() const; ///< repository alias
322 std::string userdata() const; ///< userdata/transactionID
325 ///////////////////////////////////////////////////////////////////
326 /// \class HistoryLogDataRepoAliasChange
327 /// \brief A zypp history log line for a repo alias change.
328 /// \ingroup g_ZyppHistory
329 ///////////////////////////////////////////////////////////////////
330 class HistoryLogDataRepoAliasChange : public HistoryLogData
333 typedef shared_ptr<HistoryLogDataRepoAliasChange> Ptr;
334 typedef shared_ptr<const HistoryLogDataRepoAliasChange> constPtr;
335 /** Ctor \b moving \a FieldVector (via swap).
336 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
338 HistoryLogDataRepoAliasChange( FieldVector & fields_r );
341 enum Index ///< indices of known fields
343 DATE_INDEX = HistoryLogData::DATE_INDEX,
344 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
345 OLDALIAS_INDEX, ///< repositories old alias
346 NEWALIAS_INDEX, ///< repositories new alias
347 USERDATA_INDEX, ///< userdata/transactionID
351 std::string oldAlias() const; ///< repositories old alias
352 std::string newAlias() const; ///< repositories new alias
353 std::string userdata() const; ///< userdata/transactionID
356 ///////////////////////////////////////////////////////////////////
357 /// \class HistoryLogDataRepoUrlChange
358 /// \brief A zypp history log line for a repo url change.
359 /// \ingroup g_ZyppHistory
360 ///////////////////////////////////////////////////////////////////
361 class HistoryLogDataRepoUrlChange : public HistoryLogData
364 typedef shared_ptr<HistoryLogDataRepoUrlChange> Ptr;
365 typedef shared_ptr<const HistoryLogDataRepoUrlChange> constPtr;
366 /** Ctor \b moving \a FieldVector (via swap).
367 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
369 HistoryLogDataRepoUrlChange( FieldVector & fields_r );
372 enum Index ///< indices of known fields
374 DATE_INDEX = HistoryLogData::DATE_INDEX,
375 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
376 ALIAS_INDEX, ///< repository alias
377 NEWURL_INDEX, ///< repositories new url
378 USERDATA_INDEX, ///< userdata/transactionID
382 std::string alias() const; ///< repository alias
383 Url newUrl() const; ///< repositories new url
384 std::string userdata() const; ///< userdata/transactionID
387 ///////////////////////////////////////////////////////////////////
388 /// \class HistoryLogDataStampCommand
389 /// \brief A zypp history log line identifying the program that
390 /// triggered the following commit.
391 /// \ingroup g_ZyppHistory
392 ///////////////////////////////////////////////////////////////////
393 class HistoryLogDataStampCommand : public HistoryLogData
396 typedef shared_ptr<HistoryLogDataStampCommand> Ptr;
397 typedef shared_ptr<const HistoryLogDataStampCommand> constPtr;
398 /** Ctor \b moving \a FieldVector (via swap).
399 * \throws ParseException if \a fields_r has the wrong \ref HistoryActionID or number of fields.
401 HistoryLogDataStampCommand( FieldVector & fields_r );
404 enum Index ///< indices of known fields
406 DATE_INDEX = HistoryLogData::DATE_INDEX,
407 ACTION_INDEX = HistoryLogData::ACTION_INDEX,
408 USER_INDEX, ///< executed by user@hostname
409 COMMAND_INDEX, ///< the commandline executed
410 USERDATA_INDEX, ///< userdata/transactionID
414 std::string executedBy() const; ///< executed by user@hostname
415 std::string command() const; ///< the commandline executed
416 std::string userdata() const; ///< userdata/transactionID
420 ///////////////////////////////////////////////////////////////////
421 #endif /* ZYPP_HISTORYLOGDATA_H_ */