- /*
- * Adds an instant to the existing instants, verifying if
- * the instant is already added
- * @param instant, to be added
- * @return
- */
- template<class T>
- int SomeEnvironment<T>::addInstant(Instant* instant)
- {
- std::vector<Instant*>::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;k<sizeI;k++)
- int r=existingInstant->getIndexInConcept(k);
- //
- isEquals=existingInstant->isEquals(instant);
- existingInstantsIterator++;
- if(!isEquals)
- i++;
-
- }
- if(!isEquals)
- {
- //copying the instant's information
- std::vector<int>* instantVector=new std::vector<int>();
- int sizeInstant=instant->getSize();
- int k;
- for(k=0;k<sizeInstant;k++)
- {
- int d=instant->getIndexInConcept(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<class T>
- int SomeEnvironment<T>::getIndexInstantInExistingInstants(Instant* instant)
- {
- std::vector<Instant*>::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<class T>
+int SomeEnvironment<T>::getNumberOfConcepts()
+ {
+ return this->concepts.size();
+ }
+
+ /*
+* Gets the number of things
+* @return Returns the number of existing things in the environment
+*/
+template<class T>
+int SomeEnvironment<T>::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<class T>
+bool SomeEnvironment<T>::removeThing(std::string name)
+ {
+ typename std::map < std::string,SomeThing<T> >::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<class T>
+bool SomeEnvironment<T>::removeThingFromInstant(std::string name, Instant* instant)
+ {
+ typename std::map < std::string,SomeThing<T> >::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<T>* 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<class T>
+bool SomeEnvironment<T>::removeInstant(Instant* instant)
+ {
+ typename std::map < std::string,SomeThing<T> >::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<T>* 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<class T>
+bool SomeEnvironment<T>::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<class T>
+bool SomeEnvironment<T>::isInInstant(SomeThing<T>* something,Instant *instant)
+{
+ //borrame
+ for(int i=0;i<instant->getSize();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<class T>
+void SomeEnvironment<T>::removeInstantFromExistingInstants(Instant* instant)
+ {
+ std::vector<Instant*>::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<class T>
+int SomeEnvironment<T>::addInstant(Instant* instant)
+ {
+ std::vector<Instant*>::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;k<sizeI;k++)
+ /// \ TODO fix warning unused variable r
+ int r=existingInstant->getIndexInConcept(k);
+ //
+ isEquals=existingInstant->isEquals(instant);
+ existingInstantsIterator++;
+ if(!isEquals)
+ i++;
+ }
+ if(!isEquals)
+ {
+ //copying the instant's information
+ std::vector<int>* instantVector=new std::vector<int>();
+ int sizeInstant=instant->getSize();
+ int k;
+ for(k=0;k<sizeInstant;k++)
+ {
+ int d=instant->getIndexInConcept(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<class T>
+int SomeEnvironment<T>::getIndexInstantInExistingInstants(Instant* instant)
+ {
+ std::vector<Instant*>::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;
+ }