libzypp: zypp::parser::HistoryLogReader Class Reference

libzypp 17.38.14

zypp::parser::HistoryLogReader Class Reference
Libzypp History File

Zypp history file parser. More...

`#include <zypp/parser/HistoryLogReader.h>`

## Classes
struct | Impl

## Public Types
enum | OptionBits { IGNORE_INVALID_ITEMS = (1 << 0) }
| < Parser option flags More...
using | ProcessData = function<bool (const HistoryLogData::Ptr &)>
| Callback type to consume a single history line split into fields.

## Public Member Functions
| ZYPP_DECLARE_FLAGS (Options, OptionBits)
| HistoryLogReader (Pathname historyFile_r, zypp::parser::HistoryLogReader::Options options_r, ProcessData callback_r)
| Ctor taking file to parse and data consumer callback.
| ~HistoryLogReader ()
void | readAll (const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
| Read the whole log file.
void | readFrom (const Date &date, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
| Read log from specified date.
void | readFromTo (const Date &fromDate, const Date &toDate, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
| Read log between fromDate and toDate.
void | setIgnoreInvalidItems (bool ignoreInvalid=false)
| Set the reader to ignore invalid log entries and continue with the rest.
bool | ignoreInvalidItems () const
| Whether the reader is set to ignore invalid log entries.
void | addActionFilter (const HistoryActionID &action_r)
| Process only specific HistoryActionIDs.
void | clearActionFilter ()
| Clear any HistoryActionIDs.

## Private Attributes
RW_pointer< Impl, rw_pointer::Scoped< Impl > > | _pimpl

## Detailed Description

Zypp history file parser.

Reads a zypp history log file and calls the ProcessData callback passed in the constructor for each valid history line read. The callbacks return value indicates whether to continue parsing.

std::vector<HistoryLogData::Ptr> history;
parser::HistoryLogReader parser( ZConfig::instance().historyLogFile(),
HistoryLogReader::Options(),
[&history]( HistoryLogData::Ptr ptr )->bool {
history.push_back( ptr );
return true;
} );
parser.readAll();
...
if ( history[0]->action() == HistoryActionID::INSTALL )
{
// generic access to data fields plain string values:
MIL << (*p)[HistoryLogDataInstall::USERDATA_INDEX] << endl;
// The same maybe more convenient though derived classes:
HistoryLogDataInstall::Ptr ip( dynamic_pointer_cast<HistoryLogDataInstall>( p ) );
MIL << ip->userdata() << endl;
}
MIL
#define MIL
Definition Logger.h:103
zypp::HistoryLogDataInstall::Ptr
shared_ptr< HistoryLogDataInstall > Ptr
Definition HistoryLogData.h:202
zypp::HistoryLogDataInstall::USERDATA_INDEX
@ USERDATA_INDEX
userdata/transactionID
Definition HistoryLogData.h:220
zypp::HistoryLogData::Ptr
shared_ptr< HistoryLogData > Ptr
Definition HistoryLogData.h:108
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:794
zypp::parser::HistoryLogReader
Zypp history file parser.
Definition HistoryLogReader.h:67
zypp::parser
Definition HistoryLogReader.cc:30

See also
  HistoryLogData for how to access the individual data fields.

Definition at line 66 of file HistoryLogReader.h.

## Member Typedef Documentation

## ◆ ProcessData

using zypp::parser::HistoryLogReader::ProcessData = function<bool (const HistoryLogData::Ptr &)>

Callback type to consume a single history line split into fields.

The return value indicates whether to continue parsing.

Definition at line 80 of file HistoryLogReader.h.

## Member Enumeration Documentation

## ◆ OptionBits

enum zypp::parser::HistoryLogReader::OptionBits

< Parser option flags

Enumerator
IGNORE_INVALID_ITEMS | ignore invalid items and continue parsing

Definition at line 70 of file HistoryLogReader.h.

## Constructor & Destructor Documentation

## ◆ HistoryLogReader()

zypp::parser::HistoryLogReader::HistoryLogReader | ( | Pathname | historyFile_r,
|  | zypp::parser::HistoryLogReader::Options | options_r,
|  | ProcessData | callback_r )

Ctor taking file to parse and data consumer callback.

As options_r argument pass `HistoryLogReader::Options()` to use the default stettings, or an OR'ed combination of OptionBits.

Definition at line 216 of file HistoryLogReader.cc.

## ◆ ~HistoryLogReader()

zypp::parser::HistoryLogReader::~HistoryLogReader | ( |  | ) |

Definition at line 220 of file HistoryLogReader.cc.

## Member Function Documentation

## ◆ ZYPP_DECLARE_FLAGS()

zypp::parser::HistoryLogReader::ZYPP_DECLARE_FLAGS | ( | Options | ,
|  | OptionBits | )

## ◆ readAll()

void zypp::parser::HistoryLogReader::readAll | ( | const ProgressData::ReceiverFnc & | progress = ProgressData::ReceiverFnc() | ) |

Read the whole log file.

Parameters

  progress | An optional progress data receiver function.

Definition at line 229 of file HistoryLogReader.cc.

## ◆ readFrom()

void zypp::parser::HistoryLogReader::readFrom | ( | const Date & | date,
|  | const ProgressData::ReceiverFnc & | progress = ProgressData::ReceiverFnc() )

Read log from specified date.

Parameters

  date | Date from which to read.
  progress | An optional progress data receiver function.

See also
  readFromTo()

Definition at line 232 of file HistoryLogReader.cc.

## ◆ readFromTo()

void zypp::parser::HistoryLogReader::readFromTo | ( | const Date & | fromDate,
|  | const Date & | toDate,
|  | const ProgressData::ReceiverFnc & | progress = ProgressData::ReceiverFnc() )

Read log between fromDate and toDate.

The date comparison's precision goes to seconds. Omitted time parts get replaced by zeroes, so if e.g. the time is not specified at all, the date means midnight of the specified date. So

`fromDate = Date("2009-01-01", "%Y-%m-%d"); toDate = Date("2009-01-02", "%Y-%m-%d");`

will yield log entries from midnight of January, 1st untill one second before midnight of January, 2nd.

Parameters

  fromDate | Date from which to read.
  toDate | Date on which to stop reading.
  progress | An optional progress data receiver function.

Definition at line 235 of file HistoryLogReader.cc.

## ◆ setIgnoreInvalidItems()

void zypp::parser::HistoryLogReader::setIgnoreInvalidItems | ( | bool | ignoreInvalid = false | ) |

Set the reader to ignore invalid log entries and continue with the rest.

Parameters

  ignoreInvalid | true will cause the reader to ignore invalid entries

Definition at line 223 of file HistoryLogReader.cc.

## ◆ ignoreInvalidItems()

bool zypp::parser::HistoryLogReader::ignoreInvalidItems | ( |  | ) | const

Whether the reader is set to ignore invalid log entries.

See also
  setIngoreInvalidItems()

Definition at line 226 of file HistoryLogReader.cc.

## ◆ addActionFilter()

void zypp::parser::HistoryLogReader::addActionFilter | ( | const HistoryActionID & | action_r | ) |

Process only specific HistoryActionIDs.

Call repeatedly to add multiple HistoryActionIDs to process. Passing an empty HistoryActionID (HistoryActionID::NONE) clears the filter.

Definition at line 238 of file HistoryLogReader.cc.

## ◆ clearActionFilter()

void zypp::parser::HistoryLogReader::clearActionFilter | ( |  | ) |
| inline

Clear any HistoryActionIDs.

Definition at line 151 of file HistoryLogReader.h.

## Member Data Documentation

## ◆ _pimpl

RW_pointer<Impl,rw_pointer::Scoped<Impl> > zypp::parser::HistoryLogReader::_pimpl
| private

Definition at line 157 of file HistoryLogReader.h.

The documentation for this class was generated from the following files:

- zypp/parser/HistoryLogReader.h
- zypp/parser/HistoryLogReader.cc