]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/SomeEnvironment_Txx.h
db1b11f126de2c100256c30b3fa3bef571334107
[creaEnvironment.git] / lib / kernel_Environment / SomeEnvironment_Txx.h
1
2 // SYSTEM INCLUDES
3
4 #include <map>
5
6 // PROJECT INCLUDES
7
8
9 // LOCAL INCLUDES
10
11
12
13 // FORWARD REFERENCES
14
15 //NAMESPACE
16
17                                         //====== LIFECYCLE ========
18                                                 template<class T>                       
19                                                 SomeEnvironment<T>::SomeEnvironment()
20                                                 {
21                                                 }
22                                                 template<class T>       
23                                                 SomeEnvironment<T>::SomeEnvironment(std::map<std::string,int>* concepts,std::map< std::string,SomeThing<T> >* things)
24                                                 {
25                                                         this->concepts=concepts;
26                                                         this->things=things;
27                                                 }
28
29                                                 template<class T>       
30                                                 SomeEnvironment<T>::~SomeEnvironment()
31                                                         {
32                                                                 
33                                                                 int size,i;
34                                                                 
35                                                                 //deleting existing instants
36                                                                 size=existingInstants.size();
37                                                                 for(i=0;i<size;i++)
38                                                                         delete existingInstants[i];
39                                                                 existingInstants.clear();
40                                                                 //deleting concepts     
41                                                                 concepts.clear();
42                                                                 //deleting things
43                                                                 things.clear();
44                                                                 //indexes of concept
45                                                                 indexesConcepts.clear();
46                                                                 //things of instant
47                                                                 thingsOfInstant.clear();
48                                                         }
49                                         
50                                                 //====== OPERATIONS =======
51                                                 /*
52                                                 *       Adds a thing to the program
53                                                 *       @param name: name of the thing
54                                                 *       @param thing: thing to be added
55                                                 *       @return true if the thing was succesfully added
56                                                 */
57                                                 
58                                                 template<class T>       
59                                                 bool SomeEnvironment<T>:: addThing(std::string name,T thing)
60                                                         {
61                                                                 SomeThing<T> something (name);
62                                                                 something.setThing(thing);
63                                                                 things.insert(std::pair < std::string, SomeThing<T> >(name,something));
64                                                                 return true;
65
66                                                         }
67                                                 
68                                                 /*
69                                                 *       Add thing with the name given to the instant given
70                                                 *       PRECONDITION
71                                                 *       the thing that has that name IS ALREADY ADDED TO THE PROGRAM
72                                                 *       @param name: name of the EXISTANT thing
73                                                 *       @param instant: instant associated to the thing
74                                                 *       @return true if the thing was succesfully added
75                                                 */
76                                                 template<class T>       
77                                                 bool SomeEnvironment<T>::addInstantToThing(std::string name,Instant* instant)
78                                                         {
79                                                                 typename std::map< std::string,SomeThing<T> >::iterator thingsIterator;
80                                                                 thingsIterator=things.find(name);
81                                                                 if(thingsIterator != things.end())
82                                                                 {                                       
83                                                                         
84                                                                         
85                                                                          SomeThing<T>* something=&thingsIterator->second;
86                                                                         //getting the address of the instant added to the environment
87                                                                         // in the existing instants; EVERYTHING IS HANDLED INSIDE
88                                                                         
89                                                                          //saving instants
90                                                                          int indexInstantInside=addInstant(instant);
91                                                                          //borrame
92                                                                          //int indexInstantInside=getIndexInstantInExistingInstants(instant);
93                                                                          Instant* instantInExistingInstants=NULL;
94                                                                          if(indexInstantInside!=-1)
95                                                                                  {
96                                                                                         instantInExistingInstants=existingInstants[indexInstantInside];
97                                                                                         something->addInstant(instantInExistingInstants);
98                                                                                         return true;
99                                                                                  }
100                                                                          return false;
101                                                                         
102                                                                 }
103                                                                 return false;
104                                                         }
105                                                 /*
106                                                 *       Add thing with the name given, and the data given in the instant given
107                                                 *       @param name: name of the thing
108                                                 *       @param thing: information of the thing to be added
109                                                 *       @param instant: instant associated to the thing
110                                                 *       @return true if the thing was succesfully added
111                                                 */
112                                                 template<class T>       
113                                                 bool SomeEnvironment<T>::addThingWithInstant(std::string name,T thing,Instant* instant)
114                                                         {
115                                                                 SomeThing<T> something(name);
116                                                                 something.setThing(thing);
117                                                                 //saving instants
118                                                                 int indexInstantInside=addInstant(instant);
119                                                                 //borrame
120                                                                 //int indexInstantInside=getIndexInstantInExistingInstants(instant);
121                                                                 if(indexInstantInside!=-1)      
122                                                                  {
123                                                                         Instant* instantInExistingInstants = existingInstants[indexInstantInside];
124                                                                         something.addInstant(instantInExistingInstants);
125                                                                         things.insert(std::pair< std::string, SomeThing<T> >(name,something));
126                                                                         return true;
127                                                                  }
128                                                                 return false;
129                                                         }
130                                                 /*
131                                                 *       Add a concept to the environment
132                                                 *       @param name: name of the concept
133                                                 *       @param size: size of the concept, it means that its indexes are
134                                                 *                                distributed 0..size-1
135                                                 *       @return true if succesful, false otherwise
136                                                 */
137                                                 
138                                                 template<class T>       
139                                                 bool SomeEnvironment<T>::addConcept(std::string name, int size)
140                                                         {
141                                                                 concepts.insert(std::pair< std::string,int >(name,size));
142                                                                 int sizeMap=concepts.size();
143                                                                 indexesConcepts.insert(std::pair< std::string,int >(name,sizeMap-1));
144                                                                 return true;
145                                                         }
146                                                 /*
147                                                 * Validate the index of a concept in an instant
148                                                 */
149                                                 template<class T>
150                                                 bool SomeEnvironment<T>::isValidIndex(int index, int indexInInstant)
151                                                         {
152                                                                 std::map<std::string,int>::iterator conceptsIterator=concepts.begin();
153                                                                 std::map<std::string,int>::iterator conceptsIndexesIterator;
154                                                                 std::string conceptNamei;
155                                                                 int indexInInstantConcepti,size;
156                                                                 while(conceptsIterator!=concepts.end())
157                                                                         {
158                                                                                 conceptNamei=conceptsIterator->first;
159                                                                                 size=conceptsIterator->second;
160                                                                                 indexInInstantConcepti=getIndexConcept(conceptNamei);
161                                                                                 if(indexInInstantConcepti==indexInInstant)
162                                                                                         {
163                                                                                                 if(index<size)
164                                                                                                         return true;
165                                                                                                 else
166                                                                                                         return false;
167                                                                                         }
168                                                                                 conceptNamei.clear();
169                                                                                 conceptsIterator++;
170                                                                         }
171                                                                 return false;
172
173                                                         }
174                                                 
175                                                 //====== INQUIRY =========
176                                                 
177                                                 template<class T>       
178                                                 std::vector<T*>* SomeEnvironment<T>::getThings(Instant* instant)
179                                                         {
180                                                                 //cleaning things of instant
181                                                                 thingsOfInstant.clear();
182                                                                 //
183                                                                 
184                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
185                                                                 thingsIterator = things.begin();
186                                                                 //setting the environment instant
187                                                                 int indexInstantInside=getIndexInstantInExistingInstants(instant);
188                                                                 Instant* instantInExistingInstants=NULL;
189                                                                 if(indexInstantInside!=-1)
190                                                                         {       
191                                                                                 instantInExistingInstants=existingInstants[indexInstantInside];
192                                                                 
193                                                                                 while(thingsIterator!=things.end() && instantInExistingInstants)
194                                                                                         {
195                                                                                                 SomeThing<T>* something=&thingsIterator->second;
196                                                                                                 
197                                                                                                 bool isInInstantB=isInInstant(something,instantInExistingInstants);
198                                                                                                 if(isInInstantB)
199                                                                                                         {
200                                                                                                                 T* thing=something->getThing();
201                                                                                                                 thingsOfInstant.push_back(thing);
202                                                                                                                 
203                                                                                                         }       
204                                                                                                 thingsIterator++;
205                                                                                         }
206                                                                         }
207                                                                         
208                                                                 return &thingsOfInstant;
209
210                                                         }
211                                                 
212                                                 /*
213                                                 *       Returns the things with their names in the environment
214                                                 *       @param names, vector where is goint to be safe the names 
215                                                 *       of the things in the environment.
216                                                 *       @param things, vector where is going to be save the things
217                                                 *       @return
218                                                 */
219                                                 template<class T>       
220                                                 void SomeEnvironment<T>::getThings(std::vector< std::string >& names,std::vector< T* >& thingsVector, Instant* instant)
221                                                         {
222                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
223                                                                 thingsIterator=things.begin();
224                                                                 //setting the environment instant
225                                                                 int indexInstantInside=getIndexInstantInExistingInstants(instant);
226                                                                 Instant* instantInExistingInstants=NULL;
227                                                                 if(indexInstantInside!=-1)
228                                                                 {       
229                                                                         instantInExistingInstants=existingInstants[indexInstantInside];
230                                                                 
231                                                                         while(thingsIterator!=things.end() && instantInExistingInstants)
232                                                                                 {
233                                                                                         SomeThing<T>* something=&thingsIterator->second;
234                                                                                         bool isInInstantB=isInInstant(something,instantInExistingInstants);
235                                                                                         if(isInInstantB)
236                                                                                                 {
237                                                                                                         std::string nameThingInEnvironment=thingsIterator->first;
238                                                                                                         T* thing=something->getThing();
239                                                                                                         thingsVector.push_back(thing);
240                                                                                                         names.push_back(nameThingInEnvironment);
241                                                                                                         
242                                                                                                 }       
243                                                                                         thingsIterator++;
244                                                                                 }
245                                                                 }
246                                                         }
247                                                 /*
248                                                 *       Returns the instants where the thing identified by the name
249                                                 *       it should appears
250                                                 *       @param nameThing, name of the thing in the environment
251                                                 *       @return instants of that thing
252                                                 */
253                                                 template<class T>
254                                                 std::vector<Instant*>* SomeEnvironment<T>::getInstantsOfThing(std::string nameThing)
255                                                         {
256                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
257                                                                 thingsIterator=things.find(nameThing);
258                                                                 if(thingsIterator!=things.end())
259                                                                         {
260                                                                                 SomeThing<T>* something=&thingsIterator->second;
261                                                                                 return something->getInstants();
262                                                                         }
263                                                                 return (std::vector<Instant*>*)NULL;
264                                                         }
265
266                                                 /*
267                                                 *       Returns the instants define in the environment
268                                                 *       @return existing instants in the environment
269                                                 *       A POINTER TO THE  EXISTINGINSTANTS
270                                                 */
271                                                 template<class T>
272                                                 std::vector<Instant*>* SomeEnvironment<T>::getExistingInstants()
273                                                         {
274                                                                 return &existingInstants;
275                                                         }
276                                                 
277                                                 
278                                                 /*
279                                                 *       Returns the size of the concept identified by nameConcept
280                                                 *       @param nameConcept, name of the concept in the environment
281                                                 *       @return size, of the concept given or -1 if the concept doesnt
282                                                 *   exist
283                                                 */
284                                                 template<class T>
285                                                 int SomeEnvironment<T>::getSizeConcept(std::string nameConcept)
286                                                         {
287                                                                 std::map< std::string, int>::iterator conceptsIterator;
288                                                                 conceptsIterator= concepts.find(nameConcept);
289                                                                 if(conceptsIterator!= concepts.end())
290                                                                  {
291                                                                         return conceptsIterator->second;
292                                                                  }
293                                                                 else
294                                                                         return -1;
295                                                         }
296                                                 /*
297                                                 * returns the index of the  concept in the instants
298                                                 */
299                                                 template<class T>
300                                                 int SomeEnvironment<T>::getIndexConcept(std::string nameConcept)
301                                                         {
302                                                                 std::map< std::string, int>::iterator indexesConceptsIterator;
303                                                                 indexesConceptsIterator= indexesConcepts.find(nameConcept);
304                                                                 if(indexesConceptsIterator!= indexesConcepts.end())
305                                                                  {
306                                                                         return indexesConceptsIterator->second;
307                                                                  }
308                                                                 else
309                                                                         return -1;
310                                                         }
311                                                 /*
312                                                 *       NEW
313                                                 *       Give the names of the names defined
314                                                 *       @param nameConcepts, vector where is goin to be save the names of the concepts
315                                                 */
316                                                 template<class T>
317                                                 void SomeEnvironment<T>::getConceptsNames(std::vector<std::string>& namesConcepts)
318                                                         {
319                                                                 std::map<std::string,int>::iterator iteratorConcepts=concepts.begin();
320                                                                 std::string nameConcept;
321                                                                 while(iteratorConcepts!=concepts.end())
322                                                                         {
323                                                                                 nameConcept=iteratorConcepts->first;
324                                                                                 namesConcepts.push_back(nameConcept);
325                                                                                 iteratorConcepts++;
326                                                                         }
327                                                         }
328                                                 /*
329                                                 *       Method that retorns the name of each concept and the size of it.
330                                                 *       @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts
331                                                 *       @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts
332                                                 */
333                                                 template<class T>
334                                                 void SomeEnvironment<T> :: getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect)
335                                                 {
336                                                         std::map<std::string,int>::iterator iteratorConcepts=concepts.begin();                                                  
337                                                         while(iteratorConcepts!=concepts.end())
338                                                                 {
339                                                                         std::string aName = iteratorConcepts->first;
340                                                                         int aSize = iteratorConcepts->second;                                                                   
341                                                                         conceptNameVect.push_back( aName );
342                                                                         conceptSizeVect.push_back( aSize );
343                                                                         iteratorConcepts++;
344                                                                 }
345                                                 }
346
347                                                 /*
348                                                 * returns all the things of the environment
349                                                 */
350                                                 template<class T>
351                                                 void SomeEnvironment<T>::getThingsOfEnvironment(std::vector<T*>* thingsVector)
352                                                         {
353                                                                 typename std::map<std::string, SomeThing<T> >::iterator iteratorThings= things.begin();
354                                                                 thingsVector->clear();
355                                                                 while(iteratorThings!=things.end())
356                                                                         {
357                                                                                 SomeThing<T>* something=&iteratorThings->second;
358                                                                                 T* thing=something->getThing();
359                                                                                 thingsVector->push_back(thing);
360                                                                                 iteratorThings++;
361                                                                         }
362
363                                                         }
364                                                 /*
365                                                 * returns a pointer to the thing with the name given
366                                                 */
367                                                 template<class T>
368                                                 T* SomeEnvironment<T>::getThingByName(std::string name)
369                                                         {
370                                                                 T* thing=NULL;
371                                                                 typename std::map<std::string, SomeThing<T> >::iterator iteratorThings= things.find(name);
372                                                                 if(iteratorThings!=things.end())
373                                                                         {
374                                                                                 SomeThing<T>* something=&iteratorThings->second;
375                                                                                 thing=something->getThing();
376                                                                         }
377                                                                 return thing;
378                                                         }
379
380
381                                                 /*
382                                                 * returns the number of concepts defined
383                                                 */
384                                                 template<class T>       
385                                                 int SomeEnvironment<T>::getNumberOfConcepts()
386                                                         {
387                                                                 return this->concepts.size();
388                                                         }
389
390                                                         /*
391                                                 * Gets the number of things 
392                                                 * @return Returns the number of existing things in the environment
393                                                 */
394                                                 template<class T>
395                                                 int SomeEnvironment<T>::getNumberOfThings ()
396                                                         {
397                                                                 return things.size();
398                                                         }
399                                                         
400
401                                                 //====== ACCESS ==========
402                                                 /*
403                                                 *       Remove a thing from all the instants, it means from the program
404                                                 *       @param name: name of the thing
405                                                 *       @return: true if the removed is succesful (false if the thing doesn exist)
406                                                 */
407                                                 template<class T>       
408                                                 bool SomeEnvironment<T>::removeThing(std::string name)
409                                                         {
410                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
411                                                                 thingsIterator=things.find(name);
412                                                                 if(thingsIterator!=things.end())
413                                                                         {
414                                                                                 things.erase(thingsIterator);
415                                                                                 return true;
416                                                                         }
417                                                                 return false;
418                                                         }
419                                                 /*
420                                                 *       Removes the thing with the name given, from the instant
421                                                 *       given
422                                                 *       @param name: name of the thing
423                                                 *       @param Instant: Instant from which it will be removed
424                                                 *       @return true: if the removed is succesful (false if the thing doesn exist)
425                                                 */
426                                                 template<class T>       
427                                                 bool SomeEnvironment<T>::removeThingFromInstant(std::string name, Instant* instant)
428                                                         {
429                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
430                                                                 thingsIterator=things.find(name);
431                                                                 //setting the environment instant
432                                                                 int indexInstantInside=getIndexInstantInExistingInstants(instant);
433                                                                 Instant* instantInExistingInstants=NULL;
434                                                                 if(indexInstantInside!=-1)
435                                                                         instantInExistingInstants=existingInstants[indexInstantInside];
436                                                                                 
437                                                                 if(thingsIterator!=things.end() && instantInExistingInstants)
438                                                                         {
439                                                                                 SomeThing<T>* something=&thingsIterator->second;
440                                                                                 
441                                                                                 bool isInInstantB=isInInstant(something,instantInExistingInstants);
442                                                                                 if(isInInstantB)
443                                                                                         {
444                                                                                                 something->removeInstant(instant);
445                                                                                                 return true;
446                                                                                         }
447                                                                         }
448                                                                 return false;
449                                                         }
450
451                                                 /*
452                                                 *       Remove Instant from the program, it means, that from all the
453                                                 *       somethings that have that instant, after call this method them 
454                                                 *       doesnt have that instant anymore
455                                                 *       @param instant: instant that is going to be removed
456                                                 *       @return true: if the removed is succesful (false other wise)
457                                                 */
458                                                 template<class T>       
459                                                 bool SomeEnvironment<T>::removeInstant(Instant* instant)
460                                                         {
461                                                                 typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
462                                                                 thingsIterator=things.begin();
463                                                                 bool ok=false;
464                                                                                                                                                         
465                                                                 //setting the environment instant
466                                                                 int indexInstantInside=getIndexInstantInExistingInstants(instant);
467                                                                 Instant* instantInExistingInstants=NULL;
468                                                                 if(indexInstantInside!=-1)
469                                                                         instantInExistingInstants=existingInstants[indexInstantInside];
470                                                                 
471                                                                 while(thingsIterator!=things.end() && instantInExistingInstants)
472                                                                         {
473                                                                                 SomeThing<T>* something=&thingsIterator->second;
474                                                                                 bool isInInstantB=isInInstant(something,instantInExistingInstants);
475                                                                                 if(isInInstantB)
476                                                                                                 ok = something->removeInstant(instantInExistingInstants);
477                                                                                 thingsIterator++;
478                                                                                 
479                                                                         }
480                                                                 //removing from inside instants
481                                                                 removeInstantFromExistingInstants(instant);
482                                                                 return ok;
483                                                                         
484                                                         }
485                                                 /*
486                                                 *       Remove a dimension from the environment
487                                                 *       THE REMOVE OF THE CONCEPT IS WHEN IS BEING DEFINED THE ENVIRONMENT ,NO IN
488                                                 *       EXECUTION
489                                                 *       PRECONDITION
490                                                 *       the name of the concept given is already added to the environment
491                                                 *       @param nameConcept, name of the concept to remove
492                                                 */
493                                                 template<class T>               
494                                                 bool SomeEnvironment<T>::removeConcept(std::string nameConcept)
495                                                         {
496                                                                 std::map < std::string,int >::iterator conceptsIterator;
497                                                                 conceptsIterator=concepts.find(nameConcept);
498                                                                 if(conceptsIterator!=concepts.end())
499                                                                         {
500                                                                                 concepts.erase(conceptsIterator);
501                                                                                 return true;
502                                                                         }
503                                                                 return false;
504                                                         }
505                                                 //====== PRIVATE METHODS=========
506                                                 /*
507                                                 *       Checks if in the instant given the something given has it
508                                                 *       @param instant, instant to check
509                                                 *       @param something;, something to check in the instant
510                                                 *       @return
511                                                 */
512                                                 template<class T>       
513                                                 bool SomeEnvironment<T>::isInInstant(SomeThing<T>* something,Instant *instant)
514                                                 {
515                                                         //borrame
516                                                         for(int i=0;i<instant->getSize();i++)
517                                                                 int k=instant->getIndexInConcept(i);
518                                                         //                      
519                                                         int index=something->hasInstant(instant);
520                                                         if(index!=-1)
521                                                                 return true;
522                                                         else
523                                                                 return false;
524                                                 }
525                                                 /*
526                                                 *       Remove the instant from the environment
527                                                 *       @param instant, to be erased
528                                                 *       @return
529                                                 */
530                                                 template<class T>       
531                                                 void  SomeEnvironment<T>::removeInstantFromExistingInstants(Instant* instant)
532                                                         {
533                                                                 std::vector<Instant*>::iterator existingInstantsIterator=existingInstants.begin();
534                                                                 bool isEquals=false;
535                                                                 while(existingInstantsIterator!=existingInstants.end()&& !isEquals)
536                                                                         {
537                                                                                 isEquals=(*existingInstantsIterator)->isEquals(instant);
538                                                                                 if(isEquals)
539                                                                                         existingInstants.erase(existingInstantsIterator);
540                                                                                 existingInstantsIterator++;
541                                                                                 
542                                                                         }
543                                                                  
544                                                         }
545
546                                                 /*
547                                                 *       Adds an instant to the existing instants, verifying if
548                                                 *   the instant is already added
549                                                 *       @param instant, to be added
550                                                 *       @return
551                                                 */
552                                                 template<class T>       
553                                                 int SomeEnvironment<T>::addInstant(Instant* instant)
554                                                         {
555                                                                 std::vector<Instant*>::iterator existingInstantsIterator=existingInstants.begin();
556                                                                 int i=0;
557                                                                 bool isEquals=false;
558                                                                 while(existingInstantsIterator!=existingInstants.end() && !isEquals)
559                                                                         {
560                                                                                 Instant* existingInstant=*existingInstantsIterator;
561                                                                                 //borrame
562                                                                                 int sizeI=existingInstant->getSize();
563                                                                                 for(int k=0;k<sizeI;k++)
564                                                                                         int r=existingInstant->getIndexInConcept(k);
565                                                                                 //
566                                                                                 isEquals=existingInstant->isEquals(instant);
567                                                                                 existingInstantsIterator++;
568                                                                                 if(!isEquals)
569                                                                                         i++;
570                                                                                 
571                                                                         }
572                                                                 if(!isEquals)
573                                                                         {
574                                                                                 //copying the instant's information
575                                                                         std::vector<int>* instantVector=new std::vector<int>();
576                                                                                 int sizeInstant=instant->getSize();
577                                                                                 int k;
578                                                                                 for(k=0;k<sizeInstant;k++)
579                                                                                         {
580                                                                                                 int d=instant->getIndexInConcept(k);
581                                                                                                 instantVector->push_back(d);
582                                                                                         }
583                                                                                 //
584                                                                                 //saving the instant given in the handler
585                                                                                 Instant* instantToAdded= new Instant(instantVector);
586                                                                                 existingInstants.push_back(instantToAdded);
587                                                                                 i=existingInstants.size()-1;
588                                                                         }
589                                                                 return i;
590                                                         }
591                                                 /*
592                                                 *       Return the index in the existing instants of the instant 
593                                                 *       that the user had given
594                                                 *       @param instant, instant for which we are looking the index in
595                                                 *       the  existings intants in the environment
596                                                 *       @return an index in (0,existingInstants.size()-1)or -1 if the instant hasnt
597                                                 *       being defined
598                                                 */
599                                                 template<class T>       
600                                                 int SomeEnvironment<T>::getIndexInstantInExistingInstants(Instant* instant)
601                                                         {
602                                                                 std::vector<Instant*>::iterator existingInstantsIterator=existingInstants.begin();
603                                                                 int i=0;
604                                                                 bool isEquals=false;
605                                                                 while(existingInstantsIterator!=existingInstants.end() && !isEquals)
606                                                                         {
607                                                                                 isEquals=(*existingInstantsIterator)->isEquals(instant);
608                                                                                 existingInstantsIterator++;
609                                                                                 if(!isEquals)
610                                                                                         i++;
611                                                                                 
612                                                                         }
613                                                                 if(!isEquals)
614                                                                                 return -1;
615                                                                 else
616                                                                                 return i;
617                                                         }
618                      
619