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/ProgressData.h"
18 #include "zypp/Pathname.h"
20 #include "zypp/HistoryLogData.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////////
35 // CLASS NAME: HistoryLogReader
38 * Reads a zypp history log file and calls the ProcessItem function passed
39 * in the constructor for each item read.
44 * struct HistoryItemCollector
46 * vector<HistoryItem::Ptr> items;
48 * bool operator()( const HistoryItem::Ptr & item_ptr )
50 * items.push_back(item_ptr);
57 * HistoryItemCollector ic;
58 * HistoryLogReader reader("/var/log/zypp/history", boost::ref(ic));
64 * catch (const Exception & e)
66 * cout << e.asUserHistory() << endl;
71 * \see http://en.opensuse.org/Libzypp/Package_History
73 class HistoryLogReader
76 typedef function< bool( const HistoryItem::Ptr & )> ProcessItem;
79 HistoryLogReader( const Pathname & repo_file,
80 const ProcessItem & callback );
84 * Read the whole log file.
86 * \param progress An optional progress data receiver function.
89 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
92 * Read log from specified \a date.
94 * \param date Date from which to read.
95 * \param progress An optional progress data receiver function.
99 void readFrom( const Date & date,
100 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
103 * Read log between \a fromDate and \a toDate.
105 * The date comparison's precision goes to seconds. Omitted time parts
106 * get replaced by zeroes, so if e.g. the time is not specified at all, the
107 * date means midnight of the specified date. So
110 * fromDate = Date("2009-01-01", "%Y-%m-%d");
111 * toDate = Date("2009-01-02", "%Y-%m-%d");
114 * will yield log entries from midnight of January, 1st untill
115 * one second before midnight of January, 2nd.
117 * \param fromDate Date from which to read.
118 * \param toDate Date on which to stop reading.
119 * \param progress An optional progress data receiver function.
121 void readFromTo( const Date & fromDate, const Date & toDate,
122 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
125 * Set the reader to ignore invalid log entries and continue with the rest.
127 * \param ignoreInvalid <tt>true</tt> will cause the reader to ignore invalid entries
129 void setIgnoreInvalidItems( bool ignoreInvalid = false );
132 * Whether the reader is set to ignore invalid log entries.
134 * \see setIngoreInvalidItems()
136 bool ignoreInvalidItems() const;
139 /** Implementation */
141 RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
143 ///////////////////////////////////////////////////////////////////
146 /////////////////////////////////////////////////////////////////
147 } // namespace parser
148 ///////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////
151 ///////////////////////////////////////////////////////////////////
153 #endif /* ZYPP_PARSER_HISTORYLOGREADER_H_ */