From: jean-pierre roux Date: Thu, 28 Jul 2011 09:52:11 +0000 (+0000) Subject: some more unused variables X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaEnvironment.git;a=commitdiff_plain;h=616ebd66c01c517fb21bd6966d3b749b657eec67 some more unused variables --- diff --git a/lib/kernel_Environment/SomeEnvironment_Txx.h b/lib/kernel_Environment/SomeEnvironment_Txx.h index db1b11f..aa3e992 100644 --- a/lib/kernel_Environment/SomeEnvironment_Txx.h +++ b/lib/kernel_Environment/SomeEnvironment_Txx.h @@ -14,606 +14,590 @@ //NAMESPACE - //====== LIFECYCLE ======== - template - SomeEnvironment::SomeEnvironment() - { - } - template - SomeEnvironment::SomeEnvironment(std::map* concepts,std::map< std::string,SomeThing >* things) - { - this->concepts=concepts; - this->things=things; - } + //====== LIFECYCLE ======== + template +SomeEnvironment::SomeEnvironment() +{ +} +template +SomeEnvironment::SomeEnvironment(std::map* concepts,std::map< std::string,SomeThing >* things) +{ + this->concepts=concepts; + this->things=things; +} - template - SomeEnvironment::~SomeEnvironment() - { - - int size,i; - - //deleting existing instants - size=existingInstants.size(); - for(i=0;i - bool SomeEnvironment:: addThing(std::string name,T thing) - { - SomeThing something (name); - something.setThing(thing); - things.insert(std::pair < std::string, SomeThing >(name,something)); - return true; +template +SomeEnvironment::~SomeEnvironment() + { + int size,i; + + //deleting existing instants + size=existingInstants.size(); + for(i=0;i - bool SomeEnvironment::addInstantToThing(std::string name,Instant* instant) - { - typename std::map< std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.find(name); - if(thingsIterator != things.end()) - { - - - SomeThing* something=&thingsIterator->second; - //getting the address of the instant added to the environment - // in the existing instants; EVERYTHING IS HANDLED INSIDE - - //saving instants - int indexInstantInside=addInstant(instant); - //borrame - //int indexInstantInside=getIndexInstantInExistingInstants(instant); - Instant* instantInExistingInstants=NULL; - if(indexInstantInside!=-1) - { - instantInExistingInstants=existingInstants[indexInstantInside]; - something->addInstant(instantInExistingInstants); - return true; - } - return false; - - } - return false; - } - /* - * Add thing with the name given, and the data given in the instant given - * @param name: name of the thing - * @param thing: information of the thing to be added - * @param instant: instant associated to the thing - * @return true if the thing was succesfully added - */ - template - bool SomeEnvironment::addThingWithInstant(std::string name,T thing,Instant* instant) - { - SomeThing something(name); - something.setThing(thing); - //saving instants - int indexInstantInside=addInstant(instant); - //borrame - //int indexInstantInside=getIndexInstantInExistingInstants(instant); - if(indexInstantInside!=-1) - { - Instant* instantInExistingInstants = existingInstants[indexInstantInside]; - something.addInstant(instantInExistingInstants); - things.insert(std::pair< std::string, SomeThing >(name,something)); - return true; - } - return false; - } - /* - * Add a concept to the environment - * @param name: name of the concept - * @param size: size of the concept, it means that its indexes are - * distributed 0..size-1 - * @return true if succesful, false otherwise - */ - - template - bool SomeEnvironment::addConcept(std::string name, int size) - { - concepts.insert(std::pair< std::string,int >(name,size)); - int sizeMap=concepts.size(); - indexesConcepts.insert(std::pair< std::string,int >(name,sizeMap-1)); - return true; - } - /* - * Validate the index of a concept in an instant - */ - template - bool SomeEnvironment::isValidIndex(int index, int indexInInstant) - { - std::map::iterator conceptsIterator=concepts.begin(); - std::map::iterator conceptsIndexesIterator; - std::string conceptNamei; - int indexInInstantConcepti,size; - while(conceptsIterator!=concepts.end()) - { - conceptNamei=conceptsIterator->first; - size=conceptsIterator->second; - indexInInstantConcepti=getIndexConcept(conceptNamei); - if(indexInInstantConcepti==indexInInstant) - { - if(index +bool SomeEnvironment:: addThing(std::string name,T thing) + { + SomeThing something (name); + something.setThing(thing); + things.insert(std::pair < std::string, SomeThing >(name,something)); + return true; + } - } - - //====== INQUIRY ========= - - template - std::vector* SomeEnvironment::getThings(Instant* instant) - { - //cleaning things of instant - thingsOfInstant.clear(); - // - - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator = things.begin(); - //setting the environment instant - int indexInstantInside=getIndexInstantInExistingInstants(instant); - Instant* instantInExistingInstants=NULL; - if(indexInstantInside!=-1) - { - instantInExistingInstants=existingInstants[indexInstantInside]; - - while(thingsIterator!=things.end() && instantInExistingInstants) - { - SomeThing* something=&thingsIterator->second; - - bool isInInstantB=isInInstant(something,instantInExistingInstants); - if(isInInstantB) - { - T* thing=something->getThing(); - thingsOfInstant.push_back(thing); - - } - thingsIterator++; - } - } - - return &thingsOfInstant; +/* +* Add thing with the name given to the instant given +* PRECONDITION +* the thing that has that name IS ALREADY ADDED TO THE PROGRAM +* @param name: name of the EXISTANT thing +* @param instant: instant associated to the thing +* @return true if the thing was succesfully added +*/ +template +bool SomeEnvironment::addInstantToThing(std::string name,Instant* instant) + { + typename std::map< std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + if(thingsIterator != things.end()) + { + SomeThing* something=&thingsIterator->second; + //getting the address of the instant added to the environment + // in the existing instants; EVERYTHING IS HANDLED INSIDE + + //saving instants + int indexInstantInside=addInstant(instant); + //borrame + //int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + something->addInstant(instantInExistingInstants); + return true; + } + return false; + } + return false; + } +/* +* Add thing with the name given, and the data given in the instant given +* @param name: name of the thing +* @param thing: information of the thing to be added +* @param instant: instant associated to the thing +* @return true if the thing was succesfully added +*/ +template +bool SomeEnvironment::addThingWithInstant(std::string name,T thing,Instant* instant) + { + SomeThing something(name); + something.setThing(thing); + //saving instants + int indexInstantInside=addInstant(instant); + //borrame + //int indexInstantInside=getIndexInstantInExistingInstants(instant); + if(indexInstantInside!=-1) + { + Instant* instantInExistingInstants = existingInstants[indexInstantInside]; + something.addInstant(instantInExistingInstants); + things.insert(std::pair< std::string, SomeThing >(name,something)); + return true; + } + return false; + } +/* +* Add a concept to the environment +* @param name: name of the concept +* @param size: size of the concept, it means that its indexes are +* distributed 0..size-1 +* @return true if succesful, false otherwise +*/ - } - - /* - * Returns the things with their names in the environment - * @param names, vector where is goint to be safe the names - * of the things in the environment. - * @param things, vector where is going to be save the things - * @return - */ - template - void SomeEnvironment::getThings(std::vector< std::string >& names,std::vector< T* >& thingsVector, Instant* instant) - { - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.begin(); - //setting the environment instant - int indexInstantInside=getIndexInstantInExistingInstants(instant); - Instant* instantInExistingInstants=NULL; - if(indexInstantInside!=-1) - { - instantInExistingInstants=existingInstants[indexInstantInside]; - - while(thingsIterator!=things.end() && instantInExistingInstants) - { - SomeThing* something=&thingsIterator->second; - bool isInInstantB=isInInstant(something,instantInExistingInstants); - if(isInInstantB) - { - std::string nameThingInEnvironment=thingsIterator->first; - T* thing=something->getThing(); - thingsVector.push_back(thing); - names.push_back(nameThingInEnvironment); - - } - thingsIterator++; - } - } - } - /* - * Returns the instants where the thing identified by the name - * it should appears - * @param nameThing, name of the thing in the environment - * @return instants of that thing - */ - template - std::vector* SomeEnvironment::getInstantsOfThing(std::string nameThing) - { - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.find(nameThing); - if(thingsIterator!=things.end()) - { - SomeThing* something=&thingsIterator->second; - return something->getInstants(); - } - return (std::vector*)NULL; - } +template +bool SomeEnvironment::addConcept(std::string name, int size) + { + concepts.insert(std::pair< std::string,int >(name,size)); + int sizeMap=concepts.size(); + indexesConcepts.insert(std::pair< std::string,int >(name,sizeMap-1)); + return true; + } +/* +* Validate the index of a concept in an instant +*/ +template +bool SomeEnvironment::isValidIndex(int index, int indexInInstant) + { + std::map::iterator conceptsIterator=concepts.begin(); + std::map::iterator conceptsIndexesIterator; + std::string conceptNamei; + int indexInInstantConcepti,size; + while(conceptsIterator!=concepts.end()) + { + conceptNamei=conceptsIterator->first; + size=conceptsIterator->second; + indexInInstantConcepti=getIndexConcept(conceptNamei); + if(indexInInstantConcepti==indexInInstant) + { + if(index - std::vector* SomeEnvironment::getExistingInstants() - { - return &existingInstants; - } - - - /* - * Returns the size of the concept identified by nameConcept - * @param nameConcept, name of the concept in the environment - * @return size, of the concept given or -1 if the concept doesnt - * exist - */ - template - int SomeEnvironment::getSizeConcept(std::string nameConcept) - { - std::map< std::string, int>::iterator conceptsIterator; - conceptsIterator= concepts.find(nameConcept); - if(conceptsIterator!= concepts.end()) - { - return conceptsIterator->second; - } - else - return -1; - } - /* - * returns the index of the concept in the instants - */ - template - int SomeEnvironment::getIndexConcept(std::string nameConcept) - { - std::map< std::string, int>::iterator indexesConceptsIterator; - indexesConceptsIterator= indexesConcepts.find(nameConcept); - if(indexesConceptsIterator!= indexesConcepts.end()) - { - return indexesConceptsIterator->second; - } - else - return -1; - } - /* - * NEW - * Give the names of the names defined - * @param nameConcepts, vector where is goin to be save the names of the concepts - */ - template - void SomeEnvironment::getConceptsNames(std::vector& namesConcepts) - { - std::map::iterator iteratorConcepts=concepts.begin(); - std::string nameConcept; - while(iteratorConcepts!=concepts.end()) - { - nameConcept=iteratorConcepts->first; - namesConcepts.push_back(nameConcept); - iteratorConcepts++; - } - } - /* - * Method that retorns the name of each concept and the size of it. - * @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts - * @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts - */ - template - void SomeEnvironment :: getConceptsInformation(std::vector& conceptNameVect, std::vector& conceptSizeVect) - { - std::map::iterator iteratorConcepts=concepts.begin(); - while(iteratorConcepts!=concepts.end()) - { - std::string aName = iteratorConcepts->first; - int aSize = iteratorConcepts->second; - conceptNameVect.push_back( aName ); - conceptSizeVect.push_back( aSize ); - iteratorConcepts++; - } - } +//====== INQUIRY ========= - /* - * returns all the things of the environment - */ - template - void SomeEnvironment::getThingsOfEnvironment(std::vector* thingsVector) - { - typename std::map >::iterator iteratorThings= things.begin(); - thingsVector->clear(); - while(iteratorThings!=things.end()) - { - SomeThing* something=&iteratorThings->second; - T* thing=something->getThing(); - thingsVector->push_back(thing); - iteratorThings++; - } +template +std::vector* SomeEnvironment::getThings(Instant* instant) + { + //cleaning things of instant + thingsOfInstant.clear(); + // + + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator = things.begin(); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; - } - /* - * returns a pointer to the thing with the name given - */ - template - T* SomeEnvironment::getThingByName(std::string name) - { - T* thing=NULL; - typename std::map >::iterator iteratorThings= things.find(name); - if(iteratorThings!=things.end()) - { - SomeThing* something=&iteratorThings->second; - thing=something->getThing(); - } - return thing; - } + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + T* thing=something->getThing(); + thingsOfInstant.push_back(thing); + } + thingsIterator++; + } + } + return &thingsOfInstant; + } +/* +* Returns the things with their names in the environment +* @param names, vector where is goint to be safe the names +* of the things in the environment. +* @param things, vector where is going to be save the things +* @return +*/ +template +void SomeEnvironment::getThings(std::vector< std::string >& names,std::vector< T* >& thingsVector, Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.begin(); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + std::string nameThingInEnvironment=thingsIterator->first; + T* thing=something->getThing(); + thingsVector.push_back(thing); + names.push_back(nameThingInEnvironment); + } + thingsIterator++; + } + } + } +/* +* Returns the instants where the thing identified by the name +* it should appears +* @param nameThing, name of the thing in the environment +* @return instants of that thing +*/ +template +std::vector* SomeEnvironment::getInstantsOfThing(std::string nameThing) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(nameThing); + if(thingsIterator!=things.end()) + { + SomeThing* something=&thingsIterator->second; + return something->getInstants(); + } + return (std::vector*)NULL; + } - /* - * returns the number of concepts defined - */ - template - int SomeEnvironment::getNumberOfConcepts() - { - return this->concepts.size(); - } +/* +* Returns the instants define in the environment +* @return existing instants in the environment +* A POINTER TO THE EXISTINGINSTANTS +*/ +template +std::vector* SomeEnvironment::getExistingInstants() + { + return &existingInstants; + } - /* - * Gets the number of things - * @return Returns the number of existing things in the environment - */ - template - int SomeEnvironment::getNumberOfThings () - { - return things.size(); - } - - //====== ACCESS ========== - /* - * Remove a thing from all the instants, it means from the program - * @param name: name of the thing - * @return: true if the removed is succesful (false if the thing doesn exist) - */ - template - bool SomeEnvironment::removeThing(std::string name) - { - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.find(name); - if(thingsIterator!=things.end()) - { - things.erase(thingsIterator); - return true; - } - return false; - } - /* - * Removes the thing with the name given, from the instant - * given - * @param name: name of the thing - * @param Instant: Instant from which it will be removed - * @return true: if the removed is succesful (false if the thing doesn exist) - */ - template - bool SomeEnvironment::removeThingFromInstant(std::string name, Instant* instant) - { - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.find(name); - //setting the environment instant - int indexInstantInside=getIndexInstantInExistingInstants(instant); - Instant* instantInExistingInstants=NULL; - if(indexInstantInside!=-1) - instantInExistingInstants=existingInstants[indexInstantInside]; - - if(thingsIterator!=things.end() && instantInExistingInstants) - { - SomeThing* something=&thingsIterator->second; - - bool isInInstantB=isInInstant(something,instantInExistingInstants); - if(isInInstantB) - { - something->removeInstant(instant); - return true; - } - } - return false; - } +/* +* Returns the size of the concept identified by nameConcept +* @param nameConcept, name of the concept in the environment +* @return size, of the concept given or -1 if the concept doesnt +* exist +*/ +template +int SomeEnvironment::getSizeConcept(std::string nameConcept) + { + std::map< std::string, int>::iterator conceptsIterator; + conceptsIterator= concepts.find(nameConcept); + if(conceptsIterator!= concepts.end()) + { + return conceptsIterator->second; + } + else + return -1; + } +/* +* returns the index of the concept in the instants +*/ +template +int SomeEnvironment::getIndexConcept(std::string nameConcept) + { + std::map< std::string, int>::iterator indexesConceptsIterator; + indexesConceptsIterator= indexesConcepts.find(nameConcept); + if(indexesConceptsIterator!= indexesConcepts.end()) + { + return indexesConceptsIterator->second; + } + else + return -1; + } +/* +* NEW +* Give the names of the names defined +* @param nameConcepts, vector where is goin to be save the names of the concepts +*/ +template +void SomeEnvironment::getConceptsNames(std::vector& namesConcepts) + { + std::map::iterator iteratorConcepts=concepts.begin(); + std::string nameConcept; + while(iteratorConcepts!=concepts.end()) + { + nameConcept=iteratorConcepts->first; + namesConcepts.push_back(nameConcept); + iteratorConcepts++; + } + } +/* +* Method that retorns the name of each concept and the size of it. +* @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts +* @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts +*/ +template +void SomeEnvironment :: getConceptsInformation(std::vector& conceptNameVect, std::vector& conceptSizeVect) +{ + std::map::iterator iteratorConcepts=concepts.begin(); + while(iteratorConcepts!=concepts.end()) + { + std::string aName = iteratorConcepts->first; + int aSize = iteratorConcepts->second; + conceptNameVect.push_back( aName ); + conceptSizeVect.push_back( aSize ); + iteratorConcepts++; + } +} - /* - * Remove Instant from the program, it means, that from all the - * somethings that have that instant, after call this method them - * doesnt have that instant anymore - * @param instant: instant that is going to be removed - * @return true: if the removed is succesful (false other wise) - */ - template - bool SomeEnvironment::removeInstant(Instant* instant) - { - typename std::map < std::string,SomeThing >::iterator thingsIterator; - thingsIterator=things.begin(); - bool ok=false; - - //setting the environment instant - int indexInstantInside=getIndexInstantInExistingInstants(instant); - Instant* instantInExistingInstants=NULL; - if(indexInstantInside!=-1) - instantInExistingInstants=existingInstants[indexInstantInside]; - - while(thingsIterator!=things.end() && instantInExistingInstants) - { - SomeThing* something=&thingsIterator->second; - bool isInInstantB=isInInstant(something,instantInExistingInstants); - if(isInInstantB) - ok = something->removeInstant(instantInExistingInstants); - thingsIterator++; - - } - //removing from inside instants - removeInstantFromExistingInstants(instant); - return ok; - - } - /* - * Remove a dimension from the environment - * THE REMOVE OF THE CONCEPT IS WHEN IS BEING DEFINED THE ENVIRONMENT ,NO IN - * EXECUTION - * PRECONDITION - * the name of the concept given is already added to the environment - * @param nameConcept, name of the concept to remove - */ - template - bool SomeEnvironment::removeConcept(std::string nameConcept) - { - std::map < std::string,int >::iterator conceptsIterator; - conceptsIterator=concepts.find(nameConcept); - if(conceptsIterator!=concepts.end()) - { - concepts.erase(conceptsIterator); - return true; - } - return false; - } - //====== PRIVATE METHODS========= - /* - * Checks if in the instant given the something given has it - * @param instant, instant to check - * @param something;, something to check in the instant - * @return - */ - template - bool SomeEnvironment::isInInstant(SomeThing* something,Instant *instant) - { - //borrame - for(int i=0;igetSize();i++) - int k=instant->getIndexInConcept(i); - // - int index=something->hasInstant(instant); - if(index!=-1) - return true; - else - return false; - } - /* - * Remove the instant from the environment - * @param instant, to be erased - * @return - */ - template - void SomeEnvironment::removeInstantFromExistingInstants(Instant* instant) - { - std::vector::iterator existingInstantsIterator=existingInstants.begin(); - bool isEquals=false; - while(existingInstantsIterator!=existingInstants.end()&& !isEquals) - { - isEquals=(*existingInstantsIterator)->isEquals(instant); - if(isEquals) - existingInstants.erase(existingInstantsIterator); - existingInstantsIterator++; - - } - - } +/* +* returns all the things of the environment +*/ +template +void SomeEnvironment::getThingsOfEnvironment(std::vector* thingsVector) + { + typename std::map >::iterator iteratorThings= things.begin(); + thingsVector->clear(); + while(iteratorThings!=things.end()) + { + SomeThing* something=&iteratorThings->second; + T* thing=something->getThing(); + thingsVector->push_back(thing); + iteratorThings++; + } + } +/* +* returns a pointer to the thing with the name given +*/ +template +T* SomeEnvironment::getThingByName(std::string name) + { + T* thing=NULL; + typename std::map >::iterator iteratorThings= things.find(name); + if(iteratorThings!=things.end()) + { + SomeThing* something=&iteratorThings->second; + thing=something->getThing(); + } + return thing; + } - /* - * Adds an instant to the existing instants, verifying if - * the instant is already added - * @param instant, to be added - * @return - */ - template - int SomeEnvironment::addInstant(Instant* instant) - { - std::vector::iterator existingInstantsIterator=existingInstants.begin(); - int i=0; - bool isEquals=false; - while(existingInstantsIterator!=existingInstants.end() && !isEquals) - { - Instant* existingInstant=*existingInstantsIterator; - //borrame - int sizeI=existingInstant->getSize(); - for(int k=0;kgetIndexInConcept(k); - // - isEquals=existingInstant->isEquals(instant); - existingInstantsIterator++; - if(!isEquals) - i++; - - } - if(!isEquals) - { - //copying the instant's information - std::vector* instantVector=new std::vector(); - int sizeInstant=instant->getSize(); - int k; - for(k=0;kgetIndexInConcept(k); - instantVector->push_back(d); - } - // - //saving the instant given in the handler - Instant* instantToAdded= new Instant(instantVector); - existingInstants.push_back(instantToAdded); - i=existingInstants.size()-1; - } - return i; - } - /* - * Return the index in the existing instants of the instant - * that the user had given - * @param instant, instant for which we are looking the index in - * the existings intants in the environment - * @return an index in (0,existingInstants.size()-1)or -1 if the instant hasnt - * being defined - */ - template - int SomeEnvironment::getIndexInstantInExistingInstants(Instant* instant) - { - std::vector::iterator existingInstantsIterator=existingInstants.begin(); - int i=0; - bool isEquals=false; - while(existingInstantsIterator!=existingInstants.end() && !isEquals) - { - isEquals=(*existingInstantsIterator)->isEquals(instant); - existingInstantsIterator++; - if(!isEquals) - i++; - - } - if(!isEquals) - return -1; - else - return i; - } - - + +/* +* returns the number of concepts defined +*/ +template +int SomeEnvironment::getNumberOfConcepts() + { + return this->concepts.size(); + } + + /* +* Gets the number of things +* @return Returns the number of existing things in the environment +*/ +template +int SomeEnvironment::getNumberOfThings () + { + return things.size(); + } + + +//====== ACCESS ========== +/* +* Remove a thing from all the instants, it means from the program +* @param name: name of the thing +* @return: true if the removed is succesful (false if the thing doesn exist) +*/ +template +bool SomeEnvironment::removeThing(std::string name) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + if(thingsIterator!=things.end()) + { + things.erase(thingsIterator); + return true; + } + return false; + } +/* +* Removes the thing with the name given, from the instant +* given +* @param name: name of the thing +* @param Instant: Instant from which it will be removed +* @return true: if the removed is succesful (false if the thing doesn exist) +*/ +template +bool SomeEnvironment::removeThingFromInstant(std::string name, Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + instantInExistingInstants=existingInstants[indexInstantInside]; + + if(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + something->removeInstant(instant); + return true; + } + } + return false; + } + +/* +* Remove Instant from the program, it means, that from all the +* somethings that have that instant, after call this method them +* doesnt have that instant anymore +* @param instant: instant that is going to be removed +* @return true: if the removed is succesful (false other wise) +*/ +template +bool SomeEnvironment::removeInstant(Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.begin(); + bool ok=false; + + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + ok = something->removeInstant(instantInExistingInstants); + thingsIterator++; + + } + //removing from inside instants + removeInstantFromExistingInstants(instant); + return ok; + } +/* +* Remove a dimension from the environment +* THE REMOVE OF THE CONCEPT IS WHEN IS BEING DEFINED THE ENVIRONMENT ,NO IN +* EXECUTION +* PRECONDITION +* the name of the concept given is already added to the environment +* @param nameConcept, name of the concept to remove +*/ +template +bool SomeEnvironment::removeConcept(std::string nameConcept) + { + std::map < std::string,int >::iterator conceptsIterator; + conceptsIterator=concepts.find(nameConcept); + if(conceptsIterator!=concepts.end()) + { + concepts.erase(conceptsIterator); + return true; + } + return false; + } +//====== PRIVATE METHODS========= +/* +* Checks if in the instant given the something given has it +* @param instant, instant to check +* @param something;, something to check in the instant +* @return +*/ +template +bool SomeEnvironment::isInInstant(SomeThing* something,Instant *instant) +{ + //borrame + for(int i=0;igetSize();i++) + /// \TODO fix warning unused variable k + int k=instant->getIndexInConcept(i); + // + int index=something->hasInstant(instant); + if(index!=-1) + return true; + else + return false; +} +/* +* Remove the instant from the environment +* @param instant, to be erased +* @return +*/ +template +void SomeEnvironment::removeInstantFromExistingInstants(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end()&& !isEquals) + { + isEquals=(*existingInstantsIterator)->isEquals(instant); + if(isEquals) + existingInstants.erase(existingInstantsIterator); + existingInstantsIterator++; + } + } + +/* +* Adds an instant to the existing instants, verifying if +* the instant is already added +* @param instant, to be added +* @return +*/ +template +int SomeEnvironment::addInstant(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + int i=0; + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end() && !isEquals) + { + Instant* existingInstant=*existingInstantsIterator; + //borrame + int sizeI=existingInstant->getSize(); + for(int k=0;kgetIndexInConcept(k); + // + isEquals=existingInstant->isEquals(instant); + existingInstantsIterator++; + if(!isEquals) + i++; + } + if(!isEquals) + { + //copying the instant's information + std::vector* instantVector=new std::vector(); + int sizeInstant=instant->getSize(); + int k; + for(k=0;kgetIndexInConcept(k); + instantVector->push_back(d); + } + // + //saving the instant given in the handler + Instant* instantToAdded= new Instant(instantVector); + existingInstants.push_back(instantToAdded); + i=existingInstants.size()-1; + } + return i; + } +/* +* Return the index in the existing instants of the instant +* that the user had given +* @param instant, instant for which we are looking the index in +* the existings intants in the environment +* @return an index in (0,existingInstants.size()-1)or -1 if the instant hasnt +* being defined +*/ +template +int SomeEnvironment::getIndexInstantInExistingInstants(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + int i=0; + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end() && !isEquals) + { + isEquals=(*existingInstantsIterator)->isEquals(instant); + existingInstantsIterator++; + if(!isEquals) + i++; + } + if(!isEquals) + return -1; + else + return i; + } diff --git a/lib/kernel_Environment/SomeThing_Txx.h b/lib/kernel_Environment/SomeThing_Txx.h index c46ad8d..4ca6348 100644 --- a/lib/kernel_Environment/SomeThing_Txx.h +++ b/lib/kernel_Environment/SomeThing_Txx.h @@ -49,6 +49,7 @@ //borrame int sizeInstant=instant->getSize(); for(int i=0;igetIndexInConcept(i); // int index= hasInstant(instant);