-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.h
90 lines (71 loc) · 2.04 KB
/
Form.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by Niccolò Caselli on 16/06/23.
//
#ifndef ACTIVITYJOURNAL_FORM_H
#define ACTIVITYJOURNAL_FORM_H
#include "string"
#include "Subject.h"
#include "Observer.h"
#include "list"
#include "Utils.h"
/**
* Classe che si occupa di gestire i dati del form
* Fa ta Subject nel pattern Observer
*/
class Form: Subject {
public:
Form(){
date = Utils::getCurrentDate();
searchDate = std::time(0);
// initilalize varibailes to current time
startTime =std::time(0);
endTime = std::time(0);
}
const std::string &getDescription() const;
void setDescription(const std::string &description);
time_t getStartTime() const;
void setStartTime(time_t startTime);
time_t getEndTime() const;
void setEndTime(time_t endTime);
tm getDate() const;
void setDate(tm date);
time_t getSearchDate() const;
void setSearchDate(time_t date);
/**
* Metodo che notifica gli observer di un cambiamento dei dati
*/
void notifyObservers() const override {
for (auto observer : observers) {
observer->update();
}
}
/**
* Registra un observer
* @param observer
*/
void registerObserver(Observer *observer) override {
observers.push_back(observer);
}
/**
* Rimuove un observer
* @param observer
*/
void removeObserver(Observer *observer) override {
observers.remove(observer);
}
/**
* Metodo che valida i dati del form
* @return Restituisce se il form è valido
*/
bool validateForm() const;
private:
// dati del form:
std::string description;
std::time_t startTime;
std::time_t endTime;
std::tm date;
std::time_t searchDate;
// pattern observer:
std::list<Observer*> observers;
};
#endif //ACTIVITYJOURNAL_FORM_H