-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstituicao.cpp
115 lines (100 loc) · 1.83 KB
/
Instituicao.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
#include "Instituicao.h"
#include "Sistema.h"
Instituicao::Instituicao() : Persistivel()
{
id = -1;
strcpy_s(nome, "");
strcpy_s(sigla, "");
strcpy_s(tipo, "");
definePersistidorNaConstrutora();
}
Instituicao::~Instituicao()
{
delete persistidor;
}
void Instituicao::definePersistidorNaConstrutora()
{
if (Sistema::getGravaTudoMemoriaRam())
{
persistidor = new PersisteMemoriaInstituicao(this);
}
else
{
persistidor = new PersisteBinarioInstituicao(this);
}
}
//setters
void Instituicao::setNome(const char * n)
{
strcpy_s(nome, n);
}
void Instituicao::setSigla(const char * s)
{
strcpy_s(sigla, s);
}
void Instituicao::setTipo(const char * t)
{
strcpy_s(tipo, t);
}
//getters
const char * Instituicao::getNome() const
{
return nome;
}
const char * Instituicao::getSigla() const
{
return sigla;
}
const char * Instituicao::getTipo() const
{
return tipo;
}
///inherited methods
bool Instituicao::gravar()
{
//inserindo novo cadastro
if (-1 == getId())
{
bool resposta = persistidor->inserir();
return resposta;
}
//alterando cadastro
else
{
bool resposta = persistidor->alterar();
return resposta;
}
return false;
}
bool Instituicao::remover()
{
bool resposta = persistidor->remover();
return resposta;
}
Persistivel* Instituicao::carregar(int id)
{
vector<Persistivel*> vLista = localizarCadastroPeloId(id);
if (vLista.size() == 1)
{
return vLista.at(0);
}
return false;
}
vector<Persistivel*> Instituicao::localizarCadastros()
{
return localizarCadastroPeloId(-1);
}
vector<Persistivel*> Instituicao::localizarCadastroPeloId(const int id)
{
vector<Persistivel*> vLista = persistidor->carregarCadastros(id);
return vLista;
}
Prototype* Instituicao::clone()
{
Instituicao *p = new Instituicao();
p->setId(getId());
p->setNome(getNome());
p->setSigla(getSigla());
p->setTipo(getTipo());
return p;
}