1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
10 /** \file zypp/parser/HistoryLogReader.h
13 #ifndef ZYPP_PARSER_HISTORYLOGREADER_H_
14 #define ZYPP_PARSER_HISTORYLOGREADER_H_
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/base/Flags.h"
18 #include "zypp/ProgressData.h"
19 #include "zypp/Pathname.h"
21 #include "zypp/HistoryLogData.h"
23 ///////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
34 /// \class HistoryLogReader
35 /// \brief Zypp history file parser
36 /// \ingroup g_ZyppHistory
37 /// \ingroup g_ZyppParser
39 /// Reads a zypp history log file and calls the \ref ProcessData callback
40 /// passed in the constructor for each valid history line read. The callbacks
41 /// return value indicates whether to continue parsing.
44 /// std::vector<HistoryLogData::Ptr> history;
45 /// parser::HistoryLogReader parser( ZConfig::instance().historyLogFile(),
46 /// HistoryLogReader::Options(),
47 /// [&history]( HistoryLogData::Ptr ptr )->bool {
48 /// history.push_back( ptr );
53 /// if ( history[0]->action() == HistoryActionID::INSTALL )
55 /// // generic access to data fields plain string values:
56 /// MIL << (*p)[HistoryLogDataInstall::USERDATA_INDEX] << endl;
58 /// // The same maybe more convenient though derived classes:
59 /// HistoryLogDataInstall::Ptr ip( dynamic_pointer_cast<HistoryLogDataInstall>( p ) );
60 /// MIL << ip->userdata() << endl;
63 /// \see \ref HistoryLogData for how to access the individual data fields.
65 ///////////////////////////////////////////////////////////////////
66 class HistoryLogReader
70 enum OptionBits ///< Parser option flags
72 IGNORE_INVALID_ITEMS = (1 << 0) ///< ignore invalid items and continue parsing
74 ZYPP_DECLARE_FLAGS( Options, OptionBits );
77 /** Callback type to consume a single history line split into fields.
78 * The return value indicates whether to continue parsing.
80 typedef function< bool( const HistoryLogData::Ptr & )> ProcessData;
82 /** Ctor taking file to parse and data consumer callback.
83 * As \a options_r argument pass \c HistoryLogReader::Options() to
84 * use the default stettings, or an OR'ed combination of \ref OptionBits.
86 HistoryLogReader( const Pathname & historyFile_r, const Options & options_r, const ProcessData & callback_r );
91 * Read the whole log file.
93 * \param progress An optional progress data receiver function.
95 void readAll( const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
98 * Read log from specified \a date.
100 * \param date Date from which to read.
101 * \param progress An optional progress data receiver function.
105 void readFrom( const Date & date, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
108 * Read log between \a fromDate and \a toDate.
110 * The date comparison's precision goes to seconds. Omitted time parts
111 * get replaced by zeroes, so if e.g. the time is not specified at all, the
112 * date means midnight of the specified date. So
115 * fromDate = Date("2009-01-01", "%Y-%m-%d");
116 * toDate = Date("2009-01-02", "%Y-%m-%d");
119 * will yield log entries from midnight of January, 1st untill
120 * one second before midnight of January, 2nd.
122 * \param fromDate Date from which to read.
123 * \param toDate Date on which to stop reading.
124 * \param progress An optional progress data receiver function.
126 void readFromTo( const Date & fromDate, const Date & toDate, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
129 * Set the reader to ignore invalid log entries and continue with the rest.
131 * \param ignoreInvalid <tt>true</tt> will cause the reader to ignore invalid entries
133 void setIgnoreInvalidItems( bool ignoreInvalid = false );
136 * Whether the reader is set to ignore invalid log entries.
138 * \see setIngoreInvalidItems()
140 bool ignoreInvalidItems() const;
143 /** Process only specific HistoryActionIDs.
144 * Call repeatedly to add multiple HistoryActionIDs to process.
145 * Passing an empty HistoryActionID (HistoryActionID::NONE) clears
148 void addActionFilter( const HistoryActionID & action_r );
150 /** Clear any HistoryActionIDs. */
151 void clearActionFilter()
152 { addActionFilter( HistoryActionID::NONE ); }
155 /** Implementation */
157 RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
160 /** \relates HistoryLogReader::Options */
161 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( HistoryLogReader::Options );
163 ///////////////////////////////////////////////////////////////////
165 } // namespace parser
166 /////////////////////////////////////////////////////////////////
168 ///////////////////////////////////////////////////////////////////
170 #endif /* ZYPP_PARSER_HISTORYLOGREADER_H_ */