]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/SomeEnvironment.h
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / SomeEnvironment.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27 //      MACRO
28
29 #ifndef __SOMEENVIRONMENT_H_INCLUDED__
30 #define  __SOMEENVIRONMENT_H_INCLUDED__
31
32 // SYSTEM INCLUDES
33
34         #include <iostream>
35         #include <map>
36         #include <vector>
37         #include <string>
38
39
40 // PROJECT INCLUDES
41
42
43 // LOCAL INCLUDES
44
45 #include "SomeThing.h"
46
47
48 // FORWARD REFERENCES
49
50 /*
51 *       COMMENT
52 *       @param
53 *       @return
54 */
55
56
57
58 template <class T>
59         
60 class SomeEnvironment
61         {
62                                 public:
63                                                 //====== LIFECYCLE ========
64                                                 SomeEnvironment();
65
66                                                 SomeEnvironment(std::map<std::string,int>* concepts,std::map< std::string,SomeThing<T> >* things);
67                                                 
68                                                 ~SomeEnvironment();
69                                                         
70                                                 //====== OPERATIONS =======
71                                                 /*
72                                                 *       Adds a thing to the program
73                                                 *       @param name: name of the thing
74                                                 *       @param thing: thing to be added
75                                                 *       @return true if the thing was succesfully added
76                                                 */
77                                                 
78
79                                                 bool addThing(std::string name,T thing);
80                                                         
81                                                 
82                                                 /*
83                                                 *       Add thing with the name given to the instant given
84                                                 *       PRECONDITION
85                                                 *       the thing that has that name IS ALREADY ADDED TO THE PROGRAM
86                                                 *       @param name: name of the EXISTANT thing
87                                                 *       @param instant: instant associated to the thing
88                                                 *       @return true if the thing was succesfully added
89                                                 */
90
91                                                 bool addInstantToThing(std::string name,Instant* instant);
92                                                         
93                                                 /*
94                                                 *       Add thing with the name given, and the data given in the instant given
95                                                 *       @param name: name of the thing
96                                                 *       @param thing: information of the thing to be added
97                                                 *       @param instant: instant associated to the thing
98                                                 *       @return true if the thing was succesfully added
99                                                 */
100
101                                                 bool addThingWithInstant(std::string name,T thing,Instant* instant);
102                                                         
103                                                 /*
104                                                 *       Add a concept to the environment
105                                                 *       @param name: name of the concept
106                                                 *       @param size: size of the concept, it means that its indexes are
107                                                 *                                distributed 0..size-1
108                                                 *       @return true if succesful, false otherwise
109                                                 */
110                                                 
111                                         
112                                                 bool addConcept(std::string name, int size);
113
114                                                 //bool addConceptToThing(std::string nameConcept,std::string nameThing,int indexInConcept);
115                                                         
116                                                 /*
117                                                 * Validate the index of a concept in an instant
118                                                 */
119                                                 bool isValidIndex(int index, int indexInInstant);
120
121                                                 //====== INQUIRY =========
122                                                 
123                                                 /*
124                                                 *       Get the things of that instant
125                                                 *       @param instant: the instant for wich we need to know its things
126                                                 *       @return thingsOfInstant: a vector with the pointers to the things
127                                                 *       of the instant asked
128                                                 */
129                                                 std::vector<T*>* getThings(Instant* instant);
130                                                 
131                                                 /*
132                                                 *       Returns the things with their names in the environment
133                                                 *       @param names, vector where is goint to be safe the names 
134                                                 *       of the things in the environment.
135                                                 *       @param things, vector where is going to be save the things
136                                                 *       @parama instant, instant for wich
137                                                 *       @return
138                                                 */
139                                                 void getThings(std::vector<std::string>& names,std::vector<T*>& thingsVector,Instant* instant);
140                                                 
141                                                 /*
142                                                 *       Returns the instants where the thing identified by the name
143                                                 *       it should appears
144                                                 *       @param nameThing, name of the thing in the environment
145                                                 *       @return instants of that thing
146                                                 *       NOTE SENDS THE POINT TO A COPY OF THE VECTORS OF INSTANTS
147                                                 */
148                                                 
149                                                 std::vector<Instant*>* getInstantsOfThing(std::string nameThing);
150
151                                                 /*
152                                                 *       Returns the instants define in the environment
153                                                 *       @return existing instants in the environment
154                                                 */
155                                                 
156                                                 std::vector<Instant*>* getExistingInstants();
157
158                                                 /*
159                                                 *       Returns the size of the concept identified by nameConcept
160                                                 *       @param nameConcept, name of the concept in the environment
161                                                 *       @return size, of the concept given
162                                                 */
163                                                 int getSizeConcept(std::string nameConcept);
164
165                                                 /*
166                                                 * returns the index of the  concept in the instants
167                                                 */
168                                                 int getIndexConcept(std::string nameConcept);
169                                         
170                                                 /*
171                                                 *       Give the names of the names defined
172                                                 *       @param nameConcepts, vector where is goin to be save the names of the concepts
173                                                 */
174                                                 void getConceptsNames(std::vector<std::string>& namesConcepts);
175
176                                                 /*
177                                                 *       Method that retorns the name of each concept and the size of it.
178                                                 *       @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts
179                                                 *       @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts
180                                                 */
181                                                 void getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect);
182                                         
183                                                 /*
184                                                 * returns all the things of the environment
185                                                 * @param vector where is going to be charge the things
186                                                 * PRECONDITION
187                                                 *  thingsVector is empty
188                                                 */
189                                                 void getThingsOfEnvironment(std::vector<T*>* thingsVector);
190
191                                                 /*
192                                                 * returns a pointer to the thing with the name given
193                                                 */
194                                                 T* getThingByName(std::string name);
195                                                 /*
196                                                 * returns the number of concepts defined
197                                                 */
198                                                 int getNumberOfConcepts();
199
200                                                 /*
201                                                 * Gets the number of things 
202                                                 * @return Returns the number of existing things in the environment
203                                                 */
204                                                 int getNumberOfThings ();
205
206                                                 //====== ACCESS ==========
207                                                 /*
208                                                 *       Remove a thing from all the instants, it means from the program
209                                                 *       @param name: name of the thing
210                                                 *       @return: true if the removed is succesful (false if the thing doesnt exist)
211                                                 */
212                                                 
213                                                 bool removeThing(std::string name);
214                                                         
215                                                 /*
216                                                 *       Removes the thing with the name given, from the instant
217                                                 *       given
218                                                 *       @param name: name of the thing
219                                                 *       @param Instant: Instant from which it will be removed
220                                                 *       @return true: if the removed is succesful (false if the thing doesn exist)
221                                                 */
222                                                 
223                                                 bool removeThingFromInstant(std::string name, Instant* instant);
224                                                         
225
226                                                 /*
227                                                 *       Remove Instant from the program, it means, that from all the
228                                                 *       somethings that have that instant, after call this method them 
229                                                 *       doesnt have that instant anymore
230                                                 *       @param instant: instant that is going to be removed
231                                                 *       @return true: if the removed is succesful (false other wise)
232                                                 */
233                                                 bool removeInstant(Instant* instant);
234                                                 
235
236                                                 /*
237                                                 *       TODO
238                                                 *       Change the instant (any index of any concept) for all the things
239                                                 *       that should be find in that instant
240                                                 *       @param indexInstant: index of the instant in the existing instants
241                                                 *       in the environment
242                                                 *       @param indexConcept: index of the concept in the instant to be changed
243                                                 *       @param indexInConcept: which value between 0-sizeConcept is going to be saved
244                                                 *       @return 
245                                                 */
246                                                 void changeInstantForAllThings(int indexInstant, int indexConcept, int indexInConcept);
247
248                                                 
249                                                 //void changeInstantOnlyForThing(std::string nameThing, Instant* instant, int indexConcept,);
250                                                 /*
251                                                 *       Remove a dimension from the environment
252                                                 *       THE REMOVE OF THE CONCEPT IS WHEN IS BEING DEFINED THE ENVIRONMENT ,NO IN
253                                                 *       EXECUTION
254                                                 *       PRECONDITION
255                                                 *       the name of the concept given is already added to the environment
256                                                 *       @param nameConcept, name of the concept to remove
257                                                 */
258                                                         
259                                                 bool removeConcept(std::string nameConcept);
260                                                 
261
262                                                 
263                                 private:
264                                         
265                                         //======= ATTRIBUTES=======
266                                         
267                                         /*
268                                         *       Concepts that was defined
269                                         *       Saving in like (nameConcept,sizeConcept), where the key 
270                                         *       is the name of the concept
271                                         */
272                                         
273                                         std::map<std::string,int>               concepts;
274                                         /*
275                                         *       The things that this concepts handle
276                                         *       EXAMPLE
277                                         *       in visualization the concepts handle actors, it means that 
278                                         *       the actor are them things, but things also store the thing's name
279                                         *       PRECONDITION
280                                         *       each thing has a unique name, and is stored like (nameThing,Thing)
281                                         *       where the key is the name of the thing
282                                         */
283                                 
284                                         std::map < std::string,SomeThing<T> >    things;
285                                         
286                                         /*
287                                         *       this is the things of the instant asked
288                                         *       use for returning the data
289                                         */
290                                         std::vector<T*> thingsOfInstant;
291                                         
292                                         /*
293                                         *       this vector saves the instants that
294                                         *       are defined in the Environment
295                                         */
296                                         std::vector<Instant*> existingInstants;
297
298                                         /*
299                                         * is the relation between the  the indexes of the instants and the 
300                                         * concepts in the environment
301                                         */
302                                         std::map<std::string,int> indexesConcepts;
303
304                                         //====== PRIVATE METHODS=========
305                                                 /*
306                                                 *       Checks if in the instant given the something given has it
307                                                 *       @param instant, instant to check
308                                                 *       @param something;, something to check in the instant
309                                                 *       @return
310                                                 */
311                                                 bool isInInstant(SomeThing<T>* something,Instant *instant);
312                                                 
313                                                 /*
314                                                 *       Remove the instant from the environment
315                                                 *       @param instant, to be erased
316                                                 *       @return
317                                                 */
318                                                 void removeInstantFromExistingInstants(Instant* instant);
319                                                 
320                                                 /*
321                                                 *       Adds an instant to the existing instants, verifying if
322                                                 *   the instant is already added
323                                                 *       @param instant, to be added
324                                                 *       @return the index of that instant in the existing instants in the 
325                                                 *       environment
326                                                 */
327                                                 int addInstant(Instant* instant);
328                                                 /*
329                                                 *       Return the index in the existing instants of the instant 
330                                                 *       that the user had given
331                                                 *       @param instant, instant for which we are looking the index in
332                                                 *       the  existings intants in the environment
333                                                 *       @return an index in (0,existingInstants.size()-1)
334                                                 */
335                                                 int getIndexInstantInExistingInstants(Instant* instant);
336                         
337
338                                         
339                                         
340                                         
341
342         };
343 //include the implementation of the template
344 #include "SomeEnvironment_Txx.h"
345 #endif