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