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 #define TARIFF_TIME_BASE_H_INCLUDED
#include <QString> #include <QString>
#include <QDebug>
#include <QDebugStateSaver>
struct ATBTimeBase { struct ATBTimeBase {
enum class TimeBaseType {ABSOLUTE=0, RELATIVE=1}; enum class TimeBaseType {ABSOLUTE=0, RELATIVE=1};
@ -9,6 +11,30 @@ struct ATBTimeBase {
ATBTimeBase() = default; ATBTimeBase() = default;
TimeBaseType tbase_type; TimeBaseType tbase_type;
QString tbase_label; 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 #endif // TARIFF_TIME_BASE_H_INCLUDED

View File

@ -1,8 +1,27 @@
#pragma once #ifndef TIME_RANGE_HEADER_H_INCLUDED
#include <ctime> #define TIME_RANGE_HEADER_H_INCLUDED
class ATBTimeRange { #include <QString>
public: #include <QDateTime>
time_t time_from; #include <QDebug>
time_t time_to; #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