Add structures to encode service and out-of-service times
This commit is contained in:
		
							
								
								
									
										79
									
								
								library/include/mobilisis/tariff_out_of_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								library/include/mobilisis/tariff_out_of_service.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
#ifndef TARIFF_OUT_OF_SERVICE_H_INCLUDED
 | 
			
		||||
#define TARIFF_OUT_OF_SERVICE_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "time_range.h"
 | 
			
		||||
 | 
			
		||||
enum class ApplyOutOfService {
 | 
			
		||||
    NEVER = 0,
 | 
			
		||||
    MATCH_PREV_DAY = 1,
 | 
			
		||||
    MATCH_NEXT_DAY = 2,
 | 
			
		||||
    ALWAYS = 3
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ATBTariffOutOfService {
 | 
			
		||||
    int m_id;
 | 
			
		||||
    QString m_weekDay;
 | 
			
		||||
    QDate m_date;
 | 
			
		||||
    TimeRange m_range;
 | 
			
		||||
    ApplyOutOfService m_outOfServiceIf;
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffOutOfService()
 | 
			
		||||
      : m_id(-1)
 | 
			
		||||
      , m_outOfServiceIf(ApplyOutOfService::NEVER) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setOutOfServiceIf(QString const &oosif) {
 | 
			
		||||
        if (oosif == "never") {
 | 
			
		||||
            m_outOfServiceIf = ApplyOutOfService::NEVER;
 | 
			
		||||
        } else
 | 
			
		||||
        if (oosif == "match_prev_day") {
 | 
			
		||||
            m_outOfServiceIf = ApplyOutOfService::MATCH_PREV_DAY;
 | 
			
		||||
        } else
 | 
			
		||||
        if (oosif == "match_next_day") {
 | 
			
		||||
            m_outOfServiceIf = ApplyOutOfService::MATCH_NEXT_DAY;
 | 
			
		||||
        } else
 | 
			
		||||
        if (oosif == "always") {
 | 
			
		||||
            m_outOfServiceIf = ApplyOutOfService::ALWAYS;
 | 
			
		||||
        } else {
 | 
			
		||||
           qCritical() << "ERROR unknown servcie application" << oosif;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ApplyOutOfService outOfServiceIf() const {
 | 
			
		||||
        return m_outOfServiceIf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QString outOfServiceIfStr() const {
 | 
			
		||||
        if (m_outOfServiceIf == ApplyOutOfService::NEVER) {
 | 
			
		||||
            return "never";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_outOfServiceIf == ApplyOutOfService::ALWAYS) {
 | 
			
		||||
            return "always";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_outOfServiceIf == ApplyOutOfService::MATCH_PREV_DAY) {
 | 
			
		||||
            return "match prev day";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_outOfServiceIf == ApplyOutOfService::MATCH_NEXT_DAY) {
 | 
			
		||||
            return "match next day";
 | 
			
		||||
        }
 | 
			
		||||
        return QString("ERROR unknown out of service application: %1").arg(static_cast<int>(m_outOfServiceIf));
 | 
			
		||||
    }
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBTariffOutOfService const &oos) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "\nTariffOutOfService:\n"
 | 
			
		||||
            << "            week day: " << oos.m_weekDay << "\n"
 | 
			
		||||
            << "                date: " << oos.m_date.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "                  id: " << oos.m_id << "\n"
 | 
			
		||||
            << "               start: " << oos.m_range.m_start << "\n"
 | 
			
		||||
            << "                 end: " << oos.m_range.m_end << "\n"
 | 
			
		||||
            << "            duration: " << oos.m_range.m_duration << endl;
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TARIFF_SERVICE_H_INCLUDED
 | 
			
		||||
							
								
								
									
										81
									
								
								library/include/mobilisis/tariff_service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								library/include/mobilisis/tariff_service.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
			
		||||
#ifndef TARIFF_SERVICE_H_INCLUDED
 | 
			
		||||
#define TARIFF_SERVICE_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "time_range.h"
 | 
			
		||||
 | 
			
		||||
enum class ApplyService {
 | 
			
		||||
    NEVER = 0,
 | 
			
		||||
    MATCH_PREV_DAY = 1,
 | 
			
		||||
    MATCH_NEXT_DAY = 2,
 | 
			
		||||
    ALWAYS = 3
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ATBTariffService {
 | 
			
		||||
    int m_id;
 | 
			
		||||
    QString m_weekDay;
 | 
			
		||||
    QDate m_date;
 | 
			
		||||
    TimeRange m_range;
 | 
			
		||||
    ApplyService m_serviceIf;
 | 
			
		||||
 | 
			
		||||
    explicit ATBTariffService()
 | 
			
		||||
      : m_id(-1)
 | 
			
		||||
      , m_serviceIf(ApplyService::NEVER) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setServiceIf(QString const &sif) {
 | 
			
		||||
        if (sif == "never") {
 | 
			
		||||
            m_serviceIf = ApplyService::NEVER;
 | 
			
		||||
        } else
 | 
			
		||||
        if (sif == "match_prev_day") {
 | 
			
		||||
            m_serviceIf = ApplyService::MATCH_PREV_DAY;
 | 
			
		||||
        } else
 | 
			
		||||
        if (sif == "match_next_day") {
 | 
			
		||||
            m_serviceIf = ApplyService::MATCH_NEXT_DAY;
 | 
			
		||||
        } else
 | 
			
		||||
        if (sif == "always") {
 | 
			
		||||
            m_serviceIf = ApplyService::ALWAYS;
 | 
			
		||||
        } else {
 | 
			
		||||
           qCritical() << "ERROR unknown servcie application" << sif;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ApplyService serviceIf() const {
 | 
			
		||||
        return m_serviceIf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QString serviceIfStr() const {
 | 
			
		||||
        if (m_serviceIf == ApplyService::NEVER) {
 | 
			
		||||
            return "never";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_serviceIf == ApplyService::ALWAYS) {
 | 
			
		||||
            return "always";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_serviceIf == ApplyService::MATCH_PREV_DAY) {
 | 
			
		||||
            return "match prev day";
 | 
			
		||||
        }
 | 
			
		||||
        if (m_serviceIf == ApplyService::MATCH_NEXT_DAY) {
 | 
			
		||||
            return "match next day";
 | 
			
		||||
        }
 | 
			
		||||
        return QString("ERROR unknown service application: %1").arg(static_cast<int>(m_serviceIf));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    friend QDebug operator<<(QDebug debug, ATBTariffService const &ts) {
 | 
			
		||||
        QDebugStateSaver saver(debug);
 | 
			
		||||
 | 
			
		||||
        debug.nospace()
 | 
			
		||||
            << "\nTariffService:\n"
 | 
			
		||||
            << "       week day: " << ts.m_weekDay << "\n"
 | 
			
		||||
            << "           date: " << ts.m_date.toString(Qt::ISODate) << "\n"
 | 
			
		||||
            << "             id: " << ts.m_id << "\n"
 | 
			
		||||
            << "          start: " << ts.m_range.m_start << "\n"
 | 
			
		||||
            << "            end: " << ts.m_range.m_end << "\n"
 | 
			
		||||
            << "       duration: " << ts.m_range.m_duration << "\n"
 | 
			
		||||
            << "     prepaid if: " << ts.serviceIfStr() << endl;
 | 
			
		||||
        return debug;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TARIFF_SERVICE_H_INCLUDED
 | 
			
		||||
		Reference in New Issue
	
	Block a user