-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_event.h
58 lines (49 loc) · 1.42 KB
/
custom_event.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
#ifndef CUSTOM_EVENT_H_
#define CUSTOM_EVENT_H_
#include "base_event.h"
namespace mtm
{
template <class CanRegister>
class CustomEvent;
}
template <typename CanRegister>
class mtm::CustomEvent: public mtm::BaseEvent
{
private:
CanRegister can_register;
public:
CustomEvent(mtm::DateWrap date,std::string name, CanRegister can_register);
~CustomEvent(){}
void registerParticipant(int participant) override;
CustomEvent* clone() const override;
};
namespace mtm
{
template <typename CanRegister>
CustomEvent<CanRegister>::CustomEvent(mtm::DateWrap date, std::string name, CanRegister function)
:BaseEvent(date, name), can_register(function) {}
template <typename CanRegister>
void CustomEvent<CanRegister>::registerParticipant(int participant)
{
if (participant > this->MAX_STUDENT || participant < this->MIN_STUDENT)
{
throw InvalidStudent();
}
if(this->can_register(participant))
{
BaseEvent::registerParticipant(participant);
}
else
{
throw RegistrationBlocked();
}
}
template <typename CanRegister>
CustomEvent<CanRegister>* CustomEvent<CanRegister>::clone() const
{
CustomEvent* cloned_event = new CustomEvent(this->date,this->name, this->can_register);
cloned_event->participants = this->participants;
return cloned_event;
}
}
#endif