Add representations for PERMIT_TYPE and Product
This commit is contained in:
		
							
								
								
									
										101
									
								
								library/include/mobilisis/tariff_permit_type.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								library/include/mobilisis/tariff_permit_type.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,101 @@ | ||||
| #ifndef TARIFF_PERMIT_TYPE_H_INCLUDED | ||||
| #define TARIFF_PERMIT_TYPE_H_INCLUDED | ||||
|  | ||||
| #include <QString> | ||||
|  | ||||
| enum class PERMIT_TYPE : quint8 { | ||||
|     SHORT_TERM_PARKING, | ||||
|     DAY_TICKET, | ||||
|     SZEGED_START, | ||||
|     SZEGED_STOP, | ||||
|     DAY_TICKET_ADULT, | ||||
|     DAY_TICKET_TEEN, | ||||
|     DAY_TICKET_CHILD, | ||||
|     INVALID | ||||
| }; | ||||
|  | ||||
| struct PermitType { | ||||
|     PERMIT_TYPE m_permitType; | ||||
|  | ||||
|     PermitType() { m_permitType = PERMIT_TYPE::INVALID; } | ||||
|     PermitType(int permitType) { | ||||
|         switch(permitType) { | ||||
|         case 0: | ||||
|             m_permitType = PERMIT_TYPE::SHORT_TERM_PARKING; | ||||
|             break; | ||||
|         case 1: | ||||
|             m_permitType = PERMIT_TYPE::DAY_TICKET; | ||||
|             break; | ||||
|         case 2: | ||||
|             m_permitType = PERMIT_TYPE::SZEGED_START; | ||||
|             break; | ||||
|         case 3: | ||||
|             m_permitType = PERMIT_TYPE::SZEGED_STOP; | ||||
|             break; | ||||
|         case 4: | ||||
|             m_permitType = PERMIT_TYPE::DAY_TICKET_ADULT; | ||||
|             break; | ||||
|         case 5: | ||||
|             m_permitType = PERMIT_TYPE::DAY_TICKET_TEEN; | ||||
|             break; | ||||
|         case 6: | ||||
|             m_permitType = PERMIT_TYPE::DAY_TICKET_CHILD; | ||||
|             break; | ||||
|         default: | ||||
|             m_permitType = PERMIT_TYPE::INVALID; | ||||
|         } | ||||
|     } | ||||
|     PermitType(PERMIT_TYPE permitType) : m_permitType(permitType) {} | ||||
|  | ||||
|     void set(PERMIT_TYPE p) { m_permitType = p; } | ||||
|     PERMIT_TYPE get() const { return m_permitType; } | ||||
|  | ||||
|     operator PERMIT_TYPE() const { return m_permitType; } | ||||
|  | ||||
|     operator int() const { | ||||
|         switch(m_permitType) { | ||||
|         case PERMIT_TYPE::SHORT_TERM_PARKING: | ||||
|             return 0; | ||||
|         case PERMIT_TYPE::DAY_TICKET: | ||||
|             return 1; | ||||
|         case PERMIT_TYPE::SZEGED_START: | ||||
|             return 2; | ||||
|         case PERMIT_TYPE::SZEGED_STOP: | ||||
|             return 3; | ||||
|         case PERMIT_TYPE::DAY_TICKET_ADULT: | ||||
|             return 4; | ||||
|         case PERMIT_TYPE::DAY_TICKET_CHILD: | ||||
|             return 5; | ||||
|         case PERMIT_TYPE::DAY_TICKET_TEEN: | ||||
|             return 6; | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|         return 7; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     operator QString() const { | ||||
|         switch(m_permitType) { | ||||
|         case PERMIT_TYPE::DAY_TICKET: | ||||
|             return QString("DAY_TICKET"); | ||||
|         case PERMIT_TYPE::DAY_TICKET_ADULT: | ||||
|             return QString("DAY_TICKET_ADULT"); | ||||
|         case PERMIT_TYPE::DAY_TICKET_CHILD: | ||||
|             return QString("DAY_TICKET_CHILD"); | ||||
|         case PERMIT_TYPE::DAY_TICKET_TEEN: | ||||
|             return QString("DAY_TICKET_TEEN"); | ||||
|         case PERMIT_TYPE::SHORT_TERM_PARKING: | ||||
|             return QString("SHORT_TERM_PARKING"); | ||||
|         case PERMIT_TYPE::SZEGED_START: | ||||
|             return QString("SZEGED_START"); | ||||
|         case PERMIT_TYPE::SZEGED_STOP: | ||||
|             return QString("SZEGED_STOP"); | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|         return QString("INVALID"); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| #endif // TARIFF_PERMIT_TYPE_H_INCLUDED | ||||
							
								
								
									
										64
									
								
								library/include/mobilisis/tariff_product.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								library/include/mobilisis/tariff_product.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| #ifndef TARIFF_PRODUCT_H_INCLUDED | ||||
| #define TARIFF_PRODUCT_H_INCLUDED | ||||
|  | ||||
| #include <QString> | ||||
| #include <QDateTime> | ||||
| #include <QDebug> | ||||
| #include <QDebugStateSaver> | ||||
|  | ||||
| #include "tariff_permit_type.h" | ||||
|  | ||||
| struct ATBTariffProduct { | ||||
|     PermitType m_tariff_product_id; | ||||
|     uint32_t m_tariff_product_price; | ||||
|     QString m_tariff_product_name; | ||||
|     QTime m_tariff_product_start; | ||||
|     QTime m_tariff_product_end; | ||||
|     int m_tariff_product_from_in_minutes_from_start; | ||||
|     int m_tariff_product_to_in_minutes_from_start; | ||||
|  | ||||
|     explicit ATBTariffProduct() = default; | ||||
|  | ||||
|     QTime const &getTimeStart() const { return m_tariff_product_start; } | ||||
|     QTime const &getTimeEnd() const { return m_tariff_product_end; } | ||||
|  | ||||
|     bool computeQTimeStart(QTime const &t) { | ||||
|         if (m_tariff_product_from_in_minutes_from_start != -1) { | ||||
|             m_tariff_product_start = t.addSecs(m_tariff_product_from_in_minutes_from_start * 60); | ||||
|             return m_tariff_product_start.isValid(); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool computeQTimeEnd(QTime const &t) { | ||||
|         if (m_tariff_product_to_in_minutes_from_start != -1) { | ||||
|             m_tariff_product_end = t.addSecs(m_tariff_product_from_in_minutes_from_start * 60); | ||||
|             return m_tariff_product_end.isValid(); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     bool computeQTimes(QTime const &t) { | ||||
|         if (!t.isNull() && t.isValid()) { | ||||
|             return computeQTimeStart(t) && computeQTimeEnd(t); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) { | ||||
|         QDebugStateSaver saver(debug); | ||||
|  | ||||
|         debug.nospace() | ||||
|             << "                        m_tariff_product_id: " << QString(product.m_tariff_product_id) << "\n" | ||||
|             << "                      m_tariff_product_name: " << product.m_tariff_product_name << "\n" | ||||
|             << "                     m_tariff_product_price: " << product.m_tariff_product_price << "\n" | ||||
|             << "                     m_tariff_product_start: " << product.m_tariff_product_start << "\n" | ||||
|             << "                       m_tariff_product_end: " << product.m_tariff_product_end << "\n" | ||||
|             << "m_tariff_product_from_in_minutes_from_start: " << product.m_tariff_product_from_in_minutes_from_start << "\n" | ||||
|             << "  m_tariff_product_to_in_minutes_from_start: " << product.m_tariff_product_to_in_minutes_from_start << "\n"; | ||||
|  | ||||
|         return debug; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| #endif // TARIFF_PRODUCT_H_INCLUDED | ||||
		Reference in New Issue
	
	Block a user