Add operator << for printing

This commit is contained in:
Gerhard Hoffmann 2023-12-15 13:28:34 +01:00
parent ddded411aa
commit f1f5ac8900
2 changed files with 52 additions and 7 deletions

View File

@ -2,6 +2,8 @@
#define TARIFF_TIME_BASE_H_INCLUDED
#include <QString>
#include <QDebug>
#include <QDebugStateSaver>
struct ATBTimeBase {
enum class TimeBaseType {ABSOLUTE=0, RELATIVE=1};
@ -9,6 +11,30 @@ struct ATBTimeBase {
ATBTimeBase() = default;
TimeBaseType tbase_type;
QString tbase_label;
friend QDebug operator<<(QDebug debug, ATBTimeBase const &timeBase) {
QDebugStateSaver saver(debug);
switch(timeBase.tbase_type) {
case ATBTimeBase::TimeBaseType::ABSOLUTE:
debug.nospace()
<< " tbase_type: " << "TimeBaseType::ABSOLUTE" << "\n"
<< "tbase_label: " << timeBase.tbase_label << "\n";
break;
case ATBTimeBase::TimeBaseType::RELATIVE:
debug.nospace()
<< " tbase_type: " << "TimeBaseType::RELATIVE" << "\n"
<< "tbase_label: " << timeBase.tbase_label << "\n";
break;
default:
debug.nospace()
<< " tbase_type: " << "TimeBaseType::???" << "\n";
break;
}
return debug;
}
};
#endif // TARIFF_TIME_BASE_H_INCLUDED

View File

@ -1,8 +1,27 @@
#pragma once
#include <ctime>
#ifndef TIME_RANGE_HEADER_H_INCLUDED
#define TIME_RANGE_HEADER_H_INCLUDED
class ATBTimeRange {
public:
time_t time_from;
time_t time_to;
};
#include <QString>
#include <QDateTime>
#include <QDebug>
#include <QDebugStateSaver>
struct ATBTimeRange {
int time_range_id;
QTime time_range_from;
QTime time_range_to;
friend QDebug operator<<(QDebug debug, ATBTimeRange const &timeRange) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " time_range_id: " << timeRange.time_range_id << "\n"
<< "time_range_from: " << timeRange.time_range_from.toString(Qt::ISODate) << "\n"
<< " time_range_to: " << timeRange.time_range_to.toString(Qt::ISODate) << "\n";
return debug;
}
};
#endif // TIME_RANGE_HEADER_H_INCLUDED