-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelation.h
387 lines (372 loc) · 12.3 KB
/
relation.h
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*!
*@file relation.h
*@author Ngo Sy Toan
* @date June 2017
* @brief The relation file: contain all the description of a relation, couple and Relation Manager
*/
#ifndef RELATION_H
#define RELATION_H
#include "note.h"
#include "iterator.h"
#include <QString>
#include "exception.h"
/*!
* \brief The Couple class: contain 2 note linked together by a relation, with label
*/
class Couple {
/*!
* \brief note1: note from
*/
Note* note1;
/*!
* \brief note2: note to
*/
Note* note2;
/*!
* \brief label: label of the couple
*/
QString label;
public:
/*!
* \brief Couple: constructor of couple
* \param n1: note from
* \param n2: note to
* \param lb: label of the couple
* \details This couple indicates the relation from note 1 to note 2 if it is oriented otherwise the relation between note 1 and note 2
*/
Couple(Note* n1, Note* n2, QString& lb): note1(n1), note2(n2), label(lb) {}
/*!
* \brief getNote1: get the note 1 in the couple
* \return const Note&
*/
const Note& getNote1() const { return *note1; }
/*!
* \brief getNote2: get the note 1 in the couple
* \return const Note&
*/
const Note& getNote2() const { return *note2; }
/*!
* \brief getLabel: get the label of the couple
* \return const QString&
*/
const QString& getLabel() const {return label;}
/*!
* \brief setLabel: set the new label
* \param newLb: new label
*/
void setLabel(QString& newLb) {label = newLb;}
/*!
* \brief destructor of couple
*/
~Couple(){}
};
/*!
* \brief The Relation class is abstract, it contains couples and the orientation of the couples inside.
* \details There are RelationNormale and RelationPreexistence are inherit relation
*/
class Relation {
/*!
* \brief couples: table of couples
*/
Couple** couples;
/*!
* \brief nbCouples: number of couples in the table
*/
unsigned int nbCouples;
/*!
* \brief maxCouples: maximum couples can be contained in the table
*/
unsigned int maxCouples;
protected:
/*!
* \brief titre: titre of the relation
*/
QString titre;
/*!
* \brief description: description of the relation
*/
QString description;
/*!
* \brief orientee: true if orientee
*/
bool orientee;
public:
/*!
* \brief Relation: constructor of relation
* \param titr: titre of the relation
* \param desc: description of the relation
* \param orie: orientation of the relation
*/
Relation(const QString& titr, const QString& desc="", bool orie=true):
titre(titr), description(desc), nbCouples(0), maxCouples(0), orientee(orie){}
/*!
* \brief setTitre: set new titre
* \param newTitre: new titre of the relation
* \details class pure virtual
*/
virtual void setTitre(const QString& newTitre) = 0; //pure
/*!
* \brief setDescription: set new description
* \param newDescription: new description of the relation
* \details class pure virtual
*/
virtual void setDescription(const QString& newDescription) = 0; //pure
/*!
* \brief setOrientee: set new orientee
* \param boolVal: true if the relation is oriented
* \details class pure virtual
*/
virtual void setOrientee(bool boolVal) = 0; //pure
/*!
* \brief getTitre: get titre of relation
* \return const QString&
*/
const QString& getTitre() const {return titre;}
/*!
* \brief getDescription: get description of relation
* \return const QString&
*/
const QString& getDescription() const {return description;}
/*!
* \brief getOrientee: get orientee of relation
* \return bool
*/
bool getOrientee() const {return orientee;}
/*!
* \brief ajouterCouple: add new couple into relation
* \param newCouple: pointer to the new couple
*/
void ajouterCouple(Couple* newCouple);
/*!
* \brief supprimerCouple: delete the couple
* \param supCouple: pointer to the couple need to delete
*/
void supprimerCouple(Couple* supCouple);
/*!
* \brief ~Relation: destructor of relation
* \details Free the table couple, virtual function
*/
virtual ~Relation(){
for (unsigned int i=0; i < nbCouples; i++) delete couples[i];
delete[] couples;
}
//implement iterator
/*!
* \brief The iterator class: iterator of relation, iterate throught the table of couple
*/
class iterator: public Iterator<Couple>{
friend class Relation;
iterator(Couple** c): Iterator(c){}
};
/*!
* \brief begin: get the pointer to the beginning of the table of couple
* \return iterator
*/
iterator begin() {return iterator(couples);}
/*!
* \brief end: get the pointer to the end of the table of couple
* \return iterator
*/
iterator end() {return iterator(couples+nbCouples);}
};
/*!
* \brief The RelationNormale class: heritate of Relation class
* \details Normal relation which can be deleted and change titre, description and orientation
*/
class RelationNormale: public Relation{
public:
/*!
* \brief RelationNormale: constructor of RelationNormale
* \param titr: titre of RelationNormale
* \param desc: description of RelationNormale
* \param orie: orientation of RelationNormale, true if orientee
*/
RelationNormale(const QString& titr, const QString& desc, bool orie=true): Relation(titr, desc, orie){}
/*!
* \brief setTitre: set new titre to RelationNormale
* \param newTitre: new titre of RelationNormale
*/
void setTitre(const QString& newTitre) {titre = newTitre;}
/*!
* \brief setDescription: set new description to RelationNormale
* \param newDescription: new description of RelationNormale
*/
void setDescription(const QString& newDescription){description = newDescription;}
/*!
* \brief setOrientee: set new orientee to RelationNormale
* \param boolVal: true of orientee
*/
void setOrientee(bool boolVal){orientee = boolVal;}
};
/*!
* \brief The RelationPreexistente class: the Preexistence class, Reference
* \details Cannot delete this class, this class hold the first place in table of Relation in RelationManager, singleton
*/
class RelationPreexistente: public Relation{
/*!
* \brief setTitre: define the virtual function herited from Relation class
* \details it is in the private to prevent changing titre
*/
void setTitre(const QString&){}
/*!
* \brief setDescription: define the virtual function herited from Relation class
* \details it is in the private to prevent changing description
*/
void setDescription(const QString&){}
/*!
* \brief setOrientee: define the virtual function herited from Relation class
* \details it is in the private to prevent changing orientation
*/
void setOrientee(bool){}
/*!
* \brief instance_RelationPreexistente: instance of Singleton of RelationPreexistente
*/
static RelationPreexistente* instance_RelationPreexistente;
/*!
* \brief RelationPreexistente: constructor by recopy
* \param r: RelationPreexistence
* \details hide this function in private to prevent constructor by recopy
*/
RelationPreexistente(const RelationPreexistente& r);
/*!
* \brief ~RelationPreexistence: destructor, hide it because of Singleton
*/
~RelationPreexistente(){}
/*!
* \brief operator =: constructor by affectation
* \return RelationPreexistence&
* \details Private because Singleton
*/
RelationPreexistente& operator=(const RelationPreexistente&);
/*!
* \brief RelationPreexistente: constructor
*/
RelationPreexistente();
public:
/*!
* \brief getRelationPreexistente: get the RelationPreexistence
* \return the instance of RelationPreexistence
* \details contruct new instance if there is no instance, otherwise get the instance pointer
*/
static RelationPreexistente* getRelationPreexistente(){
if (!instance_RelationPreexistente) instance_RelationPreexistente = new RelationPreexistente;
return instance_RelationPreexistente;
}
static void libererRelationPreexistente(){
if (instance_RelationPreexistente){
delete instance_RelationPreexistente;
instance_RelationPreexistente = 0;
}
}
};
/*!
* \brief The RelationManager class: Relation Manager to manage Relation, Singleton
*/
class RelationManager{
/*!
* \brief relations: table of relations
* \details first relation in table is RelationPreexistence
*/
Relation** relations;
/*!
* \brief nbRelations: number of relations in the table
*/
unsigned int nbRelations;
/*!
* \brief maxRelations: maximum number of relations in the table
*/
unsigned int maxRelations;
/*!
* \brief instance_RelationManager: instance of RelationManager
* \details Private because Singleton
*/
static RelationManager* instance_RelationManager;
/*!
* \brief RelationManager: constructor by recopy of RelationManager
* \details Private because Singleton
*/
RelationManager(const RelationManager&){}
/*!
* \brief RelationManager: constructor of RelationManager
* \details Private because Singleton
*/
RelationManager();
/*!
* \brief operator =: constructor by affectation
* \return RelationManager&
* \details Private because of Singleton
*/
RelationManager& operator=(const RelationManager&);
public:
/*!
* \brief getRelationManager: get instance of RelationManager, contruct if there is no instance of RelationManager
* \return pointer to instance of RelationManager
*/
static RelationManager* getRelationManager(){
if (RelationManager::instance_RelationManager==nullptr){
RelationManager::instance_RelationManager = new RelationManager;
RelationPreexistente* RP = RelationPreexistente::getRelationPreexistente();
instance_RelationManager->ajouterRelation(RP);
}
return instance_RelationManager;
}
/*!
* \brief libererRelationManager: Free the instance of RelationManager
*/
static void libererRelationManager(){
if (RelationManager::instance_RelationManager!=nullptr){
delete RelationManager::instance_RelationManager;
}
RelationManager::instance_RelationManager=nullptr;
}
/*!
* \brief getRelationFromTitle: return pointer to relation from a titre
* \param titre: titre of the relation
* \return Relation*
*/
Relation* getRelationFromTitle(QString& title);
/*!
* \brief getNbRelations: get number of relations in RelationManager
* \return unsigned int
*/
unsigned int getNbRelations() {return nbRelations;}
/*!
* \brief ajouterRelation: add Relation to table of Relation in RelationManager
* \param newRelation: pointer to the newRelation
*/
void ajouterRelation(Relation* newRelation);
/*!
* \brief supprimerRelation: detete a Relation in RelationManager
* \param supprimerRelation: pointer to the Relation needed to delete
*/
void supprimerRelation(Relation* supprimerRelation);
//implement iterator
/*!
* \brief The iterator class: iterator through table of relations
*/
class iterator: public Iterator<Relation>{
friend class RelationManager;
iterator(Relation** c): Iterator(c){}
};
/*!
* \brief begin: return the pointer to the first position in the table
* \return iterator
*/
iterator begin() {return iterator(relations);}
/*!
* \brief end: return the pointer to the end position in the table
* \return iterator
*/
iterator end() {return iterator(relations+nbRelations);}
/*!
* \brief loadRelationManager: load .xml to RelationManager
* \param filename: file .xml to load
*/
void loadRelationManager(const QString & filename);
/*!
* \brief saveRelationManager: save RelationManager to .xml
* \param filename: save to file .xml
*/
void saveRelationManager(const QString & filename);
};
#endif // RELATION_H