-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexto.cpp
163 lines (137 loc) · 4.3 KB
/
Texto.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/************************************************************************
Texto.cpp
**************************************************************************/
#include "Texto.h"
// Constructors/Destructors
//
Texto::Texto (const string nombre, const unsigned int tamano) {
this->id = 0;
this->nombre = nombre;
this->tamano = tamano;
this->comprimida = false;
this->particiones.clear();
}
Texto::Texto (const unsigned int id, const string nombre, const unsigned int tamano ) {
this->id = id;
this->nombre = nombre;
this->tamano = tamano;
this->comprimida = false;
this->particiones.clear();
}
Texto::~Texto ( ) {
this->eliminarListaParticiones();
}
string Texto::getNombre ( ) {
return this->nombre;
}
void Texto::setNombre (string nombre ) {
this->nombre = nombre;
}
unsigned int Texto::getNroParticiones ( ) {
return this->particiones.size();
}
unsigned int Texto::getCantidadParticionesOriginal(){
return this->cantidadParticionesOriginales;
}
void Texto::setCantidadParticionesOriginal(unsigned int cantidad){
this->cantidadParticionesOriginales = cantidad;
}
bool Texto::esValido(){
return (this->getNroParticiones() == this->getCantidadParticionesOriginal());
}
list<Almacenable *>* Texto::obtenerParticiones ( ) {
return (&this->particiones);
}
list<Almacenable*> Texto::obtenerCopiaParticiones ( ){
return this->particiones;
}
void Texto::setParticionesList (list<Almacenable*> lista){
this->eliminarListaParticiones();
this->particiones = lista;
}
void Texto::agregarParticion (Particion* particion ) {
this->particiones.push_back(particion);
}
void Texto ::agregarParticionInicio(Particion* particion){
this->particiones.push_front(particion);
}
bool Texto::eliminarParticion (unsigned int idParticion ){
list<Almacenable *>::iterator it = this->particiones.begin();
bool encontrado = false;
while ((!encontrado) && (it != this->particiones.end())){
if (((Particion*)*it)->getId() == idParticion){
delete (*it);
it = this->particiones.erase(it);
encontrado = true;
}
else
it++;
}
return encontrado;
}
Particion* Texto::obtenerParticion (unsigned int idParticion ) {
list<Almacenable *>::iterator it = this->particiones.begin();
Almacenable* encontrado = NULL;
while ((!encontrado) && (it != this->particiones.end())){
if (((Particion*)*it)->getId() == idParticion)
encontrado = *it;
it++;
}
return (Particion*)encontrado;
}
// private:
void Texto::eliminarListaParticiones(){
list<Almacenable *>::iterator it = this->particiones.begin();
while ( it != this->particiones.end()){
delete (*it);
it = this->particiones.erase(it);
}
}
bool Texto::usaPortador(unsigned int idImagen){
bool usa = false;
list<Almacenable*>::iterator it = this->particiones.begin();
while ((!usa) && (it != this->particiones.end())){
if (((Particion*)*it)->getIdImagen() == idImagen)
usa = true;
else
it++;
}
return usa;
}
void Texto::removerParticiones(unsigned int idImagen){
list<Almacenable *>::iterator it = this->particiones.begin();
while ( it != this->particiones.end()){
if (((Particion*)*it)->getIdImagen() == idImagen){
delete (*it);
it = this->particiones.erase(it);
}
else
it++;
}
}
list<Almacenable*> Texto::obtenerParticiones(const unsigned int idImagen){
list<Almacenable*>::iterator it = this->particiones.begin();
list<Almacenable*> resultado;
while ( it != this->particiones.end()){
if (((Particion*)*it)->getIdImagen() == idImagen)
resultado.push_back(*it);
it++;
}
return resultado;
}
/**
* Crea y devuelve una copia del texto
*/
Texto* Texto::copiar(){
Texto* texto = new Texto(this->id, this->nombre, this->tamano);
list<Almacenable*> particiones = this->obtenerCopiaParticiones();
list<Almacenable*>::iterator it = particiones.begin();
while (it != particiones.end()){
*it = ((Particion*)*it)->copiar();
it++;
}
texto->setParticionesList(particiones);
texto->setPersistido(this->esPersistido());
texto->setComprimida(this->comprimida);
return texto;
}