-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
89 lines (83 loc) · 2.96 KB
/
main.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
#include <cstdlib>
#include <iostream>
#include <random>
#include "My_forward_list.h"
#include "MyForwardIterator.h"
#include "Shape.h"
#include "factory.h"
using namespace std;
typedef My_forward_list<Shape*> list;
typedef MyForwardIterator<Shape*> list_iterator;
int main(int argc, char** argv)
{
std::random_device rd;
std::uniform_int_distribution<int> gen_type(0, 5);
try
{
list shapes_list;
for(int i=0; i<20; i++)
{
int job=gen_type(rd);
if(job == 0)
shapes_list.add_in_ending(random_factory(std::string("Point")));
else if(job == 1)
shapes_list.add_in_ending(random_factory(std::string("Circle")));
else if(job == 2)
shapes_list.add_in_ending(random_factory(std::string("Rect")));
else if(job == 3)
shapes_list.add_in_ending(random_factory(std::string("Square")));
else if(job == 4)
shapes_list.add_in_ending(random_factory(std::string("Polyline")));
else //if(job == 5)
shapes_list.add_in_ending(random_factory(std::string("Polygon")));
}
std::cout << "Shape::GetCount()=" << Shape::get_counter() << '\n' << "INFO\n";
list_iterator i(shapes_list.get_beginning());
while(i != shapes_list.get_ending())
{
std::cout << (*(i))->get_info() << '\n';
i++;
}
std::cout << (*i)->get_info() << '\n';
//очищаем память ручками т.к у нас список указателей
i=shapes_list.get_beginning();
while(i != shapes_list.get_ending())
{
delete *i;
i++;
}
delete *i;
std::cout << "Shape::GetCount()=" << Shape::get_counter() << '\n';
}
catch(My_forward_list_errors err)
{
switch(err)
{
case CANT_ALLOCATE_MEMORY://она не выкидывается. вместо нее обычный бэд аллок идет...
cout << "CANT_ALLOCATE_MEMORY\n";
return -1;
case ACCESS_TO_ELEMNT_FROM_EMPTY_LIST:
cout << "ACCESS_TO_ELEMNT_FROM_EMPTY_LIST\n";
return -1;
case ITERATOR_HAVE_MOVED_OUTSIDE_LIST:
cout << "ITERATOR_HAVE_MOVED_OUTSIDE_LIST\n";
return -1;
}
}
catch(Shape_errors err)
{
switch(err)
{
case WRONG_PARAMETERS_FOR_CIRCLE:
cout << "WRONG_PARAMETERS_FOR_CIRCLE\n";
return -1;
case WRONG_PARAMETERS_FOR_RECT:
cout << "WRONG_PARAMETERS_FOR_RECT\n";
return -1;
case WRONG_PARAMETERS_FOR_SQUARE:
cout << "WRONG_PARAMETERS_FOR_SQUARE\n";
return -1;
}
}
return 0;
}