-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndiceDatos.cpp
More file actions
116 lines (85 loc) · 2.48 KB
/
IndiceDatos.cpp
File metadata and controls
116 lines (85 loc) · 2.48 KB
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
/*
* IndiceDatos.cpp
*
* Created on: Jun 1, 2012
* Author: vdiego
*/
#include "IndiceDatos.h"
#include <iostream>
#include "Claves/InstanciadorIncidentes.h"
#include "Claves/ClaveIncidente.h"
using namespace std;
IndiceDatos::~IndiceDatos()
{
delete this->m_arbolBKD;
}
IndiceDatos* IndiceDatos::Crear(const std::string filePath, int tamanioBloque)
{
IndiceDatos* ret = new IndiceDatos();
ret->m_arbolBKD = BKDArbol::CrearEnDisco(filePath, tamanioBloque, new InstanciadorIncidentes());
if (ret->m_arbolBKD == NULL)
cerr << "Ocurrió un error al intentar crear el archivo de indice." << endl;
return ret;
}
IndiceDatos* IndiceDatos::Abrir(std::string filePath, int tamanioBloque)
{
IndiceDatos* ret = new IndiceDatos();
ret->m_arbolBKD = BKDArbol::AbrirDeDisco(filePath, new InstanciadorIncidentes());
if (ret->m_arbolBKD == NULL)
cerr << "Ocurrió un error al intentar acceder al archivo de indice." << endl;
return ret;
}
Incidente IndiceDatos::BuscarIncidente(Incidente incidente)
{
BKDRegistro* inPtr;
//ClaveInt clave = ClaveInt(incidente.formacion);
ClaveIncidente clave = ClaveIncidente(incidente);
if (!this->m_arbolBKD->BuscarRegistro(clave, &inPtr))
return Incidente();
else
{
Incidente res = Incidente(*(Incidente*)inPtr);
delete inPtr;
return res;
}
}
std::list<Incidente> IndiceDatos::BuscarPorRango(Incidente incidenteMin, Incidente incidenteMax)
{
list<BKDRegistro*> outList;
list<Incidente> result;
ClaveIncidente claveMin = ClaveIncidente(incidenteMin);
ClaveIncidente claveMax = ClaveIncidente(incidenteMax);
m_arbolBKD->DebugPrintAll();
if (!this->m_arbolBKD->BuscarPorRango(claveMin, claveMax, outList)) {
cout << "No hay Incidentes para ese criterio de busqueda" << endl;
return result;
}
else
{
cout << "Incidentes Encontrados: " << endl;
for(std::list<BKDRegistro*>::iterator it = outList.begin(); it != outList.end(); it++)
{
Incidente res = Incidente(*(Incidente*)(*it));
result.push_back(res);
cout << res.ToString() << endl;
delete *it;
*it = NULL;
}
outList.clear();
return result;
}
return std::list<Incidente>();
}
bool IndiceDatos::InsertarIncidente(Incidente incidente)
{
return this->m_arbolBKD->InsertarRegistro(incidente);
}
bool IndiceDatos::ModificarIncidente(Incidente incidente)
{
return this->m_arbolBKD->ModificarRegistro(incidente);
}
bool IndiceDatos::EliminarIncidente(int formacion)
{
ClaveInt clave = ClaveInt(formacion);
return this->m_arbolBKD->EliminarRegistro(clave);
}