]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/ReaderEnvironment_Txx.h
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / ReaderEnvironment_Txx.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 // SYSTEM INCLUDES
28
29
30 // PROJECT INCLUDES
31
32
33 // LOCAL INCLUDES
34
35 // FORWARD REFERENCES
36
37 //NAMESPACE                                     
38
39 #include <cstdlib>
40
41
42                                         //====== LIFECYCLE ========
43                                         template<class T>
44                                         ReaderEnvironment<T>::ReaderEnvironment(std::string nameConfigurationFile,std::map<std::string,T>* things)
45                                                 {
46                                                         this->nameConfigurationFile=nameConfigurationFile;
47                                                         this->things=things;
48                                                         this->instantHandler=NULL;
49                                                         this->nameOtherConceptsFile = nameOtherConceptsFile;
50                                                         this->environment= new SomeEnvironment<T>();
51                                                         //constants
52                                                         NUMCONCEPTS="numConcepts";
53                                                         CONCEPT="concept";
54                                                         OBJECT="object";
55                                                         NUMOBJECTS="numObjects";
56                                                         NAME="name";
57                                                         SIZE="size";
58                                                         PATH="path";
59                                                         INSTANT="instant";
60                                                         NUMINSTANTS="numInstants";
61                                                         RANGE="r";
62                                                         COMMENT="#";
63                                                         EQUAL="=";
64                                                         POINT=".";
65                                                         ALL="all";
66                                                         nameOtherConceptsFile = "";
67                                                         numberOfConcepts = 0;
68
69                                                         //build the environment
70                                                         buildEnvironment();
71                                                 }
72                                         template<class T>
73                                         ReaderEnvironment<T>::ReaderEnvironment(std::string nameConceptFile,std::string nameObjectFile,std::map<std::string,T>* things)
74                                                 {
75                                                         this->nameConceptFile=nameConceptFile;
76                                                         this->nameObjectFile=nameObjectFile;
77
78                                                         this->things=things;
79                                                         this->nameOtherConceptsFile = nameOtherConceptsFile;
80                                                         this->environment= new SomeEnvironment<T>();
81                                                         //constants
82                                                         NUMCONCEPTS="numConcepts";
83                                                         CONCEPT="concept";
84                                                         OBJECT="object";
85                                                         NUMOBJECTS="numObjects";
86                                                         NAME="name";
87                                                         SIZE="size";
88                                                         PATH="path";
89                                                         INSTANT="instant";
90                                                         NUMINSTANTS="numInstants";
91                                                         RANGE="r";
92                                                         COMMENT="#";
93                                                         EQUAL="=";
94                                                         POINT=".";
95                                                         ALL="all";
96                                                         nameOtherConceptsFile = "";
97                                                         numberOfConcepts = 0;
98                                                         //build the environment
99                                                         buildEnvironment();
100
101                                                 }
102                                         template<class T>
103                                         ReaderEnvironment<T> :: ReaderEnvironment(std::string nameOtherConceptsFile, std::string nameConceptFile,std::string nameObjectFile, std::map<std::string,T>* things)
104                                                 {
105                                                         this->nameConceptFile=nameConceptFile;
106                                                         this->nameObjectFile=nameObjectFile;
107                                                         this->nameOtherConceptsFile = nameOtherConceptsFile;
108                                                         this->things=things;
109                                                         this->environment= new SomeEnvironment<T>();
110                                                         //constants
111                                                         NUMCONCEPTS="numConcepts";
112                                                         CONCEPT="concept";
113                                                         OBJECT="object";
114                                                         NUMOBJECTS="numObjects";
115                                                         NAME="name";
116                                                         SIZE="size";
117                                                         PATH="path";
118                                                         INSTANT="instant";
119                                                         NUMINSTANTS="numInstants";
120                                                         RANGE="r";
121                                                         COMMENT="#";
122                                                         EQUAL="=";
123                                                         POINT=".";
124                                                         ALL="all";                              
125                                                         numberOfConcepts = 0;
126                                                         //build the environment
127                                                         buildEnvironment();
128                                                 }
129                                         template<class T>
130                                         ReaderEnvironment<T>::~ReaderEnvironment()
131                                                 {       
132                                                         //deletes the things
133                                                         things->clear();
134                                                         if(things) delete this->things;
135                                                         nameConceptFile.clear();
136                                                         nameConfigurationFile.clear();
137                                                         nameObjectFile.clear();
138                                                         dataInFile.clear();
139                                                         nameOtherConceptsFile.clear();
140                                                         if(instantHandler) delete instantHandler;
141                                                         
142                                                 }
143                                                 
144                                         //====== OPERATIONS =======
145                                         /*
146                                         * @return environment builded
147                                         */
148                                         template<class T>
149                                         SomeEnvironment<T>* ReaderEnvironment<T>::getEnvironment()
150                                                 {
151                                                         return this->environment;
152                                                 }
153                                         /*
154                                         * build the environment
155                                         */
156                                         template<class T>
157                                         void ReaderEnvironment<T>::buildEnvironment()
158                                                 {
159                                                         
160                                                         //read the file
161                                                         if(!nameConfigurationFile.empty())
162                                                                 readFile(nameConfigurationFile);
163                                                         else
164                                                                 {
165                                                                         readFile(nameConceptFile);
166                                                                         readFile(nameObjectFile);
167                                                                         if(!nameOtherConceptsFile.empty())
168                                                                                 {
169                                                                                         readFile(nameOtherConceptsFile);
170                                                                                 }
171                                                                 }
172                                                         //adding the data of the concepts to the environment
173                                                     addConcepts();
174                                                         //setting the instant handler
175                                                         this->instantHandler=new InstantHandler<T>(environment);
176                                                         //adding the things to the  environment
177                                                         addThings();
178         
179                                                 }
180                                         //======== PRIVATE METHODS ==============
181                                         
182                                         /*
183                                         *       build the instant from the string readed in the file
184                                         *       @param instant, string with the description of the instant
185                                         *       @param nameObject, name of the object for wich we can add an instant or several instants
186                                         *       @return
187                                         *   TODO: when is an r(i j) and when the user doesnt write all the information 
188                                         *       of the instants it is considered like an all
189                                         *       for example, there is 3 concepts, the data complete for an instant is of size 3
190                                         *       but the user can write only an index of the first concept, the others is assumed
191                                         *       to be all, is like instant= i, then it is assumed like instant= i all all
192                                         */
193                                         
194                                                         
195                                         template<class T>
196                                         bool ReaderEnvironment<T>::addInstants(std::string nameObject,std::string instant)
197                                                 {
198                                                         
199                                                         int indexAll,numConcept,sizeConcept=-1,i,k=0;
200
201                                                         //copying the string of the instant
202                                                         std::string instantCopy=instant;
203                                                         //finding alls
204                                                         indexAll=instantCopy.find(ALL);
205                                                         std::string concept;
206                                                         char* indexConcept=(char*)malloc(sizeof(char));
207                                                         Instant* instantThing;
208                                                         //if have an all
209                                                         
210                                                         if(indexAll!=-1)        
211                                                         {                                       
212                                                                         std::string nameConcept;
213                                                                         //setting the first     instant of the handler, using all the all's defined in the string
214                                                                         while(indexAll!=-1)
215                                                                                 {
216                                                                                         //itoa(0,indexConcept,10); // itoa not ANSI
217                                                                                          sprintf(indexConcept, "%d", 0);
218                                                                                         instantCopy.replace(indexAll,ALL.size(),indexConcept);
219                                                                                         numConcept=getNumConcept(instantCopy,indexAll);
220                                                                                         getConceptName( nameConcept,numConcept);
221                                                                                         //setting the instanHandler
222                                                                                         instantHandler->addConceptToHandled(nameConcept,2,k);
223                                                                                         k++;
224                                                                                         nameConcept.clear();
225                                                                                         indexAll=instantCopy.find(ALL);
226                                                                                 }
227                                                                         
228                                                                         
229                                                                         //starting instant
230                                                                         instantThing=getInstant(instantCopy);
231                                                                         //adding to the environment
232                                                                         if(instantThing)
233                                                                         {
234                                                                                 if(environment->getNumberOfConcepts()== instantThing->getSize())
235                                                                                         {
236                                                                                                 environment->addInstantToThing(nameObject,instantThing);
237                                                                                                 //starting the  actual instant
238                                                                                                 instantHandler->setActualInstant(instantThing);
239                                                                                         }
240                                                                                 //else THROW EXCEPTION
241                                                                         }
242                                                                         //else THROW AN EXCEPTION
243                                                                         //deleting memory
244                                                                         delete instantThing;
245                                                                         //calculatig the number of instants
246                                                                         
247                                                                         int numInstants=instantHandler->getNumOfInstants();
248                                                                         
249                                                                         //calculating all the instants
250                                                                         for(i=1;i<numInstants;i++)
251                                                                                 {
252                                                                                         instantHandler->nextInstant();
253                                                                                         instantThing=instantHandler->getActualInstant();
254                                                                                         //borrame
255                                                                                         int sizeI=instantThing->getSize();
256                                                                                         for(int j=0;j<sizeI;j++)
257                                                                                                 int q=instantThing->getIndexInConcept(j);
258                                                                                         //
259                                                                                         environment->addInstantToThing(nameObject,instantThing);
260                                                                                 }
261                                                         }
262                                                         
263                                                         //doesnt have an all
264                                                         else
265                                                                 {
266                                                                         instantThing=getInstant(instantCopy);
267                                                                         if(instantThing)
268                                                                         {
269                                                                                 environment->addInstantToThing(nameObject,instantThing);
270                                                                                 delete instantThing;
271                                                                         }
272                                                                         
273                                                                         //else throw an exception
274                                                                         
275                                                                 }
276                                                         return true;
277                                                                                                         
278                                                 }
279                                         
280                                         /*
281                                         *       Returns the name of the concept in the concepts defined given the number 
282                                         *       of the concept in the instant
283                                         *       @param nameConcept, string where is going to be load the name of the concept
284                                         *       @param numConcept, number of the concept in the instant for which we are looking
285                                         *       for the name
286                                         */
287                                         template<class T>
288                                         void  ReaderEnvironment<T>::getConceptName(std::string& nameConcept,int numConcept)
289                                                 {
290                                                         int ncs,conceptIndexInEnvironment,i;
291                                                         
292                                                         //getting the names of the concept defined
293                                                         std::vector<std::string> nameConcepts;
294                                                         environment->getConceptsNames(nameConcepts);
295                                                         //name of the concept i
296                                                         std::string nameConcepti;
297                                                         ncs=nameConcepts.size();
298                                                         bool isConcept=false;
299                                                         for(i=0;i< ncs && !isConcept;i++)
300                                                                 {                                                                                       
301                                                                         nameConcepti=nameConcepts[i];
302                                                                         conceptIndexInEnvironment=environment->getIndexConcept(nameConcepti);
303                                                                         if(conceptIndexInEnvironment==numConcept)
304                                                                                 isConcept=true;
305                                                                         else    
306                                                                                 nameConcepti.clear();
307                                                                 }
308                                                         if(isConcept)
309                                                                 nameConcept=nameConcepti;
310                                                         nameConcepti.clear();
311                                                 }
312                                 
313                                         /*
314                                         *       Returns the number of the concept in the instant string read
315                                         *       @param instant,instant where we are going to search the number of the
316                                         *       concept that is in the position given
317                                         *       @param position, position of the concept (string position) for which we want the number in the instant given
318                                         *       @return the number of concept in the instant
319                                         */
320                                         template<class T>
321                                         int ReaderEnvironment<T>::getNumConcept(std::string& instant,int position )
322                                                 {
323                                                         int splitIndex,counter=0;
324                                                         splitIndex=instant.rfind(" ",position);
325                                                         while(splitIndex>=0)
326                                                                 {
327                                                                         counter++;
328                                                                         if(splitIndex>0)
329                                                                                 splitIndex=instant.rfind(" ",splitIndex-1);
330                                                                         if(splitIndex==0)
331                                                                                 splitIndex=-1;
332                                                                 }
333                                                         return counter;
334                                                 }
335                                 
336                                         /*
337                                         *       Returns the instant object of the instant string given
338                                         *       1 1 1 1 and returns an instant object (1,1,1,1)
339                                         *       @param instant, instant for which  we want to construct an Instant object
340                                         *       @return an Instant's object
341                                         *       TODO validation of  indexes in instant
342                                         */
343                                         template<class T>
344                                         Instant* ReaderEnvironment<T>:: getInstant(std::string instant)
345                                                 {
346                                                         int value,splitIndex;
347                                                         //getting the names of the concept defined
348                                                         std::vector<std::string> nameConcepts;
349                                                         environment->getConceptsNames(nameConcepts);
350                                                         //instant vector
351                                                         std::vector<int>* instantVector=new std::vector<int>();
352                                                         
353                                                         std::string concept;
354                                                         splitIndex=instant.find(" ");
355                                                         bool stop=false;
356                                                         int k=0;
357                                                         bool isValid= true;
358                                                         while(!stop && isValid)
359                                                                 {
360                                                                         if(splitIndex==-1)
361                                                                                 stop=true;
362                                                                         
363                                                                         concept=instant.substr(0,splitIndex);
364                                                                         instant.erase(0,splitIndex+1);                                                                  
365                                                                         value=atoi(concept.c_str());
366                                                                         isValid=environment->isValidIndex(value,k);
367                                                                         if(isValid)
368                                                                                 instantVector->push_back(value);
369                                                                         splitIndex=instant.find(" ");
370                                                                         k++;
371                                                                 }
372                                                         Instant* instantThing;
373                                                         if(stop)        
374                                                                 {
375                                                                         instantThing= new Instant(instantVector);
376                                                                         delete instantVector;
377                                                                 }
378                                                         else
379                                                                  instantThing=NULL;
380                                                         return instantThing;
381                                                 }                       
382
383                                         /*
384                                         *       add the instants defined in the file for the name of the
385                                         *       object given
386                                         *       @param nameObject, name of the object for which we want to search
387                                         *       its instant
388                                         */
389                                         template<class T>
390                                                 bool ReaderEnvironment<T>::addInstantToThing(std::string nameObject,std::string index)
391                                                 {
392                                                         int numInstants,i;
393                                                         std::map<std::string,std::string>::iterator iteratorData;
394                                                         bool added=true;
395                                                         
396                                                         //getting the number of instants for the object given
397                                                         
398                                                         std::string s(OBJECT + index + POINT + NUMINSTANTS);
399                                                         iteratorData=dataInFile.find(s);
400                                                         
401                                                         if(iteratorData!=dataInFile.end())
402                                                                 {
403                                                                         std::string numIns=iteratorData->second;
404                                                                         numInstants=atoi(numIns.c_str());
405                                                                         numIns.clear();
406                                                                 }
407                                                         //else throw exception
408                                                         //getting the instants
409                                                         s.clear();
410                                                         std::string instant;
411                                                                 
412                                                         //finding the number of decimals places
413                                                         int num=getNumberOfDecimalPlaces(numInstants);
414                                                         char* indexi=(char*)malloc(sizeof(char)*(num+1));
415                                                         //std::string indexiStr;
416                                                         for(i=1;i<=numInstants && added;i++)
417                                                                 {
418                                                                         //itoa(i,indexi,10);
419                            sprintf(indexi, "%d", i);
420                                                                         //indexiStr=indexi;
421                                                                         s=OBJECT+index+POINT+INSTANT+indexi;
422                                                                         iteratorData=dataInFile.find(s);
423                                                                         if(iteratorData!=dataInFile.end())
424                                                                                 {
425                                                                                         instant=iteratorData->second;
426                                                                                         addInstants(nameObject,instant);
427                                                                                         
428                                                                                 }
429                                                                         s.clear();
430                                                                         instant.clear();
431                                                                 }
432                                                         free(indexi);
433                                                         if(i==numInstants+1)    
434                                                                 return true;
435                                                         else
436                                                                         return false;
437
438                                                 }
439
440                                         /*
441                                         * adds the things to the  environment
442                                         */
443                                         template<class T>
444                                         bool ReaderEnvironment<T>::addThings()
445                                                 {
446                                                         int numObjects=0,j=0;
447                                                         bool addedInstants=true;
448                                                         typename std::map<std::string,std::string>::iterator iteratorData;
449                                                         typename std::map<std::string,T>::iterator iteratorThings;
450                                                         //getting the number of objects
451                                                         iteratorData=dataInFile.find(NUMOBJECTS);
452                                                         if(iteratorData!=dataInFile.end())
453                                                                 {
454                                                                         std::string numObj=iteratorData->second;
455                                                                         numObjects=atoi(numObj.c_str());
456                                                                         numObj.clear();
457                                                                 }
458                                                         //finding the number of decimals places
459                                                         int num=getNumberOfDecimalPlaces(numObjects);
460                                                         //getting the objects if does  come like objects
461                                                         if(things)
462                                                                 {
463                                                                         
464                                                                         char* index= (char*)malloc(sizeof(char)*(num+1));
465                                                                         std::string objectData;
466                                                                         std::string nameObjecti;
467                                                                         for(j=1;j<=numObjects && addedInstants;j++)
468                                                                                 {
469                                                                                         //itoa(j,index,10);
470                                                                                         int num2=sprintf(index, "%d", j);
471                                                                                         objectData=OBJECT+index+POINT+NAME;
472                                                                                         iteratorData=dataInFile.find(objectData);
473                                                                                         if(iteratorData!=dataInFile.end())
474                                                                                                 {
475                                                                                                         nameObjecti=iteratorData->second;
476                                                                                                         iteratorThings=things->find(nameObjecti);
477                                                                                                         if(iteratorThings!=things->end())
478                                                                                                                 {
479                                                                                                                         environment->addThing(nameObjecti,iteratorThings->second);
480                                                                                                                         //indexS=index;
481                                                                                                                         addedInstants=addInstantToThing(nameObjecti,index);
482                                                                                                                 }
483                                                                                                         //throwException
484                                                                                                         //the names given en execution and of the file should be the same
485                                                                                                         //else
486                                                                                                 }
487                                                                                         objectData.clear();
488                                                                                 }
489                                                                         objectData.clear();
490                                                                         free(index);
491                                                                         if(j==numObjects+1)
492                                                                                 return true;
493
494                                                                         else 
495                                                                                 return false;
496                                                                                 
497                                                                 }
498                                                         //if we have to charge it from a file
499                                                         //if is like that we should ask  for the objecti.path
500                                                         //else
501
502                                                         return  false;
503                                                 }
504                                         
505                                         
506                                         
507                                         /*
508                                         * adds the concepts of the file to the environment
509                                         */
510                                         template<class T>
511                                         bool ReaderEnvironment<T>::addConcepts()
512                                                 {
513                                                         int numConcepts=0,i=0;
514                                                         std::map<std::string,std::string>::iterator iteratorData;
515                                                         //getting the number of concepts defined
516                                                         iteratorData=dataInFile.find(NUMCONCEPTS);
517                                                         if(iteratorData!=dataInFile.end())
518                                                                 {
519                                                                         std::string numberOfConcepts=iteratorData->second;
520                                                                         numConcepts=atoi(numberOfConcepts.c_str());
521                                                                 }       
522                                                         //finding the number of decimals places
523                                                         int num=getNumberOfDecimalPlaces(numConcepts);
524                                                         std::string conceptData;
525                                                         char* index=(char*)malloc(sizeof(char)*(num+1));
526                                                         std::string nameConcepti;
527                                                         std::string sizeConcepti;
528                                                         for(i=1;i<=numConcepts;i++)
529                                                                 {
530                                                                         
531                                                                         //itoa(i,index,10);
532                                                                         sprintf(index, "%d", i);
533                                                                         //finding the name
534                                                                         conceptData=CONCEPT+index+POINT+NAME;
535                                                                         iteratorData=dataInFile.find(conceptData);
536                                                                         if(iteratorData!=dataInFile.end())
537                                                                                 nameConcepti=iteratorData->second;
538                                                                         //finding the size
539                                                                         conceptData.clear();
540                                                                         conceptData=CONCEPT+index+POINT+SIZE;
541                                                                         iteratorData=dataInFile.find(conceptData);
542                                                                         if(iteratorData!=dataInFile.end())
543                                                                                 sizeConcepti=iteratorData->second;
544                                                                         //adding the concept
545                                                                         environment->addConcept(nameConcepti,atoi(sizeConcepti.c_str()));
546                                                                         conceptData.clear();
547                                                                         nameConcepti.clear();
548                                                                         sizeConcepti.clear();
549                                                                         
550                                                                 }
551                                                         
552                                                         free(index);
553                                                         if(i==numConcepts+1)
554                                                                         return true;
555                                                         else
556                                                                         return false;
557
558                                                         
559                                                 }
560                                         /*
561                                         * read the configuration file
562                                         */
563                                         template<class T>
564                                                 void ReaderEnvironment<T>::readFile(std::string nameFile)
565                                                 {
566                                                         bool readingOtherConcepts = nameFile.compare(this->nameOtherConceptsFile) == 0;
567                                                         bool readingConcepts = nameFile.compare(this->nameConceptFile) == 0 || readingOtherConcepts;
568                                                         bool findedConceptOcurrence = false;
569                                                         int posPoint=0;
570                                                         int conceptValue=0;
571                                                         //std::string conceptKeyPart = "";
572                                                         int pos;
573                                                         //reader of the file
574                                                         std::ifstream configFile;
575                                                         //each line of the file
576                                                         std::string line;
577                                                         //string of the data to save
578                                                         std::string data;
579                                                         //string with the  key of the map
580                                                         std::string key;
581                                                         //line size
582                                                         int lineSize=0;
583                                                         //opening the file
584                                                         
585                                                         if(nameFile.compare("")!=0)
586                                                                 {
587                                                                         configFile.open(nameFile.c_str());
588                                                                         if(!configFile.is_open())
589                                                                         {                                                                       
590                                                                                         //should throw an exception                                                             
591                                                                                         return ;
592                                                                         }
593                                                                         else
594                                                                                 {
595                                                                                 //THIS ONLY SAVES NUMBERS OF ONE DIGIT  
596                                                                                 //FIXME
597                                                                                 char* index= (char*)malloc(sizeof(char)*5);     
598                                                                                 char* dataString= (char*)malloc(sizeof(char)*10);       
599                                                                                 while(!configFile.eof())
600                                                                                         {
601                                                                                                         //line.clear();
602                                                                                                         std::getline(configFile,line);
603                                                                                                         cleanLine(line);
604                                                                                                         pos=line.find(EQUAL);
605                                                                                                         lineSize=line.size();
606                                                                                                         //if is not a comment
607                                                                                                         
608                                                                                                         int c=line.find(COMMENT);
609                                                                                                         if (c !=std::string::npos )
610                                                                                                                 findedConceptOcurrence = false;
611
612                                                                                                         else//if(c<0 && pos>=0)
613                                                                                                                 {
614                                                                                                                         data=line.substr(pos+1,lineSize);
615                                                                                                                         key=line.substr(0,pos);                                                                                                 
616                                                                                                                         if ( readingConcepts && (key.rfind( CONCEPT ))!=std::string::npos )
617                                                                                                                                 {                                                                                                               
618                                                                                                                                                 
619                                                                                                                                         if( (key.rfind( NAME ))!=std::string::npos )
620                                                                                                                                                 {
621                                                                                                                                                         if ( !findedConceptOcurrence )
622                                                                                                                                                         {
623                                                                                                                                                                 numberOfConcepts++;
624                                                                                                                                                                 findedConceptOcurrence = true;
625                                                                                                                                                                 //itoa(numberOfConcepts,index,10);
626                                                                                                                                                                 sprintf (index, "%d", numberOfConcepts);
627                                                                                                                                                         }
628                                                                                                                                                         if ( readingOtherConcepts )
629                                                                                                                                                                 key = CONCEPT + index + POINT + NAME;                                                                                                                                   
630                                                                                                                                                 }
631                                                                                                                                         else if ( (key.rfind( SIZE ))!=std::string::npos )
632                                                                                                                                                 {
633                                                                                                                                                         if ( !findedConceptOcurrence)
634                                                                                                                                                         {
635                                                                                                                                                                 numberOfConcepts++;
636                                                                                                                                                                 findedConceptOcurrence = true;
637                                                                                                                                                                 // itoa(numberOfConcepts,index,10);
638                                                                                                                                                                 sprintf(index, "%d", numberOfConcepts);
639                                                                                                                                                         }               
640                                                                                                                                                         if ( readingOtherConcepts )
641                                                                                                                                                                 key = CONCEPT + index + POINT + SIZE;
642                                                                                                                                                 }       
643                                                                                                                                         
644                                                                                                                                 }
645                                                                                                                         
646                                                                                                                         
647                                                                                                                         int antes = dataInFile.size();
648                                                                                                                         if(!key.empty())
649                                                                                                                         {
650                                                                                                                                 if( readingOtherConcepts && key.rfind(NUMCONCEPTS)!=std::string::npos )
651                                                                                                                                 {
652                                                                                                                                         int otherConceptsValue = atoi(data.c_str());
653                                                                                                                                         //itoa(numberOfConcepts+otherConceptsValue,dataString,10);
654                                                                                                                                         sprintf(dataString,"%d", numberOfConcepts+otherConceptsValue);
655                                                                                                                                         data = dataString;
656                                                                                                                                         std::map<std::string,std::string>::iterator iter = dataInFile.find(key);
657                                                                                                                                         dataInFile.erase(iter);                                                                                                                 
658                                                                                                                                 }
659                                                                                                                                 dataInFile.insert(std::pair<std::string,std::string>(key,data));
660                                                                                                                         }
661                                                                                                                         int despues = dataInFile.size();
662                                                                                                                         //cleaning the data and the key variables
663                                                                                                                         data.clear();
664                                                                                                                         key.clear();                                                                                                    
665                                                                                                                 }                                                       
666                                                                                                                 
667
668                                                                                         }
669                                                                                 free(index);
670                                                                                 free(dataString);
671                                                                                 configFile.close();
672                                                                         }                                                               
673                                                                 }
674                                                 }
675                                         /*
676                                         * Returns the number of decimals places of the number given
677                                         */
678                                         template<class T>
679                                         int ReaderEnvironment<T>::getNumberOfDecimalPlaces(int number)
680                                                 {
681                                                         int i=0;
682                                                         while(number>0)
683                                                                 {
684                                                                         number=number/10;
685                                                                         i++;
686                                                                 }
687                                                         if(i==0)
688                                                                 i=1;
689                                                         return i;
690
691                                                 }
692                                         /*
693                                         * Clean the line readed from the file
694                                         */
695                                         template<class T>
696                                         void  ReaderEnvironment<T>::cleanLine(std::string & line)
697                                                 {
698                                                         int pos1,pos2,size;
699                                                         pos1=line.find_first_not_of(" ");
700                                                         line.erase(0,pos1);
701                                                         pos2=line.find_last_not_of(" ");
702                                                         size=line.length();
703                                                         line.erase(pos2+1,size-1);
704                                                 }
705