Introduce computational state
This commit is contained in:
		@@ -27,9 +27,16 @@ class Calculator {
 | 
				
			|||||||
                                            QDateTime const &start,
 | 
					                                            QDateTime const &start,
 | 
				
			||||||
                                            int netto_parking_time,
 | 
					                                            int netto_parking_time,
 | 
				
			||||||
                                            int paymentOptionIndex);
 | 
					                                            int paymentOptionIndex);
 | 
				
			||||||
 | 
					    struct State {
 | 
				
			||||||
 | 
					        bool m_timeLimitReached;
 | 
				
			||||||
 | 
					        uint32_t m_costAtTimeLimit;
 | 
				
			||||||
 | 
					    } m_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
    explicit Calculator() = default;
 | 
					    explicit Calculator() {
 | 
				
			||||||
 | 
					        m_state.m_timeLimitReached = false;
 | 
				
			||||||
 | 
					        m_state.m_costAtTimeLimit = ~0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    Calculator(Calculator const &other) = delete;
 | 
					    Calculator(Calculator const &other) = delete;
 | 
				
			||||||
@@ -40,6 +47,12 @@ public:
 | 
				
			|||||||
        return c;
 | 
					        return c;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool timeLimitReached() const { return m_state.m_timeLimitReached; }
 | 
				
			||||||
 | 
					    void setTimeLimitReached(bool timeLimitReached) { m_state.m_timeLimitReached = timeLimitReached; }
 | 
				
			||||||
 | 
					    bool costAtTimeLimit() const { return m_state.m_costAtTimeLimit; }
 | 
				
			||||||
 | 
					    void setCostAtTimeLimit(uint32_t cost) { if (m_state.m_costAtTimeLimit > cost) m_state.m_costAtTimeLimit = cost; }
 | 
				
			||||||
 | 
					    void resetCostAtTimeLimit() { m_state.m_costAtTimeLimit = ~0; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ResetTimeSteps(int paymentOptionIndex) {
 | 
					    void ResetTimeSteps(int paymentOptionIndex) {
 | 
				
			||||||
        if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
 | 
					        if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
 | 
				
			||||||
            m_timeSteps[paymentOptionIndex].clear();
 | 
					            m_timeSteps[paymentOptionIndex].clear();
 | 
				
			||||||
@@ -87,8 +100,8 @@ public:
 | 
				
			|||||||
    double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
 | 
					    double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
 | 
				
			||||||
                               PermitType permitType, bool nextDay = false, bool prepaid = false);
 | 
					                               PermitType permitType, bool nextDay = false, bool prepaid = false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::pair<CalcState, QDateTime> ComputeDurationFromCost(Configuration const* cfg, QDateTime const &startDatetimePassed,  int cost);
 | 
					    std::pair<CalcState, QDateTime> ComputeDurationFromCost(Configuration *cfg, QDateTime const &startDatetimePassed,  int cost);
 | 
				
			||||||
    std::pair<CalcState, std::optional<int>> ComputeCostFromDuration(Configuration const* cfg, QDateTime const &startDatetime, QDateTime &endDatetime, int nettoParkingTime);
 | 
					    std::pair<CalcState, std::optional<int>> ComputeCostFromDuration(Configuration *cfg, QDateTime const &startDatetime, QDateTime &endDatetime, int nettoParkingTime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Daily ticket
 | 
					    // Daily ticket
 | 
				
			||||||
    QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
 | 
					    QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user