Add class Ticket for future use.
This commit is contained in:
		
							
								
								
									
										64
									
								
								library/include/mobilisis/ticket.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								library/include/mobilisis/ticket.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
#ifndef TICKET_H_INCLUDED
 | 
			
		||||
#define TICKET_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <tuple>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDebugStateSaver>
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
 | 
			
		||||
#define NOT_INITIALIZED         (0)
 | 
			
		||||
#define VALID                   (1)
 | 
			
		||||
#define INVALID_FROM_DATETIME   (2)
 | 
			
		||||
#define INVALID_UNTIL_DATETIME  (3)
 | 
			
		||||
#define STATUS_END              (4)
 | 
			
		||||
 | 
			
		||||
class Ticket {
 | 
			
		||||
    enum {CODE=0, CODE_STR=1, CODE_DESC=3};
 | 
			
		||||
public:
 | 
			
		||||
    using Status = std::tuple<int, char const*, char const*>;
 | 
			
		||||
 | 
			
		||||
    explicit Ticket();
 | 
			
		||||
   
 | 
			
		||||
    explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
 | 
			
		||||
    operator QString();
 | 
			
		||||
 | 
			
		||||
    Status getStatus() const;
 | 
			
		||||
    QDateTime getValidFrom() const;
 | 
			
		||||
    QDateTime getValidUntil() const;
 | 
			
		||||
    uint32_t getPrice() const;
 | 
			
		||||
 | 
			
		||||
    Status setStatus(Status status);
 | 
			
		||||
    void setValidFrom(QDateTime const &validFrom);
 | 
			
		||||
    void setValidUntil(QDateTime const &validUnil);
 | 
			
		||||
    void setPrice(uint32_t price);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Status m_status;
 | 
			
		||||
 | 
			
		||||
    QDateTime m_validFrom;
 | 
			
		||||
    QDateTime m_validUntil;
 | 
			
		||||
    
 | 
			
		||||
    int m_durationMinutesNetto;
 | 
			
		||||
    int m_durationMinutesBrutto;
 | 
			
		||||
 | 
			
		||||
    uint32_t m_price;
 | 
			
		||||
 | 
			
		||||
    static constexpr const Status s[STATUS_END] = {
 | 
			
		||||
        {NOT_INITIALIZED       , "NOT_INITIALIZED"       , "Ticket not initialized"           },
 | 
			
		||||
        {VALID                 , "VALID"                 , "Ticket is valid"                  },
 | 
			
		||||
        {INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
 | 
			
		||||
        {INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime"  }
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
    
 | 
			
		||||
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
 | 
			
		||||
    QDebugStateSaver saver(debug);
 | 
			
		||||
    debug << "Ticket-Status: " << std::get<1>(status) 
 | 
			
		||||
          << "(" << std::get<2>(status) << ")";
 | 
			
		||||
    return debug;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // TICKET_H_INCLUDED
 | 
			
		||||
		Reference in New Issue
	
	Block a user