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