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