-
Notifications
You must be signed in to change notification settings - Fork 0
/
E.cpp
92 lines (78 loc) · 1.21 KB
/
E.cpp
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
91
92
#include "E.h"
int E::count = 0;
void E::decr_count()
{
count--;
}
void E::decr_curr_num_of_objects()
{
curr_num_of_objects--;
}
void E::set_priority(int p)
{
priority = p;
vec_obj.push(this);
}
int E::get_priority()
{
return priority;
}
E* E::get()
{
if(curr_num_of_objects < N)
{
count++;
curr_num_of_objects++;
E* o = new E();
//vec_obj.push(o);
return (o);
}
else
{
throw std::runtime_error("too many objects");
}
}
void E::print()
{
cout<<"E\n";
}
void E::del()
{
if(this == vec_obj.top())
{
this->decr_count();//
//this->count--;
this->decr_curr_num_of_objects();//
//this->curr_num_of_objects--;
vec_obj.pop();
delete(dynamic_cast<E*>(this));
}
else
{
throw runtime_error("Invalid priority");
}
}
int E::get_count()
{
return count;
}
/*
void E::del()
{
auto it = find(vec_obj.begin(), vec_obj.end(), this);
if(it != vec_obj.end())
{
assert((dynamic_cast<E*>(*it)) == this);
delete( dynamic_cast<E*>(*it) );
vec_obj.erase(it);
count--;
curr_num_of_objects--;
}
}
*/
E::~E()
{
cout<<"E dtor\n";
}
void E::operator delete( void * ) {}
E::E(){}