-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLibrary.cpp
116 lines (101 loc) · 2.42 KB
/
Library.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "Library.h"
#include "Document.h"
#include "Book.h"
#include "CD.h"
#include "Movie.h"
#include <fstream>
#include <iostream>
#include <algorithm>
Library::Library()
{
}
Library::~Library()
{
}
void Library::addDoc(Document* doc)
{
_biblio.push_back(doc);
}
void Library::deleteDoc(Document* doc)
{
for(unsigned int i = 0;i<_biblio.size();i++)
{
if((_biblio[i]->getTitle() == doc->getTitle()) && (_biblio[i]->getAutor() == doc->getAutor()))
{
_biblio.erase(_biblio.begin()+i);
}
}
}
void Library::exportHTML()
{
std::ofstream f("index.html");
if(f)
{
f<<"<!DOCTYPE html>"<<std::endl;
f<<"<html>"<<std::endl;
f<<"<head>"<<"<h1>Liste des Documents</h1>"<<"</head>"<<std::endl;
f<<"<body>"<<std::endl;
f<<"<table border=\"1\";>"<<std::endl;
f<<"<tr><th><big>Title</big></th><th><big>Autor</big></th></th><th><big>Type</big></th></tr>"<<std::endl;
for(unsigned int i = 0;i<_biblio.size();i++)
{
Book* b = dynamic_cast<Book*>(_biblio[i]);
CD* c = dynamic_cast<CD*>(_biblio[i]);
f<<"<tr><th>"<<_biblio[i]->getTitle()<<"</th><th>"<<_biblio[i]->getAutor()<<"</th>";
if(b)
{
f<<"<th>Book</th></tr>" << std::endl;
}
else if (c)
{
f<<"<th>CD</th></tr>" << std::endl;
}
else
{
f<<"<th>Movie</th></tr>" << std::endl;
}
}
f<<"</table>"<<std::endl;
f<<"</body>"<<std::endl;
f<<"</html>"<<std::endl;
f.close();
}
}
Document& Library::searchDoc(std::string title)
{
unsigned int i=0;
bool ok = false;
Document* doc = new Document("Inconnu", "Inconnu");
while((i<_biblio.size()) && (ok == false))
{
if(_biblio[i]->getTitle() == title)
{
ok = true;
}
i++;
}
if(ok == false)
{
return *doc;
}
else
{
return *_biblio[i-1];
}
}
void Library::sort(bool (*f)(Document*, Document*))
{
std::sort(_biblio.begin(), _biblio.end(), f);
}
std::vector<Document*>& Library::getDoc()
{
return _biblio;
}
void Library::showDoc()
{
std::cout<<"\n*** Liste of Documents ***"<<std::endl;
for(unsigned int i=0;i<_biblio.size();i++)
{
std::cout<<"* "<<_biblio[i]->getTitle()<<std::endl;
}
}