--- /dev/null
+PROJECT(CreaEnvironment)
+
+SET(PROJECT_MAJOR_VERSION 1)
+SET(PROJECT_MINOR_VERSION 0)
+SET(PROJECT_BUILD_VERSION 0)
+
+SET(CREA_VERBOSE_CMAKE TRUE)
+
+FIND_PACKAGE(crea REQUIRED)
+IF (crea_FOUND)
+ INCLUDE(${crea_USE_FILE})
+ENDIF(crea_FOUND)
+
+CREA_PREVENT_IN_SOURCE_BUILD()
+
+SET(USE_GDCM OFF)
+SET(USE_GDCM_VTK OFF)
+SET(USE_WXWIDGETS OFF)
+SET(USE_VTK OFF)
+SET(USE_ITK OFF)
+SET(USE_BOOST OFF)
+
+CREA_FIND_AND_USE_LIBRARIES()
+
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
+MARK_AS_ADVANCED(
+ CMAKE_BACKWARDS_COMPATIBILITY
+ EXECUTABLE_OUTPUT_PATH
+ LIBRARY_OUTPUT_PATH
+ )
+
+
+SUBDIRS(lib)
+#SUBDIRS(appli)
\ No newline at end of file
--- /dev/null
+#----------------------------------------------------------------------------
+# SET THE NAME OF YOUR EXECUTABLE
+SET ( EXE_NAME MyExe )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# EXECUTABLE SOURCES (TO BE COMPILED)
+# EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
+FILE(GLOB ${EXE_NAME}_SOURCES *.cxx *.cpp *.cc)
+# OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
+# SET ( ${EXE_NAME}_SOURCES
+#
+# )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# DEPENDENCIES (LIBRARIES TO LINK WITH)
+SET ( ${EXE_NAME}_LINK_LIBRARIES
+ ${crea_LIBRARIES}
+ # ${WXWIDGETS_LIBRARIES}
+ # ${VTK_LIBRARIES}
+ # ${ITK_LIBRARIES}
+ # ${GDCM_LIBRARIES}
+ # ${BOOST_LIBRARIES}
+ )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# CREATES AND INSTALLS THE EXE
+CREA_ADD_EXECUTABLE( ${EXE_NAME} )
+#----------------------------------------------------------------------------
+
+
--- /dev/null
+#----------------------------------------------------------------------------
+# SET THE NAME OF YOUR EXECUTABLE
+SET ( EXE_NAME MyExe )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# EXECUTABLE SOURCES (TO BE COMPILED)
+# EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
+FILE(GLOB ${EXE_NAME}_SOURCES *.cxx *.cpp *.cc)
+# OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
+# SET ( ${EXE_NAME}_SOURCES
+#
+# )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# DEPENDENCIES (LIBRARIES TO LINK WITH)
+SET ( ${EXE_NAME}_LINK_LIBRARIES
+ ${crea_LIBRARIES}
+ # ${WXWIDGETS_LIBRARIES}
+ # ${VTK_LIBRARIES}
+ # ${ITK_LIBRARIES}
+ # ${GDCM_LIBRARIES}
+ # ${BOOST_LIBRARIES}
+ )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# UNCOMMENT NEXT LINE IF YOU WANT A CONSOLE ON WINDOWS
+# NB : YOUR MAIN MUST BE ADAPTED ALSO
+# SEE THE MACRO CREA_WXMAIN_WITH_CONSOLE IN creaWx.h
+#SET(${EXE_NAME}_CONSOLE TRUE)
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# CREATES AND INSTALLS THE EXE
+CREA_ADD_WX_EXECUTABLE( ${EXE_NAME} )
+#----------------------------------------------------------------------------
+
+
--- /dev/null
+# Add a SUBDIRS command for each of your libraries
+SUBDIRS(kernel_Environment)
--- /dev/null
+#----------------------------------------------------------------------------
+# SET THE NAME OF YOUR LIBRARY
+SET ( LIBRARY_NAME CreaEnvironment )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# CREATES A USER OPTION IN CMAKE
+OPTION ( BUILD_${LIBRARY_NAME} "Build ${LIBRARY_NAME} library ?" ON)
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+IF ( BUILD_${LIBRARY_NAME} )
+#----------------------------------------------------------------------------
+
+ #----------------------------------------------------------------------------
+ # BUILD LIBRARY
+ #----------------------------------------------------------------------------
+
+ #----------------------------------------------------------------------------
+ # LIBRARY HEADERS (TO BE INSTALLED)
+ # EITHER LIST ALL .h IN CURRENT DIR USING NEXT LINE:
+ FILE(GLOB ${LIBRARY_NAME}_HEADERS "*.h")
+ # OR MANUALLY LIST YOUR HEADERS WITH NEXT COMMAND
+ #SET ( ${LIBRARY_NAME}_HEADERS
+
+ #"SomeEnvironment_Txx"
+ #"SomeEnvironment"
+ #"SomeThing_Txx"
+ #"SomeThing"
+ #"Instant"
+ #"HandlerConceptsException"
+ #"InstantHandler_Txx"
+ #"InstantHandler"
+ #"ConceptInstantHandler"
+ #"InstantPlayer"
+ #"ReaderEnvironment"
+
+ # )
+ #----------------------------------------------------------------------------
+
+ #----------------------------------------------------------------------------
+ # LIBRARY SOURCES (TO BE COMPILED)
+ # EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
+ FILE(GLOB ${LIBRARY_NAME}_SOURCES *.cxx *.cpp *.cc )
+ # OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
+ # SET ( ${LIBRARY_NAME}_SOURCES
+
+ #"SomeEnvironment_Txx"
+ #"SomeEnvironment"
+ #"SomeThing_Txx"
+ #"SomeThing"
+ #"Instant"
+ #"HandlerConceptsException"
+ #"InstantHandler_Txx"
+ #"InstantHandler"
+ #"ConceptInstantHandler"
+ #"InstantPlayer"
+ #"ReaderEnvironment"
+
+ #)
+ #----------------------------------------------------------------------------
+
+ #----------------------------------------------------------------------------
+ # LIBRARY DEPENDENCIES (LIBRARIES TO LINK WITH)
+ SET (${LIBRARY_NAME}_LINK_LIBRARIES
+
+ ${crea_LIBRARIES}
+ #${WXWIDGETS_LIBRARIES}
+ #${VTK_LIBRARIES}
+ # ${ITK_LIBRARIES}
+ # ${GDCM_LIBRARIES}
+ # ${BOOST_LIBRARIES}
+ )
+ #----------------------------------------------------------------------------
+ #----------------------------------------------------------------------------
+ # MACRO WHICH DOES ALL THE JOB : BUILD AND INSTALL
+ CREA_ADD_LIBRARY( ${LIBRARY_NAME} )
+ #----------------------------------------------------------------------------
+
+ #---------------------------------------------------------------------------
+ENDIF ( BUILD_${LIBRARY_NAME} )
--- /dev/null
+
+
+// SYSTEM INCLUDES
+#include <iostream>
+#include <string>
+#include <vector>
+#include <exception>
+#include <stdio.h>
+#include <time.h>
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+#include "ConceptInstantHandler.h"
+
+// FORWARD REFERENCES
+
+
+
+
+ //====== LIFECYCLE ========
+ ConceptInstantHandler::ConceptInstantHandler(std::string name,int mode,int positionInReproduction)
+ {
+ this->name=name;
+ this->mode=mode;
+ this->positionInReproduction=positionInReproduction;
+ this->increaseValue=1;
+ this->decreaseValue=1;
+ this->actualIndex=0;
+ this->scaleTime=0;
+ //timeReproduction=intervalTimer*maximumValue
+ this->timeReproduction=100;
+ this->actualTime=0;
+ this->initialTime=0;
+ }
+ ConceptInstantHandler::~ConceptInstantHandler()
+ {
+ name.clear();
+ }
+ //====== OPERATIONS =======
+ /*
+ * change the actual index by increasing
+ * the index until the maximum by the increaseValue
+ */
+ void ConceptInstantHandler::nextIndex()
+ {
+
+ //just plus plus
+ if(mode==PLUS_PLUS)
+ actualIndex+=increaseValue;
+ //time scale
+ else
+ {
+ time_t seconds=time(NULL);
+ if(initialTime==0)
+ initialTime=seconds*1000;
+ int time=seconds*1000;
+ actualTime=time-initialTime;
+ actualIndex=(int)actualTime*scaleTime;
+ }
+
+
+ if(actualIndex>=maximumIndex)
+ actualIndex=maximumIndex-1;
+
+
+ }
+ /*
+ * change the actual index by decreasing
+ * the index until zero by the decreaseValue
+ */
+ void ConceptInstantHandler::previousIndex()
+ {
+ //just plus plus
+ if(mode==PLUS_PLUS)
+ actualIndex-=decreaseValue;
+
+ else
+ actualIndex=(int)actualTime*scaleTime;
+
+ if(actualIndex<0)
+ actualIndex=0;
+
+ }
+
+ //====== INQUIRY =========
+ /*
+ * @return name
+ */
+ std::string ConceptInstantHandler::getName()
+ {
+ return this->name;
+ }
+ /*
+ * @return PositionInReproduction
+ */
+ int ConceptInstantHandler::getPosition()
+ {
+ return this->positionInReproduction;
+ }
+ /*
+ * @return mode
+ */
+ int ConceptInstantHandler::getMode()
+ {
+ return this->mode;
+ }
+ /*
+ * @return increaseValue
+ */
+ int ConceptInstantHandler::getIncreaseValue()
+ {
+ return this->increaseValue;
+ }
+
+ /*
+ * @return decreaseValue
+ */
+ int ConceptInstantHandler::getDecreaseValue()
+ {
+ return this->decreaseValue;
+ }
+
+ /*
+ * @return indexInInstant
+ */
+ int ConceptInstantHandler::getIndexInInstant()
+ {
+ return this->indexInInstant;
+ }
+ /*
+ * @return actualIndex
+ */
+ int ConceptInstantHandler::geActualIndex()
+ {
+ return actualIndex;
+ }
+ /*
+ * @return maximumIndex
+ */
+
+ int ConceptInstantHandler::getMaximumIndex()
+ {
+ return maximumIndex;
+ }
+ /*
+ * @return timeReproduction
+ */
+ double ConceptInstantHandler::getTimeReproduction()
+ {
+ return timeReproduction;
+ }
+ /*
+ * @return scaleTime
+ */
+ double ConceptInstantHandler::getScale()
+ {
+ return scaleTime;
+ }
+ /*
+ * if the actual index is not the maximum index
+ */
+ bool ConceptInstantHandler::hasNextIndex()
+ {
+ if(actualIndex<maximumIndex-1)
+ return true;
+ else return false;
+ }
+ /*
+ * if the actual index is not zero
+ */
+ bool ConceptInstantHandler::hasPreviousIndex()
+ {
+ if(actualIndex>0)
+ return true;
+ else return false;
+ }
+ /*
+ * Get initial time
+ */
+ double ConceptInstantHandler::getInitialTime()
+ {
+ return this->initialTime;
+ }
+
+ //====== ACCESS ==========
+ /*
+ * Sets the name of the concept
+ * @param name, new name
+ */
+ void ConceptInstantHandler::setName(std::string name)
+ {
+ this->name=name;
+ }
+ /*
+ * Sets the position of the concept
+ * @param position, position
+ */
+ void ConceptInstantHandler::setPosition(int position)
+ {
+ this->positionInReproduction=position;
+ }
+ /*
+ * Sets the mode of the concept
+ * @param mode, new mode= REAL_TIME or
+ * PLUS_PLUS
+ */
+ void ConceptInstantHandler::setMode(int mode)
+ {
+ if(this->mode==PLUS_PLUS)
+ {
+ time_t seconds=time(NULL);
+ int time=seconds*1000;
+ actualTime=actualIndex/scaleTime;
+ initialTime=time-actualTime;
+ }
+ this->mode=mode;
+ }
+ /*
+ * Set Increase of the instant
+ */
+ void ConceptInstantHandler::setIncreaseValue(int increaseValue)
+ {
+ this->increaseValue=increaseValue;
+ }
+
+ /*
+ * Set decrease of the instant
+ */
+ void ConceptInstantHandler::setDecreaseValue(int decreaseValue)
+ {
+ this->decreaseValue=decreaseValue;
+ }
+ /*
+ * Sets the index of the concept in the instant
+ * @param indexInInstant
+ */
+ void ConceptInstantHandler::setIndexInInstant(int indexInInstant)
+ {
+ this->indexInInstant=indexInInstant;
+ }
+ /*
+ * Sets sets the maximum value
+ * @param maximumIndex
+ */
+ void ConceptInstantHandler::setMaximumIndex(int maximumIndex)
+ {
+ this->maximumIndex=maximumIndex;
+ scaleTime=(maximumIndex-1)/timeReproduction;
+ }
+
+ /*
+ * set the actualIndex
+ */
+ void ConceptInstantHandler::setActualIndex(int index)
+ {
+ if(index<=maximumIndex-1)
+ actualIndex=index;
+ //TODO else thow exception of out of bounds
+ }
+ /*
+ * set the timeReproduction
+ * @param timeReproduction
+ */
+ void ConceptInstantHandler::setTimeReproduction(double time)
+ {
+ this->timeReproduction=(this->maximumIndex-1)*time;
+ scaleTime=(maximumIndex-1)/timeReproduction;
+ }
+ /*
+ * set the scaleTime
+ * @param scale
+ */
+ void ConceptInstantHandler::setScale(double scale)
+ {
+ this->scaleTime=scale;
+ }
+ /*
+ * set the actualTime
+ * @param actualTime
+ */
+ void ConceptInstantHandler::setActualTime(double actualTime)
+ {
+ this->actualTime=actualTime;
+ }
+ /*
+ * reset the initial time
+ */
+ void ConceptInstantHandler::resetInitialTime()
+ {
+ this->initialTime=0;
+ }
+ /*
+ * Sets the initial time
+ */
+ void ConceptInstantHandler::setInitialTime(double time)
+ {
+ this->initialTime=time;
+ }
+
+
+
+
--- /dev/null
+/*=========================================================================
+
+ Program: ConceptInstantHandler
+ Module: $RCSfile: ConceptInstantHandler.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: Wrapper fo the concepts that subscribe to the instant handler
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+
+// SYSTEM INCLUDES
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+// PROJECT INCLUDES
+
+
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+
+#ifndef __CONCEPTINSTANTHANDLER_H_INCLUDED__
+#define __CONCEPTINSTANTHANDLER_H_INCLUDED__
+
+#if defined(WIN32)
+//If we're using a dynamic library
+# ifdef NDimensionsEnvironment_BUILD_SHARED
+# define NDimensionsEnvironment_EXPORTS __declspec( dllexport )
+# else
+# define NDimensionsEnvironment_EXPORTS //__declspec( dllimport )
+# endif //maracasvisulib_EXPORTS
+#endif
+
+
+class NDimensionsEnvironment_EXPORTS ConceptInstantHandler
+ {
+ public:
+ //===== CONSTANTS ========
+ /*
+ * if the concept is being reproduced in real time
+ */
+ const static int REAL_TIME=1;
+ /*
+ * if the concept is being reproduced by doing
+ * plus plus to its indexes
+ */
+ const static int PLUS_PLUS=2;
+
+
+ //====== LIFECYCLE ========
+ ConceptInstantHandler(std::string name,int mode,int positionInReproduction);
+ ~ConceptInstantHandler();
+ //====== OPERATIONS =======
+ /*
+ * change the actual index by increasing
+ * the index until the maximum by the increaseValue
+ */
+ void nextIndex();
+ /*
+ * change the actual index by decreasing
+ * the index until zero by the decreaseValue
+ */
+ void previousIndex();
+
+
+ //====== INQUIRY =========
+ /*
+ * @return name
+ */
+ std::string getName();
+ /*
+ * @return PositionInReproduction
+ */
+ int getPosition();
+ /*
+ * @return mode
+ */
+ int getMode();
+ /*
+ * @return increaseValue
+ */
+ int getIncreaseValue();
+
+ /*
+ * @return decreaseValue
+ */
+ int getDecreaseValue();
+
+ /*
+ * @return indexInInstant
+ */
+ int getIndexInInstant();
+ /*
+ * @return actualIndex
+ */
+ int geActualIndex();
+ /*
+ * @return maximumIndex
+ */
+
+ int getMaximumIndex();
+ /*
+ * @return timeReproduction
+ */
+ double getTimeReproduction();
+ /*
+ * @return scaleTime
+ */
+ double getScale();
+
+ /*
+ * if the actual index is not the maximum index
+ */
+ bool hasNextIndex();
+ /*
+ * if the actual index is not zero
+ */
+ bool hasPreviousIndex();
+
+ /*
+ * Get initial time
+ */
+ double getInitialTime();
+
+
+ //====== ACCESS ==========
+ /*
+ * Sets the name of the concept
+ * @param name, new name
+ */
+ void setName(std::string name);
+ /*
+ * Sets the position of the concept
+ * @param position
+ */
+ void setPosition(int position);
+ /*
+ * Sets the mode of the concept
+ * @param mode, new mode= REAL_TIME or
+ * PLUS_PLUS
+ */
+ void setMode(int mode);
+ /*
+ * Set Increase of the concept
+ * @param increaseValue
+ */
+ void setIncreaseValue(int increaseValue);
+
+ /*
+ * Set decrease of the concept
+ * @param decreaseValue
+ */
+ void setDecreaseValue(int decreaseValue);
+
+ /*
+ * Sets the index of the concept in the instant
+ * @param indexInInstant
+ */
+ void setIndexInInstant(int indexInInstant);
+ /*
+ * Sets sets the maximum value
+ * @param maximumIndex
+ */
+ void setMaximumIndex(int maximumIndex);
+ /*
+ * set the actualIndex
+ * @param index
+ */
+ void setActualIndex(int index);
+ /*
+ * set the timeReproduction
+ * @param time
+ */
+ void setTimeReproduction(double time);
+ /*
+ * set the scaleTime
+ * @param scale
+ */
+ void setScale(double scale);
+ /*
+ * set the actualTime
+ * @param actualTime
+ */
+ void setActualTime(double actualTime);
+ /*
+ * reset the initial time
+ */
+ void resetInitialTime();
+ /*
+ * Sets the initial time
+ */
+ void setInitialTime(double time);
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+
+ /*
+ * Name of the concept
+ */
+ std::string name;
+ /*
+ * Mode of changing the instant
+ * REAL_TIME
+ * PLUS_PLUS
+ */
+ int mode;
+
+ /*
+ * position in the reproduction
+ */
+ int positionInReproduction;
+ /*
+ * Increment for an instant
+ * for default is 1
+ */
+ int increaseValue;
+ /*
+ * Decrease for an instant
+ * for default is 1
+ */
+ int decreaseValue;
+ /*
+ * index in Instant
+ */
+ int indexInInstant;
+ /*
+ * index that it is
+ */
+ int actualIndex;
+ /*
+ * maximum index that can have in the instant
+ */
+ int maximumIndex;
+ /*
+ * Time in miliseconds of the reproduction
+ */
+ double timeReproduction;
+ /*
+ * Scale use for calculate the index
+ * of the concept according to the time of reproduction
+ * defined in timeReproduction
+ * scaleTime=maximumIndex/timeReproduction
+ */
+ double scaleTime;
+ /*
+ * actual time of the reproduction
+ * is in miliseconds
+ */
+ double actualTime;
+ /*
+ * Initial time
+ * is in miliseconds
+ */
+ double initialTime;
+
+
+
+ //====== PRIVATE METHODS=========
+
+
+ };
+#endif
--- /dev/null
+
+
+// SYSTEM INCLUDES
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+// PROJECT INCLUDES
+
+#include "EnvironmentEnvironmentHandler"
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+#ifndef __EnvironmentHandler_h__INCLUDED
+template <class P>
+
+class EnvironmentHandler
+ {
+ public:
+ //====== LIFECYCLE ========
+ EnvironmentHandler(SomeEnvironment<P>* environment);
+ ~EnvironmentHandler();
+
+ //====== OPERATIONS =======
+ /*
+ * change the actual intants associated to the
+ * names given
+ */
+ void nextInstants(std::vector<std::string> nameConcepts);
+
+ /*
+ * adds an actual Instant to a concept, it means, this instant
+ * has all index fixed, except the index in the instant of the concept
+ * identified by nameConcept
+ */
+ void addActualInstantOfCOncept(std::string nameConcept,Instant* instant);
+
+ /*
+ * removes the pair in the map of actual concepts
+ */
+ void removeActualInstantOfConcept(std::string nameConcept);
+
+ //====== INQUIRY =========
+ /*
+ * get all the actual instants
+ */
+ void getActualsInstants(std::vector<Instant*>& instantsVector);
+
+ /*
+ * get the actual instant fot the concept identified by the name
+ */
+ Instant* getActualInstant(std::string nameConcept);
+ //====== ACCESS ==========
+
+
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+
+ /*
+ * actual instants of the environmenHandler
+ */
+
+ std::map<std::string,Instant*> actualInstants;
+ /*
+ * Environment that's being handled
+ */
+
+ SomeEnvironment<P>* environment;
+ //====== PRIVATE METHODS=========
+
+
+ };
+//include the implementation of the template
+#include "EnvironmentHandler_Txx.h"
+#endif
--- /dev/null
+// SYSTEM INCLUDES
+
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+#include "Instant.h"
+
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+ //====== LIFECYCLE ========
+ template<class P>
+ EnvironmentHandler<P>::EnvironmentHandler(SomeEnvironment<P>* environment)
+ {
+ this->environment=environment;
+ }
+
+ template<class P>
+ EnvironmentHandler<P>::~EnvironmentHandler()
+ {
+ //deleting actual instants
+ this->actualInstants.clear();
+ //deleting environment
+ if(this->environment) delete this->environment;
+
+ }
+
+ //====== OPERATIONS =======
+ /*
+ * change the actual intants associated to the
+ * names given
+ */
+ template<class P>
+ void EnvironmentHandler<P>::nextInstants(std::vector<std::string> nameConcepts)
+ {
+ int size,i,indexConcept,indexInConcept,sizeConcept;
+ size=nameConcepts.size();
+ std::map<std::string,Instant*>::iterator actualInstantsIterator;
+ std::string nameConcepti;
+ for(i=0;i<size;i++)
+ {
+ nameConcepti=nameConcepts[i];
+ actualInstantsIterator=actualInstants.find(nameConcepti);
+ if(actualInstantsIterator!=actualInstants.end())
+ {
+ Instant* instant=actualInstantsIterator->second;
+ indexConcept=environment->getIndexConcept(nameConcepti);
+ indexInConcept=instant->getIndexInConcept(indexConcept);
+ indexInConcept++;
+ sizeConcept=environment->getSizeConcept(nameConcepti);
+ if(indexInConcept<sizeConcept)
+ instant->setConcept(indexConcept,indexInConcept);
+ }
+ }
+
+ }
+
+ /*
+ * add an actual Instant to a concept, it means, this instant
+ * has all index fixed, except the index in the instant of the concept
+ * identified by nameConcept
+ */
+ template<class P>
+ void EnvironmentHandler<P>::addActualInstantOfCOncept(std::string nameConcept,Instant* instant)
+ {
+ actualInstants.insert(std::pair<std::string,int>(nameConcept,instant));
+ }
+
+ /*
+ * removes the pair in the map of actual concepts
+ */
+ template<class P>
+ void EnvironmentHandler<P>::removeActualInstantOfConcept(std::string nameConcept)
+ {
+ std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
+ if(actualInstantsIterator!=actualInstants.end())
+ actualInstants.erase(actualInstantsIterator);
+
+ }
+ //====== INQUIRY =========
+ /*
+ * get all the actual instants
+ */
+ template<class P>
+ void EnvironmentHandler<P>::getActualsInstants(std::vector<Instant*>& instantsVector)
+ {
+
+ std::map<std::string,Instant*>::iterator actualInstantsIterator=
+ actualInstants.begin();
+ while(actualInstantsIterator!=actualInstants.end())
+ {
+ Instant* instant=actualInstantsIterator->second;
+ instantsVector.push_back(instant);
+ actualInstantsIterator++;
+ }
+
+ }
+
+ /*
+ * get the actual instant fot the concept identified by the name
+ */
+ template<class P>
+ Instant* EnvironmentHandler<P>::getActualInstant(std::string nameConcept)
+ {
+ std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
+ if(actualInstantsIterator!=actualInstants.end())
+ {
+ return instant=actualInstantsIterator->second;
+
+ }
+ else
+ return (Instant*)NULL;
+ }
+ //====== ACCESS ==========
+
\ No newline at end of file
--- /dev/null
+
+// SYSTEM INCLUDES
+
+#include <iostream>
+#include <exception>
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+//using namespace handlerDimensions
+//using namespace std;
+
+namespace handlerConcepts
+ {
+ class HandlerException: public std::exception
+ {
+
+ //====== LIFECYCLE ========
+ HandlerException(std::std::string msg)
+ {
+ this->msg=msg;
+ }
+ //======= INQUIRY ===========
+ virtual const char* what() const throw()
+ {
+ return msg;
+ }
+
+ private:
+ /*
+ * msg to return
+ */
+ std::std::string msg;
+ } handlerException;
+ }
\ No newline at end of file
--- /dev/null
+
+
+// SYSTEM INCLUDES
+
+
+// PROJECT INCLUDES
+#include <iostream>
+#include <vector>
+
+// LOCAL INCLUDES
+#include "Instant.h"
+
+// FORWARD REFERENCES
+//NAMESPACE
+
+
+
+
+ //====== LIFECYCLE ========
+
+ Instant::Instant(std::vector<int>* instant)
+ {
+ nTuple=new std::vector<int>();
+ setInstant(instant);
+ }
+
+ Instant::Instant()
+ {
+ nTuple=new std::vector<int>();
+ }
+
+ Instant::Instant(int size)
+ {
+ nTuple= new std::vector<int>();
+ int i;
+ for(i=0;i<size;i++)
+ nTuple->push_back(0);
+
+ }
+ Instant::~Instant()
+ {
+ //deleting nTuple
+ nTuple->clear();
+
+ }
+
+ //====== OPERATIONS =======
+ /*
+ * Add a new concept to the instant
+ * @param indexConcept: index concept that is going
+ * to be added of the new concept added to the instant
+ * @return --
+ *
+ */
+ void Instant::addConcept(int value)
+ {
+ nTuple->push_back(value);
+ }
+ //======= INQUIRY ===========
+ /*
+ * Returns the value nTuple
+ * @return nTuple
+ */
+ std::vector<int>* Instant::getInstant()
+ {
+ return nTuple;
+ }
+ /*
+ * Returns the index of the concept that's
+ * in the instant's concept index
+ * @param indexConcept: index of the concept in the instant
+ * @return indexInConcept
+ */
+ int Instant::getIndexInConcept(int indexConcept)
+ {
+ return (*nTuple)[indexConcept];
+ }
+
+ /*
+ * returns the number of concepts that the instant has
+ * @return nTuple.size()
+ */
+ int Instant::getSize()
+ {
+ return nTuple->size();
+ }
+
+ /*
+ * Compares if the instant given is equals to the nTuple
+ * @param instant: instant for compare
+ * @return true if is equals to the nTuple, false otherwise
+ */
+ bool Instant::isEquals(Instant* instant)
+ {
+ int sizeInstant=instant->getSize();
+ bool equals=true;
+ int sizeThisInstant=getSize();
+ if(sizeInstant==sizeThisInstant)
+ {
+ int i;
+ for(i=0;i<sizeThisInstant;i++)
+ {
+ int indexi=(*nTuple)[i];
+ int indexInConcept=instant->getIndexInConcept(i);
+ if(indexi!=indexInConcept)
+ equals=false;
+ }
+
+ }
+ else
+ equals=false;
+ return equals;
+ }
+
+ //=========== ACCESS ==========
+ /*
+ * Sets the nTuple
+ * @param instant: the vector that's going to be save in
+ * nTuple
+ */
+ void Instant::setInstant(std::vector<int>* instant)
+ {
+ int i,size;
+ size=instant->size();
+ for(i=0;i<size;i++)
+ {
+ int k=(*instant)[i];
+ nTuple->push_back(k);
+ }
+ }
+
+ /*
+ * Change the concept's index saved in the nTuple index (the index
+ * that's is for that concept
+ * @param indexConcept: Concept that's going to change the value
+ * @return--
+ *
+ */
+ void Instant::setConcept(int indexConcept, int index)
+ {
+ (*nTuple)[indexConcept]=index;
+ }
+ /*
+ * remove a concept from the instant
+ * @param indexConcept: Concept that's going to be removec
+ * @return true if succesful, false otherwise
+ *
+ */
+ bool Instant::removeConcept(int indexConcept)
+ {
+ int i;
+ std::vector<int>::iterator conceptsIterator=nTuple->begin();
+ int size=nTuple->size();
+ for(i=0;i<size;i++)
+ {
+ if(i==indexConcept)
+ {
+ nTuple->erase(conceptsIterator);
+ return true;
+ }
+ conceptsIterator++;
+ }
+ return false;
+ }
--- /dev/null
+
+
+// SYSTEM INCLUDES
+
+/*
+ #include <iostream>
+ #include <vector>
+*/
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+
+// FORWARD REFERENCES
+
+
+
+
+#ifndef __INSTANT_H_INCLUDED__
+#define __INSTANT_H_INCLUDED__
+
+#include "ConceptInstantHandler.h"
+
+class NDimensionsEnvironment_EXPORTS Instant
+ {
+ public:
+
+
+ //====== LIFECYCLE ========
+ Instant(std::vector<int>* instant);
+ Instant();
+ Instant(int size);
+ ~Instant();
+
+ //====== OPERATIONS =======
+ /*
+ * Add a new concept to the instant
+ * @param indexConcept: index concept that is going
+ * to be added of the new concept added to the instant
+ * @return --
+ *
+ */
+ void addConcept(int value);
+ //======= INQUIRY ===========
+ /*
+ * Returns the value nTuple
+ * @return nTuple
+ */
+ std::vector<int>* getInstant();
+ /*
+ * Returns the index of the concept that's
+ * in the instant's concept index
+ * @param indexConcept: index of the concept in the instant
+ * @return indexInConcept
+ */
+ int getIndexInConcept(int indexConcept);
+
+ /*
+ * returns the number of concepts that the instant has
+ * @return nTuple.size()
+ */
+ int getSize();
+
+
+ /*
+ * Compares if the instant given is equals to the nTuple
+ * @param instant: instant for compare
+ * @return true if is equals to the nTuple, false otherwise
+ */
+ bool isEquals(Instant* instant);
+
+
+ //=========== ACCESS ==========
+ /*
+ * Sets the nTuple
+ * @param instant: the vector that's going to be save in
+ * nTuple
+ */
+ void setInstant(std::vector<int>* instant);
+
+ /*
+ * Change the concept's index saved in the nTuple index (the index
+ * that's is for that concept
+ * @param indexConcept: Concept that's going to change the value
+ * @return--
+ *
+ */
+ void setConcept(int indexConcept, int index);
+ /*
+ * remove a concept from the instant
+ * @param indexConcept: Concept that's going to be removec
+ * @return true if succesful, false otherwise
+ *
+ */
+ bool removeConcept(int indexConcept);
+
+ private:
+
+ //=========== ATTRIBUTES==========
+ /*
+ * The vector that's represent an instant according to the
+ * number of concepts that are already defined
+ * EXAMPLE
+ * concepts: (time,patient), and time's size is 2, patients's size is 2
+ * then an possible instant is (1,2)
+ *
+ */
+ std::vector<int>* nTuple;
+
+ };
+#endif
+
+
+
--- /dev/null
+/*=========================================================================
+
+ Program: instantHandler
+ Module: $RCSfile: InstantHandler.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: Handles the change of instant among the concept already inscribed
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+
+
+// MACRO
+#ifndef __INSTANTHANDLER_H_INCLUDED__
+#define __INSTANTHANDLER_H_INCLUDED__
+
+// SYSTEM INCLUDES
+
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+// PROJECT INCLUDES
+
+#include "SomeEnvironment.h"
+#include "ConceptInstantHandler.h"
+#include "ViewerNDimensionsException.h"
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+template <class P>
+
+class InstantHandler
+ {
+ public:
+ //========== CONSTANTS =======
+
+ //====== LIFECYCLE ========
+ InstantHandler(SomeEnvironment<P>* environment)throw (ViewerNDimensionsException);
+ ~InstantHandler();
+
+ //====== OPERATIONS =======
+
+ /*
+ * Adds a concept to handled in the instant, it means, when
+ * the next instant is used we are going to change this concepts in the instant
+ * PRECONDITION
+ * the calls to this functions are made in order of position, where the last position (it means
+ * the higher position defined) is the concept thats is going to handled the real time
+ * THE LAST POSITION HANDLEDS THE REAL TIME DOESNT MATTER THE CONCEPT
+ * EXAMPLE
+ * The user wants to reproduce doctors, pacients and time, and positions given are:
+ * 0=reproduce doctors, 1= reproduce pacients, 2= time, then 1,2 are going to be reproduced
+ * by PLUS PLUS, and time by REAL TIME
+ * @param nameConcept, name of the concept
+ * @param mode, mode of change
+ * @param position, position of reproduction
+ * @return true if succesful, false otherwise
+ */
+ bool addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException);
+
+
+ /*
+ * Next instant of the concepts to change
+ * @param
+ * @return
+ */
+ void nextInstant()throw (ViewerNDimensionsException);
+
+
+ /*
+ * Previous instant of the actual concept
+ * @param
+ * @return
+ */
+ void previousInstant()throw (ViewerNDimensionsException);
+
+ /*
+ * Removes all the concept handled
+ */
+ void removeAllConcepts();
+
+ /*
+ * Removes the concept with the name given
+ * @param nameConcept, name of the concept to remove
+ * WARNING the user know wich concept is erasing, also knows the
+ * mode of other concepts, if the user is deleting the concept that
+ * handled the real time, should change the mode to other concept that exist
+ */
+ void removeConceptToHandled(std::string nameConcept);
+
+ /*
+ * sets all the concept to handled in 0
+ */
+ void resetConceptsHandled();
+
+ /*
+ * Pause
+ */
+ //void pause();
+
+ //====== INQUIRY =========
+
+ /*
+ * get the actual instant for the concept identified by the name
+ */
+ Instant* getActualInstant()throw (ViewerNDimensionsException);
+
+
+ /*
+ * If the actual concept has next instant, it means, if the index of the concept
+ * in the instant is less that the maximum value
+ * @return true if IS NOT in the maximum, false otherwise
+ */
+ bool hasNextInstant();
+
+ /*
+ * If the concept has previous instant, it means, if the index of the concept
+ * in the instant is positive
+ * @return true if IS NOT in zero, false otherwise
+ */
+ bool hasPreviousInstant();
+
+ /*
+ * returns the number con conceptsToHandled
+ */
+ int getSizeConceptsToChange();
+
+ /*
+ * returns the number of possibles instants of the handler
+ * it depends of the concepts added in conceptsTochange
+ */
+ int getNumOfInstants();
+
+ /*
+ * Returns the names of the concepts handled and its modes
+ * DEPRECATED
+ */
+ void getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes);
+ /*
+ * Returns the name of the concept that handled the real time
+ * DEPRECATED
+ */
+ void getTimeConcept(std::string& nameConcept);
+ //====== ACCESS ==========
+ /*
+ * Sets the environment that is going to be handled
+ * @param environment, a pointer to the environmen
+ * @return
+ */
+ void setEnvironment(SomeEnvironment<P>* environment);
+ /*
+ * Sets the actual instant of the instant handler
+ * @param instant
+ */
+ void setActualInstant(Instant* instant);
+ /*
+ * Sets the time of reproduction to the concept
+ * that depends of the real time of the reproduction
+ * (miliseconds)
+ * @param time
+ */
+ void setTimeReproduction(double time);
+ /*
+ * Sets the actual time of the reproduction,
+ * is the real time (seconds)
+ * @param actualTime
+ */
+ void setActualTime(double actualTime);
+ /*
+ * Set the mode of a concept that's being handled
+ */
+ void setModeOfConcept(std::string nameConcept,int mode);
+ /*
+ * Set handler
+ */
+ void set();
+ /*
+ * Set the increase Value for changing the instant
+ */
+ void setIncreaseValue(int increase);
+ /*
+ * Set the decrease Value for changing the instant
+ */
+ void setDecreaseValue(int decrease);
+
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+
+ /*
+ * actual instant of the InstantHandler
+ */
+ Instant* actualInstant;
+
+ /*
+ * Environment that's being handled
+ */
+ SomeEnvironment<P>* environment;
+
+ /*
+ * concepts to change in the actual instant
+ */
+ std::vector<ConceptInstantHandler*> conceptsToChange;
+
+ /*
+ * actual concept being manipulated
+ */
+ ConceptInstantHandler* actualConcept;
+
+ /*
+ * if the actual concept has next
+ */
+ bool hasNext;
+ /*
+ * if the actual concept has previous
+ */
+ bool hasPrevious;
+
+ /*
+ * actual time of the reproduction
+ */
+ double actualTime;
+
+ /*
+ * time of pause
+ */
+ double pauseTime;
+
+ //====== PRIVATE METHODS=========
+ /*
+ * Sets if the instant has next or not
+ */
+
+ void setHasNext();
+ /*
+ * Sets if the instant has previous or not
+ */
+
+ void setHasPrevious();
+ /*
+ * actualize the actual index of the concepts handled
+ */
+ void setConceptsToChange();
+ /*
+ * resets all the next concepts to zero
+ */
+ void resetNextConcepts();
+ /*
+ * Sets the next index of concepts to handled to the maximum value
+ */
+ void setNextConcepts();
+ /*
+ * this method locates the new actual concept
+ * @param next, if has to locate the actual concept to the first concept that has next
+ * next=true, else search for the first concept that has previous
+ */
+ void toLocateActualConcept(bool next);
+
+
+ };
+//include the implementation of the template
+#include "InstantHandler_Txx.h"
+#endif
--- /dev/null
+/*=========================================================================
+
+ Program: instantHandler
+ Module: $RCSfile: InstantHandler_Txx.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: Handles the change of instant among the concept already inscribed
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+
+// SYSTEM INCLUDES
+
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+//#include "Instant.h"
+
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+ //====== LIFECYCLE ========
+
+ template<class P>
+ InstantHandler<P>::InstantHandler(SomeEnvironment<P>* environment)throw (ViewerNDimensionsException)
+ {
+
+ this->hasNext=true;
+ this->hasPrevious=true;
+ this->actualConcept=NULL;
+ this->actualTime=0.0;
+ this->pauseTime=0.0;
+ if(environment)
+ {
+ this->environment=environment;
+ this->actualInstant=new Instant(environment->getNumberOfConcepts());
+ }
+ else
+ {
+ this->environment=NULL;
+ this->actualInstant=NULL;
+ throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
+ }
+
+ }
+
+ template<class P>
+ InstantHandler<P>::~InstantHandler()
+ {
+ int i,size;
+ //deleting conceptsToChange
+ size=getSizeConceptsToChange();
+ for(i=0;i<size;i++)
+ {
+ if(conceptsToChange[i])
+ delete conceptsToChange[i];
+ }
+ this->conceptsToChange.clear();
+ //deleting actual concept
+ if(actualInstant) delete actualInstant;
+
+
+
+ }
+
+ //====== OPERATIONS =======
+ /*
+ * Adds a concept to handled in the instant, it means, when
+ * the next instant is used we are going to change this concepts in the instant
+ * PRECONDITION
+ * the calls to this functions are made in order of position, where the last position (it means
+ * the higher position defined) is the concept thats is going to handled the real time
+ * THE LAST POSITION HANDLEDS THE REAL TIME DOESNT MATTER THE CONCEPT
+ * EXAMPLE
+ * The user wants to reproduce doctors, pacients and time, and positions given are:
+ * 0=reproduce doctors, 1= reproduce pacients, 2= time, then 1,2 are going to be reproduced
+ * by PLUS PLUS, and time by REAL TIME
+ * @param nameConcept, name of the concept
+ * @param mode, mode of change
+ * @param position, position of reproduction
+ * @return true if succesful, false otherwise
+ */
+ template<class P>
+ bool InstantHandler<P>::addConceptToHandled(std::string nameConcept,int mode,int position) throw (ViewerNDimensionsException)
+ {
+ if(environment)
+ {
+ //creating the concept
+ ConceptInstantHandler* conceptInstantHandler=new ConceptInstantHandler(nameConcept,mode,position);
+ //looking for its index
+ int indexInInstant=environment->getIndexConcept(nameConcept);
+ if(indexInInstant!=-1)
+ conceptInstantHandler->setIndexInInstant(indexInInstant);
+ else
+ throw new ViewerNDimensionsException("ERROR CONCEPT ISN'T IN ENVIRONMENT");
+ //setting it maximums
+ int maximumIndex=environment->getSizeConcept(nameConcept);
+ if(maximumIndex!=-1)
+ conceptInstantHandler->setMaximumIndex(maximumIndex);
+ else
+ throw new ViewerNDimensionsException("ERROR CONCEPT ISN'T IN ENVIRONMENT");
+ //adding the concept
+ this->conceptsToChange.push_back(conceptInstantHandler);
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ actualInstant->setConcept(indexInInstant,conceptInstantHandler->geActualIndex());
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /*
+ * Next instant of the concepts to change
+ * PRECONDITION
+ * conceptsToChange is ordered by the position of the concepts handled
+ * @param
+ * @return
+ */
+ template<class P>
+ void InstantHandler<P>::nextInstant() throw (ViewerNDimensionsException)
+ {
+ if(actualConcept)
+ {
+ bool hasNextIndex=actualConcept->hasNextIndex();
+ int position=actualConcept->getPosition();
+ if(hasNextIndex)
+ {
+ actualConcept->nextIndex();
+ actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
+
+ }
+ else
+ {
+ while( (position-1)>=0 && !hasNextIndex)
+ {
+ actualConcept=conceptsToChange[position-1];
+ hasNextIndex=actualConcept->hasNextIndex();
+ position=actualConcept->getPosition();
+ }
+ if(hasNextIndex)
+ {
+ actualConcept->nextIndex();
+ actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
+ resetNextConcepts();
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ }
+ else
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+
+ }
+ setHasNext();
+ setHasPrevious();
+ }
+ else
+ throw new ViewerNDimensionsException("ERROR THERE ISN'T CONCEPTS TO HANDLED IN THE PLAYER");
+ }
+
+
+ /*
+ * Previous instant of the actual concept
+ * @param
+ * @return
+ */
+ template<class P>
+ void InstantHandler<P>::previousInstant()throw (ViewerNDimensionsException)
+ {
+ if(actualConcept)
+ {
+ bool hasPreviousIndex=actualConcept->hasPreviousIndex();
+ int position=actualConcept->getPosition();
+ if(hasPreviousIndex)
+ {
+ actualConcept->previousIndex();
+ actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
+
+ }
+ else
+ {
+ while( (position-1)>=0 && !hasPreviousIndex)
+ {
+ actualConcept=conceptsToChange[position-1];
+ hasPreviousIndex=actualConcept->hasPreviousIndex();
+ position=actualConcept->getPosition();
+ }
+ if(hasPreviousIndex)
+ {
+ actualConcept->previousIndex();
+ actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
+ setNextConcepts();
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ }
+ else
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+
+ }
+ setHasPrevious();
+ setHasNext();
+ }
+ else
+ throw new ViewerNDimensionsException("ERROR THERE ISN'T CONCEPTS TO HANDLED IN THE PLAYER");
+ }
+
+ /*
+ * Removes all the concept handled
+ */
+ template<class P>
+ void InstantHandler<P>::removeAllConcepts()
+ {
+ int size,i;
+ size=getSizeConceptsToChange();
+ for(i=0;i<size;i++)
+ {
+ if(conceptsToChange[i])
+ delete conceptsToChange[i];
+ }
+ conceptsToChange.clear();
+ actualConcept=NULL;
+
+ }
+
+ /*
+ * Removes the concept with the name given
+ * @param nameConcept, name of the concept to remove
+ * WARNING the user know wich concept is erasing, also knows the
+ * mode of other concepts, if the user is deleting the concept that
+ * handled the real time, should change the mode to other concept that exist
+ */
+ template<class P>
+ void InstantHandler<P>::removeConceptToHandled(std::string nameConcept)
+ {
+ int size,i;
+ size=getSizeConceptsToChange();
+ std::vector<ConceptInstantHandler*>::iterator iteratorConcepts=conceptsToChange.begin();
+ ConceptInstantHandler* concepti;
+ std::string nameConcepti;
+ bool isConcept=false;
+ for(i=0;i<size && !isConcept;i++)
+ {
+ concepti=conceptsToChange[i];
+ nameConcepti=concepti->getName();
+ if(nameConcepti.compare(nameConcept)==0)
+ {
+ if(actualConcept==concepti)
+ actualConcept=NULL;
+ conceptsToChange.erase(iteratorConcepts);
+ actualConcept=conceptsToChange[size-1];
+ isConcept=true;
+ }
+ iteratorConcepts++;
+ }
+ }
+
+ /*
+ * sets all the concept to handled in 0
+ */
+ template<class P>
+ void InstantHandler<P>::resetConceptsHandled()
+ {
+ int size,i;
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ int indexInInstant=-1;
+ for(i=0;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ concepti->setActualIndex(0);
+ indexInInstant=concepti->getIndexInInstant();
+ actualInstant->setConcept(indexInInstant,0);
+ }
+ setHasNext();
+ setHasPrevious();
+ }
+ /*
+ * Pause
+ */
+ /*
+ template<class P>
+ void InstantHandler<P>::pause()
+ {
+ time_t seconds=time(NULL);
+ pauseTime=seconds*1000;
+ }
+ */
+ //====== INQUIRY =========
+
+ /*
+ * get the actual instant fot the concept identified by the name
+ */
+ template<class P>
+ Instant* InstantHandler<P>::getActualInstant()throw (ViewerNDimensionsException)
+ {
+ if(this->actualInstant)
+ return this->actualInstant;
+ else
+ throw new ViewerNDimensionsException("ERROR ACTUAL INSTANT IS NOT SETTED");
+ }
+
+
+ /*
+ * If the actual concept has next instant, it means, if the index of the concept
+ * in the instant is in the maximum value
+ * @param nameConcept, concept for which we need to know if we are
+ * in its maximum value
+ * @return true if IS NOT in the maximum, false otherwise
+ */
+ template<class P>
+ bool InstantHandler<P>::hasNextInstant()
+ {
+ return hasNext;
+ }
+
+
+
+ /*
+ * If the concept has previous instant, it means, if the index of the concept
+ * in the instant is positive
+ * @param nameConcept, concept for which we need to know if we are
+ * in Zero
+ * @return true if IS NOT in zero, false otherwise
+ */
+ template<class P>
+ bool InstantHandler<P>::hasPreviousInstant()
+ {
+ return hasPrevious;
+ }
+ /*
+ * returns the number con conceptsToHandled
+ */
+ template<class P>
+ int InstantHandler<P>::getSizeConceptsToChange()
+ {
+ return conceptsToChange.size();
+ }
+ /*
+ * returns the number of possibles instants of the handler
+ * it depends of the concepts added in conceptsTochange
+ */
+ template<class P>
+ int InstantHandler<P>::getNumOfInstants()
+ {
+ int i,size,numInstants=1;
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ for(i=0;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ numInstants*=concepti->getMaximumIndex();
+ }
+ return numInstants;
+
+ }
+
+ /*
+ * Returns the names of the concepts handled and its modes
+ * DEPRECATED
+ */
+ template<class P>
+ void InstantHandler<P>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
+ {
+ int size,i;
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ for(i=0;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ namesConcepts.push_back(concepti->getName());
+ modes.push_back(concepti->getMode());
+ }
+ }
+ /*
+ * Returns the name of the concept that handled the real time
+ * DEPRECATED
+ */
+ template<class P>
+ void InstantHandler<P>::getTimeConcept(std::string& nameConcept)
+ {
+ ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
+ nameConcept=concept->getName();
+ }
+
+ //====== ACCESS ==========
+ /*
+ * Sets the environment that is going to be handled
+ * @param environment, a pointer to the environmen
+ * @return
+ */
+ template<class P>
+ void InstantHandler<P>::setEnvironment(SomeEnvironment<P>* environment)
+ {
+ this->environment=environment;
+ }
+ /*
+ * Sets the actual instant of the instant handler
+ */
+ template<class P>
+ void InstantHandler<P>::setActualInstant(Instant* instant)
+ {
+ if(!actualInstant)
+ actualInstant=new Instant(instant->getInstant());
+ else
+ {
+ int i,size;
+ size=actualInstant->getSize();
+ for(i=0;i<size;i++)
+ actualInstant->setConcept(i,instant->getIndexInConcept(i));
+ }
+ setConceptsToChange();
+ }
+
+ /*
+ * Sets the time of reproduction to the concept
+ * that depends of the real time of the reproduction
+ * (seconds)
+ * @param timeReproduction
+ */
+ template<class P>
+ void InstantHandler<P>::setTimeReproduction(double time)
+ {
+ if(getSizeConceptsToChange()>0)
+ {
+ ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
+ concept->setTimeReproduction(time);
+ }
+ }
+ /*
+ * Sets the actual time of the reproduction,
+ * is the real time (seconds)
+ * @param instant
+ */
+ template<class P>
+ void InstantHandler<P>::setActualTime(double actualTime)
+ {
+ ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
+ concept->setActualTime(actualTime);
+ this->actualTime=actualTime;
+ }
+ /*
+ * Set the mode of a concept that's being handled
+ */
+ template<class P>
+ void InstantHandler<P>::setModeOfConcept(std::string nameConcept,int mode)
+ {
+ int size,i;
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ std::string nameConcepti;
+ bool isConcept=false;
+ for(i=0;i<size && !isConcept;i++)
+ {
+ concepti=conceptsToChange[i];
+ nameConcepti=concepti->getName();
+ if(nameConcepti.compare(nameConcept)==0)
+ {
+ isConcept=true;
+ concepti->setMode(mode);
+ }
+
+ }
+ }
+ /*
+ * Set handler
+ */
+ template<class P>
+ void InstantHandler<P>::set()
+ {
+ if(getSizeConceptsToChange()!=0)
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ }
+ /*
+ * Set the increase Value for changing the instant
+ */
+ template<class P>
+ void InstantHandler<P>::setIncreaseValue(int increase)
+ {
+ int size,i;
+ size=conceptsToChange.size();
+ ConceptInstantHandler* concepti;
+ for(i=0;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ concepti->setIncreaseValue(increase);
+ }
+
+ }
+ /*
+ * Set the decrease Value for changing the instant
+ */
+ template<class P>
+ void InstantHandler<P>::setDecreaseValue(int decrease)
+ {
+ int size,i;
+ size=conceptsToChange.size();
+ ConceptInstantHandler* concepti;
+ for(i=0;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ concepti->setDecreaseValue(decrease);
+ }
+ }
+
+ //====== PRIVATE METHODS=========
+
+ /*
+ * Sets if the instant has next or not
+ */
+
+ template<class P>
+ void InstantHandler<P>::setHasNext()
+ {
+ int i, sizeConceptsToChange;
+ ConceptInstantHandler* concepti;
+ hasNext=false;
+ sizeConceptsToChange=getSizeConceptsToChange();
+ for(i=0;i<sizeConceptsToChange && !hasNext;i++)
+ {
+ concepti=conceptsToChange[i];
+ if(concepti->hasNextIndex())
+ hasNext=true;
+ }
+
+
+ }
+ /*
+ * Sets if the instant has previous or not
+ */
+ template<class P>
+ void InstantHandler<P>::setHasPrevious()
+ {
+ int i, sizeConceptsToChange;
+ ConceptInstantHandler* concepti;
+ hasPrevious=false;
+ sizeConceptsToChange=getSizeConceptsToChange();
+ for(i=0;i<sizeConceptsToChange && !hasPrevious;i++)
+ {
+ concepti=conceptsToChange[i];
+ if(concepti->hasPreviousIndex())
+ hasPrevious=true;
+ }
+ }
+ /*
+ * actualize the actual index of the concepts handled
+ */
+ template<class P>
+ void InstantHandler<P>::setConceptsToChange()
+ {
+ int i,sizeConceptsToChange, indexInInstant,indexInConcept;
+ sizeConceptsToChange=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ for(i=0;i<sizeConceptsToChange;i++)
+ {
+ concepti=conceptsToChange[i];
+ indexInInstant=concepti->getIndexInInstant();
+ indexInConcept=actualInstant->getIndexInConcept(indexInInstant);
+ concepti->setActualIndex(indexInConcept);
+ }
+ }
+ /*
+ * resets all the next concepts to zero
+ */
+ template<class P>
+ void InstantHandler<P>::resetNextConcepts()
+ {
+ int i,index,size;
+ index=actualConcept->getPosition();
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ for(i=index+1;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ concepti->setActualIndex(0);
+ concepti->resetInitialTime();
+ actualInstant->setConcept(concepti->getIndexInInstant(),0);
+ }
+
+ }
+ /*
+ * Sets the next index of concepts to handled to the maximum value
+ */
+ template<class P>
+ void InstantHandler<P>::setNextConcepts()
+ {
+ int i, index,size;
+ index=actualConcept->getPosition();
+ size=getSizeConceptsToChange();
+ ConceptInstantHandler* concepti;
+ for(i=index+1;i<size;i++)
+ {
+ concepti=conceptsToChange[i];
+ concepti->setActualIndex(concepti->getMaximumIndex()-1);
+ //concepti->resetInitialTime();
+ actualInstant->setConcept(concepti->getIndexInInstant(),concepti->geActualIndex());
+ }
+ }
+ /*
+ * this method locates the new actual concept
+ * @param next, if has to locate the actual concept to the first concept that has next
+ * next=true, else search for the first concept that has previous
+ */
+ template<class P>
+ void InstantHandler<P>::toLocateActualConcept(bool next)
+ {
+ int size=getSizeConceptsToChange();
+ if(next)
+ {
+
+ if(actualConcept)
+ {
+ bool hasNextIndex=actualConcept->hasNextIndex();
+ int position=actualConcept->getPosition();
+ while( (position-1)>=0 && !hasNextIndex)
+ {
+ actualConcept=conceptsToChange[position-1];
+ hasNextIndex=actualConcept->hasNextIndex();
+ position=actualConcept->getPosition();
+ }
+ }
+ else
+ {
+ if(size>0)
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ }
+ }
+ else
+ {
+ if(actualConcept)
+ {
+ bool hasPreviousIndex=actualConcept->hasPreviousIndex();
+ int position=actualConcept->getPosition();
+ while( (position-1)>=0 && !hasPreviousIndex)
+ {
+ actualConcept=conceptsToChange[position-1];
+ hasPreviousIndex=actualConcept->hasPreviousIndex();
+ position=actualConcept->getPosition();
+ }
+ }
+ else
+ {
+ if(size>0)
+ actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
+ }
+ }
+
+ }
+
+
+
--- /dev/null
+/*=========================================================================
+
+ Program: InstantPlayer
+ Module: $RCSfile: InstantPlayer.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: it do the play methods as stop,pause, play, etc using an instant handler
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+
+// MACRO
+#ifndef __INSTANTPLAYER_H_INCLUDED__
+#define __INSTANTPLAYER_H_INCLUDED__
+
+// SYSTEM INCLUDES
+
+
+
+// PROJECT INCLUDES
+
+#include "InstantHandler.h"
+#include "ViewerNDimensionsException.h"
+
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+template <class S>
+class InstantPlayer
+ {
+
+ public:
+ //====== CONSTANTS =======
+ const static int REAL_TIME=1;
+ const static int PLUS_PLUS=2;
+
+ //========= LYFECYCLE ==========
+ InstantPlayer(SomeEnvironment<S>* environment)throw (ViewerNDimensionsException);
+ ~InstantPlayer();
+
+
+ //========= OPERATIONS =========
+ /*
+ * When the user wants to play the dimensions selected by the user
+ * and are already defined
+ * @return
+ */
+ //void play();
+ /*
+ * Paused the reproduction of the dimension played
+ * @return
+ */
+ void pause();
+ /*
+ * Used for change to the next instant in the reproduction
+ * Note: next instant from the instant that's being reproduced
+ * @param loop , if want to do next instant with looping
+ * @return true if the player has changed of instant, false if not
+ */
+
+ bool nextInstant(bool loop=false)throw (ViewerNDimensionsException);
+ /*
+ * Used for change to the previous instant in the reproduction
+ * Note: previous instant from the instant that's being reproduced
+ * @return true if the player has changed of instant, false if not
+ */
+
+ bool previousInstant()throw (ViewerNDimensionsException);
+ /*
+ * Used for stops the reproduction
+ * POSTCONDITION
+ * in the index value in the index of the dimensin in the actual Instant
+ * is now 0
+ * @return
+ */
+ void stop();
+ /*
+ * Removes all the concepts handled
+ */
+ void removeAllConcepts();
+
+ /*
+ * Removes the concept with the name given
+ * @param nameConcept, name of the concept to remove
+ */
+ void removeConceptToHandled(std::string nameConcept);
+
+ //====== INQUIRY ========
+ /*
+ * Returns the things of the actual instant
+ */
+ std::vector<S*>* getThingsOfInstant()throw (ViewerNDimensionsException);
+ /*
+ * return the actual instant in the instant handler
+ */
+ Instant* getActualInstant()throw (ViewerNDimensionsException);
+ /*
+ * add new concept to handled
+ * @param nameConcept
+ * @param mode= REAL_TIME,PLUS_PLUS
+ * @param position, position in the player
+ */
+ bool addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException);
+ /*
+ * Returns the things of the actual instant and its names in the
+ * environment
+ */
+ void getThingsWithName(std::vector<std::string>& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException);
+ /*
+ * Returns the names of the concepts handled and its modes
+ * DEPRECATED
+ */
+ void getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes);
+ /*
+ * Returns the name of the concept that handled the real time
+ * DEPRECATED
+ */
+ void getTimeConcept(std::string& nameConcept);
+ /*
+ * get the number of instants that is playing
+ */
+ int getNumInstantsPlaying();
+
+ /*
+ * Returns the names of the concept with its respectively actual value
+ * @param conceptsAndIndexes is where is going to be save the data searched
+ */
+ void getConceptsActualIndexes(std::map<std::string,int>* conceptsAndIndexes)throw (ViewerNDimensionsException);
+
+ //========= ACCESS =========
+ /*
+ * Sets the time of reproduction of the concept
+ * that managed the real time
+ * @param time, is in milliseconds
+ */
+ void setTimeReproduction(double time);
+ /*
+ * Sets the environment
+ */
+ void setEnvironment(SomeEnvironment<S>* environmment);
+ /*
+ * Set Actual Instant
+ */
+ void setActualInstant(Instant* actualInstant);
+ /*
+ * Set Actual Instant
+ */
+ void setActualInstant(std::vector<int>* actualInstant);
+ /*
+ * Set the increase Value for changing the instant
+ */
+ void setIncreaseValue(int increase);
+ /*
+ * Set the decrease Value for changing the instant
+ */
+ void setDecreaseValue(int decrease);
+
+ /*
+ * Set the mode of a concept that's being handled
+ * DEPRECATED
+ */
+ //void setModeOfConcept(std::string nameConcept,int mode);
+ /*
+ * Set actual time to the instant handler
+ * DEPRECATED
+ */
+ //void setActualTime(double actualTime);
+ /*
+ * set the modes of the concept that handled the time
+ * to the plus plus mode or real time mode
+ * DEPRECATED
+ */
+ // void setTimeConceptToMode(int mode);
+
+
+
+ private:
+
+ /*
+ * environment
+ */
+
+ SomeEnvironment < S >* environment;
+
+ /*
+ * The instant handler
+ */
+ InstantHandler < S > * instantHandler;
+
+ /*
+ * time reproduction
+ * IS IN MILISECONDS
+ */
+ //double timeReproduction;
+
+ /*
+ * things of instant
+ */
+ //std::vector<S*>* thingsOfInstant;
+
+
+
+ };
+//include the implementation of the template
+#include "InstantPlayer_Txx.h"
+#endif
+
+
+
--- /dev/null
+/*=========================================================================
+
+ Program: InstantPlayer
+ Module: $RCSfile: InstantPlayer_Txx.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: it do the play methods as stop,pause, play, etc using an instant handler
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+// SYSTEM INCLUDES
+
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+
+ //========= LYFECYCLE ==========
+ template<class S>
+ InstantPlayer<S>::InstantPlayer(SomeEnvironment<S>* environment)throw (ViewerNDimensionsException)
+ {
+ this->environment=environment;
+ if(environment)
+ this->instantHandler= new InstantHandler<S>(this->environment);
+ else
+ throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
+ //this->thingsOfInstant=NULL;
+ //this->timeReproduction=100;
+ }
+
+ template<class S>
+ InstantPlayer<S>::~InstantPlayer()
+ {
+ if(instantHandler) delete instantHandler;
+ }
+
+
+ //========= OPERATIONS =========
+ /*
+ * When the user wants to play the dimensions selected by the user
+ * and are already defined
+ * @return
+ */
+ /*
+ template<class S>
+ void InstantPlayer<S>::play()
+ {
+ //setTimeConceptToMode(REAL_TIME);
+ instantHandler->nextInstant();
+ }
+ /*
+ * Paused the reproduction of the dimension played
+ * @return
+ */
+ template<class S>
+ void InstantPlayer<S>::pause()
+ {
+ //setTimeConceptToMode(PLUS_PLUS);
+ return;
+ }
+ /*
+ * Used for change to the next instant in the reproduction
+ * Note: next instant from the instant that's being reproduced
+ * @param loop , if want to do next instant with looping
+ * @return true if the player has changed of instant, false if not
+ */
+
+ template<class S>
+
+ bool InstantPlayer<S>::nextInstant(bool loop)throw (ViewerNDimensionsException)
+ {
+ //setTimeConceptToMode(PLUS_PLUS);
+ bool hasChanged=false;
+ bool hasNextInstant=instantHandler->hasNextInstant();
+ if(hasNextInstant)
+ {
+ instantHandler->nextInstant();
+ hasChanged=true;
+ }
+ else if(!loop)
+ instantHandler->set();
+ else if(loop)
+ {
+ instantHandler->resetConceptsHandled();
+ //instantHandler->set();
+ hasChanged=true;
+ }
+ return hasChanged;
+ }
+ /*
+ * Used for change to the previous instant in the reproduction
+ * Note: previous instant from the instant that's being reproduced
+ * @return true if the player has changed of instant, false if not
+ */
+ template<class S>
+ bool InstantPlayer<S>::previousInstant()throw (ViewerNDimensionsException)
+ {
+ //setTimeConceptToMode(PLUS_PLUS);
+ bool hasChanged=false;
+ bool hasPreviousInstant=instantHandler->hasPreviousInstant();
+ if(hasPreviousInstant)
+ {
+ instantHandler->previousInstant();
+ hasChanged=true;
+ }
+ else
+ instantHandler->set();
+ return hasChanged;
+
+ }
+ /*
+ * Used for stops the reproductioN
+ * @param
+ * @return
+ */
+ template<class S>
+ void InstantPlayer<S>::stop()
+ {
+ //setTimeConceptToMode(REAL_TIME);
+ instantHandler->resetConceptsHandled();
+
+ }
+ /*
+ * Removes all the concept handled
+ */
+ template<class S>
+ void InstantPlayer<S>::removeAllConcepts()
+ {
+ instantHandler->removeAllConcepts();
+
+ }
+
+ /*
+ * Removes the concept with the name given
+ * @param nameConcept, name of the concept to remove
+ */
+ template<class S>
+ void InstantPlayer<S>::removeConceptToHandled(std::string nameConcept)
+ {
+ instantHandler->removeConceptToHandled(nameConcept);
+ }
+ //====== INQUIRY ========
+
+ /*
+ * Returns the things of the actual instant
+ */
+ template<class S>
+ std::vector<S*>* InstantPlayer<S>::getThingsOfInstant() throw (ViewerNDimensionsException)
+ {
+ Instant* actualInstant= instantHandler->getActualInstant();
+ //load the things of the actual instant
+ return environment->getThings(actualInstant);
+ }
+
+ /*
+ * return the actual instant in the instant handler
+ */
+ template<class S>
+ Instant* InstantPlayer<S>::getActualInstant()throw (ViewerNDimensionsException)
+ {
+ return instantHandler->getActualInstant();
+ }
+ /*
+ * add new concept to handled
+ * @param nameConcept
+ * @param mode= REAL_TIME,PLUS_PLUS
+ * @param position, position in the player
+ */
+ template<class S>
+ bool InstantPlayer<S>::addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException)
+ {
+ return instantHandler->addConceptToHandled(nameConcept,mode,position);
+ }
+ /*
+ * Returns the things of the actual instants and its names in the
+ * environment
+ */
+ template<class S>
+ void InstantPlayer<S>::getThingsWithName(std::vector<std::string>& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException)
+ {
+ Instant* actualInstant= instantHandler->getActualInstant();
+ environment->getThings(names,thingsVector,actualInstant);
+ }
+ /*
+ * Returns the names of the concepts handled and its modes
+ * DEPRECATED
+ */
+ template<class S>
+ void InstantPlayer<S>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
+ {
+ instantHandler->getConceptsInfo(namesConcepts,modes);
+ }
+ /*
+ * Returns the name of the concept that handled the real time
+ * DEPRECATED
+ */
+ template<class S>
+ void InstantPlayer<S>::getTimeConcept(std::string& nameConcept)
+ {
+ instantHandler->getTimeConcept(nameConcept);
+ }
+ /*
+ * get the number of instants that is playing
+ */
+ template<class S>
+ int InstantPlayer<S>::getNumInstantsPlaying()
+ {
+ return instantHandler->getNumOfInstants();
+ }
+ /*
+ * Returns the names of the concept with its respectively actual value
+ * @param conceptsAndIndexes is where is going to be save the data searched
+ */
+ template<class S>
+ void InstantPlayer<S>::getConceptsActualIndexes(std::map<std::string,int>* conceptsAndIndexes)throw (ViewerNDimensionsException)
+ {
+ std::vector<std::string> conceptsNames;
+ environment->getConceptsNames(conceptsNames);
+ int instantIndex,i,size,index;
+ size=conceptsNames.size();
+ Instant* actualInstant= getActualInstant();
+ std::string conceptNamei;
+ for(i=0;i<size;i++)
+ {
+ conceptNamei=conceptsNames[i];
+ instantIndex=environment->getIndexConcept(conceptNamei);
+ index=actualInstant->getIndexInConcept(instantIndex);
+ conceptsAndIndexes->insert(std::pair<std::string,int>(conceptNamei,index));
+ conceptNamei.clear();
+
+ }
+
+ }
+
+ //========= ACCESS =========
+ /*
+ * Sets the time of reproduction of the concept
+ * that managed the real time
+ */
+ template<class S>
+ void InstantPlayer<S>::setTimeReproduction(double time)
+ {
+ //this->timeReproduction=time;
+ instantHandler->setTimeReproduction(time);
+ }
+ /*
+ * Sets the environment
+ */
+ template<class S>
+ void InstantPlayer<S>::setEnvironment(SomeEnvironment<S>* environmment)
+ {
+ this->environment=environmment;
+ }
+ /*
+ * Set Actual Instant
+ */
+ template<class S>
+ void InstantPlayer<S>::setActualInstant(Instant* actualInstant)
+ {
+ instantHandler->setActualInstant(actualInstant);
+ }
+ /*
+ * Set Actual Instant
+ */
+ template<class S>
+ void InstantPlayer<S>::setActualInstant(std::vector<int>* actualInstant)
+ {
+ Instant* instant=new Instant(actualInstant);
+ instantHandler->setActualInstant(instant);
+ delete instant;
+ }
+ /*
+ * Set the increase Value for changing the instant
+ */
+ template<class S>
+ void InstantPlayer<S>::setIncreaseValue(int increase)
+ {
+ instantHandler->setIncreaseValue(increase);
+ }
+ /*
+ * Set the decrease Value for changing the instant
+ */
+ template<class S>
+ void InstantPlayer<S>::setDecreaseValue(int decrease)
+ {
+ instantHandler->setDecreaseValue(decrease);
+ }
+
+ /*
+ * Set the mode of a concept that's being handled
+ */
+ /*
+ template<class S>
+ void InstantPlayer<S>::setModeOfConcept(std::string nameConcept,int mode)
+ {
+ instantHandler->setModeOfConcept(nameConcept,mode);
+ }
+ /*
+ * Set actual time to the instant handler
+ */
+ /*
+ template<class S>
+ void InstantPlayer<S>::setActualTime(double actualTime)
+ {
+ instantHandler->setActualTime(actualTime);
+ }
+ /*
+ * set the modes of the concept that handled the time
+ * to the plus plus mode
+ */
+ /*
+ template<class S>
+ void InstantPlayer<S>::setTimeConceptToMode(int mode)
+ {
+ std::string nameConcept;
+ getTimeConcept(nameConcept);
+ setModeOfConcept(nameConcept,mode);
+ }
+ */
--- /dev/null
+// MACRO
+#ifndef __READERENVIRONMENT_H_INCLUDED__
+#define __READERENVIRONMENT_H_INCLUDED__
+
+// SYSTEM INCLUDES
+
+// PROJECT INCLUDES
+#include <map>
+#include <iostream>
+#include <string>
+#include <fstream>
+
+// LOCAL INCLUDES
+//#ifndef __INSTANTHANDLER_H_INCLUDED
+#include "InstantHandler.h"
+//#endif
+
+// FORWARD REFERENCES
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+
+
+template<class T>
+class ReaderEnvironment
+ {
+ public:
+
+ //=========== CONSTANTS ==============
+ std::string NUMCONCEPTS;
+ std::string CONCEPT;
+ std::string OBJECT;
+ std::string NUMOBJECTS;
+ std::string NAME;
+ std::string SIZE;
+ std::string PATH;
+ std::string INSTANT;
+ std::string NUMINSTANTS;
+ std::string RANGE;
+ std::string COMMENT;
+ std::string EQUAL;
+ std::string POINT;
+ std::string ALL;
+
+ //====== LIFECYCLE ========
+
+ ReaderEnvironment(std::string nameConfigurationFile,std::map<std::string,T>* things);
+ ReaderEnvironment(std::string nameConceptFile,std::string nameObjectFile,std::map<std::string,T>* things);
+ ReaderEnvironment(std::string nameOtherConceptsFile, std::string nameConceptFile,std::string nameObjectFile, std::map<std::string,T>* things);
+ ~ReaderEnvironment();
+
+ //====== OPERATIONS =======
+ /*
+ * @return environment builded
+ */
+ SomeEnvironment<T>* getEnvironment();
+
+ //====== ACCESS ==========
+
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+ /*
+ * Environment
+ */
+ SomeEnvironment<T>* environment;
+ /*
+ * things of the environment
+ */
+ std::map<std::string,T>* things;
+ /*
+ * name of the configuration file
+ */
+ std::string nameConfigurationFile;
+ /*
+ * name of the configuration file for the objects
+ */
+ std::string nameObjectFile;
+ /*
+ * name of the configuration file for the concepts
+ */
+ std::string nameConceptFile;
+ /*
+ * name of the configuration file for other concepts
+ */
+ std::string nameOtherConceptsFile;
+
+ /*
+ * data in the file
+ */
+ std::map<std::string,std::string> dataInFile;
+ /*
+ * instant handler
+ */
+ InstantHandler<T>* instantHandler;
+ /*
+ * concepts number count
+ */
+ int numberOfConcepts;
+
+
+ //======== PRIVATE METHODS ==========
+ /*
+ * build the environment
+ */
+
+ void buildEnvironment();
+ /*
+ * read the configuration file
+ */
+ void readFile(std::string nameFile);
+
+ /*
+ * add the concepts of the file to the environment
+ */
+ bool addConcepts();
+ /*
+ * adds the things to the environment
+ */
+ bool addThings();
+ /*
+ * add the instants defined in the file for the name of the
+ * object given
+ * @param nameObject, name of the object for which we want to search
+ * its instant
+ */
+ bool addInstantToThing(std::string nameObject,std::string index);
+ /*
+ * build the instant from the string readed in the file
+ * @param instant, string with the description of the instant
+ * @param nameObject, name of the object for wich we can add an instant or several instants
+ * @return
+ */
+ bool addInstants(std::string nameObject,std::string instant);
+ /*
+ * Returns the instant object of the instant string given
+ * 1 1 1 1 and returns an instant object (1,1,1,1)
+ * @param instant, instant for which we want to construct an Instant object
+ */
+ Instant* getInstant(std::string instant);
+ /*
+ * Returns the number of the concept in the instant string read
+ * @param instant,instant where we are going to search the number of the
+ * concept that is in the position given
+ * @param position, position of the concept for which we want the number in the instant given
+ */
+ int getNumConcept(std::string& instant,int position );
+ /*
+ * Returns the name of the concept in the concepts defined given the number
+ * of the concept in the instant
+ * @param nameConcept, string where is going to be load the name of the concept
+ * @param numConcept, number of the concept in the instant for which we are looking
+ * for the name
+ */
+
+ void getConceptName(std::string& nameConcept,int numConcept);
+
+ /*
+ * Returns the number of decimals places of the number given
+ */
+ int getNumberOfDecimalPlaces(int number);
+
+ /*
+ * Clean the line readed from the file
+ */
+ void cleanLine(std::string & line);
+
+
+
+ };
+//include the implementation of the template
+#include "ReaderEnvironment_Txx.h"
+#endif
+
+
+
--- /dev/null
+// SYSTEM INCLUDES
+
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+
+
+
+ //====== LIFECYCLE ========
+ template<class T>
+ ReaderEnvironment<T>::ReaderEnvironment(std::string nameConfigurationFile,std::map<std::string,T>* things)
+ {
+ this->nameConfigurationFile=nameConfigurationFile;
+ this->things=things;
+ this->instantHandler=NULL;
+ this->nameOtherConceptsFile = nameOtherConceptsFile;
+ this->environment= new SomeEnvironment<T>();
+ //constants
+ NUMCONCEPTS="numConcepts";
+ CONCEPT="concept";
+ OBJECT="object";
+ NUMOBJECTS="numObjects";
+ NAME="name";
+ SIZE="size";
+ PATH="path";
+ INSTANT="instant";
+ NUMINSTANTS="numInstants";
+ RANGE="r";
+ COMMENT="#";
+ EQUAL="=";
+ POINT=".";
+ ALL="all";
+ nameOtherConceptsFile = "";
+ numberOfConcepts = 0;
+
+ //build the environment
+ buildEnvironment();
+ }
+ template<class T>
+ ReaderEnvironment<T>::ReaderEnvironment(std::string nameConceptFile,std::string nameObjectFile,std::map<std::string,T>* things)
+ {
+ this->nameConceptFile=nameConceptFile;
+ this->nameObjectFile=nameObjectFile;
+ this->things=things;
+ this->nameOtherConceptsFile = nameOtherConceptsFile;
+ this->environment= new SomeEnvironment<T>();
+ //constants
+ NUMCONCEPTS="numConcepts";
+ CONCEPT="concept";
+ OBJECT="object";
+ NUMOBJECTS="numObjects";
+ NAME="name";
+ SIZE="size";
+ PATH="path";
+ INSTANT="instant";
+ NUMINSTANTS="numInstants";
+ RANGE="r";
+ COMMENT="#";
+ EQUAL="=";
+ POINT=".";
+ ALL="all";
+ nameOtherConceptsFile = "";
+ numberOfConcepts = 0;
+ //build the environment
+ buildEnvironment();
+
+ }
+ template<class T>
+ ReaderEnvironment<T> :: ReaderEnvironment(std::string nameOtherConceptsFile, std::string nameConceptFile,std::string nameObjectFile, std::map<std::string,T>* things)
+ {
+ this->nameConceptFile=nameConceptFile;
+ this->nameObjectFile=nameObjectFile;
+ this->nameOtherConceptsFile = nameOtherConceptsFile;
+ this->things=things;
+ this->environment= new SomeEnvironment<T>();
+ //constants
+ NUMCONCEPTS="numConcepts";
+ CONCEPT="concept";
+ OBJECT="object";
+ NUMOBJECTS="numObjects";
+ NAME="name";
+ SIZE="size";
+ PATH="path";
+ INSTANT="instant";
+ NUMINSTANTS="numInstants";
+ RANGE="r";
+ COMMENT="#";
+ EQUAL="=";
+ POINT=".";
+ ALL="all";
+ numberOfConcepts = 0;
+ //build the environment
+ buildEnvironment();
+ }
+ template<class T>
+ ReaderEnvironment<T>::~ReaderEnvironment()
+ {
+ //deletes the things
+ things->clear();
+ if(things) delete this->things;
+ nameConceptFile.clear();
+ nameConfigurationFile.clear();
+ nameObjectFile.clear();
+ dataInFile.clear();
+ nameOtherConceptsFile.clear();
+ if(instantHandler) delete instantHandler;
+
+ }
+
+ //====== OPERATIONS =======
+ /*
+ * @return environment builded
+ */
+ template<class T>
+ SomeEnvironment<T>* ReaderEnvironment<T>::getEnvironment()
+ {
+ return this->environment;
+ }
+ /*
+ * build the environment
+ */
+ template<class T>
+ void ReaderEnvironment<T>::buildEnvironment()
+ {
+
+ //read the file
+ if(!nameConfigurationFile.empty())
+ readFile(nameConfigurationFile);
+ else
+ {
+ readFile(nameConceptFile);
+ readFile(nameObjectFile);
+ if(!nameOtherConceptsFile.empty())
+ {
+ readFile(nameOtherConceptsFile);
+ }
+ }
+ //adding the data of the concepts to the environment
+ addConcepts();
+ //setting the instant handler
+ this->instantHandler=new InstantHandler<T>(environment);
+ //adding the things to the environment
+ addThings();
+
+ }
+ //======== PRIVATE METHODS ==============
+
+ /*
+ * build the instant from the string readed in the file
+ * @param instant, string with the description of the instant
+ * @param nameObject, name of the object for wich we can add an instant or several instants
+ * @return
+ * TODO: when is an r(i j) and when the user doesnt write all the information
+ * of the instants it is considered like an all
+ * for example, there is 3 concepts, the data complete for an instant is of size 3
+ * but the user can write only an index of the first concept, the others is assumed
+ * to be all, is like instant= i, then it is assumed like instant= i all all
+ */
+
+
+ template<class T>
+ bool ReaderEnvironment<T>::addInstants(std::string nameObject,std::string instant)
+ {
+
+ int indexAll,numConcept,sizeConcept=-1,i,k=0;
+
+ //copying the string of the instant
+ std::string instantCopy=instant;
+ //finding alls
+ indexAll=instantCopy.find(ALL);
+ std::string concept;
+ char* indexConcept=(char*)malloc(sizeof(char));
+ Instant* instantThing;
+ //if have an all
+
+ if(indexAll!=-1)
+ {
+ std::string nameConcept;
+ //setting the first instant of the handler, using all the all's defined in the string
+ while(indexAll!=-1)
+ {
+ //itoa(0,indexConcept,10); // itoa not ANSI
+ sprintf(indexConcept, "%d", 0);
+ instantCopy.replace(indexAll,ALL.size(),indexConcept);
+ numConcept=getNumConcept(instantCopy,indexAll);
+ getConceptName( nameConcept,numConcept);
+ //setting the instanHandler
+ instantHandler->addConceptToHandled(nameConcept,2,k);
+ k++;
+ nameConcept.clear();
+ indexAll=instantCopy.find(ALL);
+ }
+
+
+ //starting instant
+ instantThing=getInstant(instantCopy);
+ //adding to the environment
+ if(instantThing)
+ {
+ if(environment->getNumberOfConcepts()== instantThing->getSize())
+ {
+ environment->addInstantToThing(nameObject,instantThing);
+ //starting the actual instant
+ instantHandler->setActualInstant(instantThing);
+ }
+ //else THROW EXCEPTION
+ }
+ //else THROW AN EXCEPTION
+ //deleting memory
+ delete instantThing;
+ //calculatig the number of instants
+
+ int numInstants=instantHandler->getNumOfInstants();
+
+ //calculating all the instants
+ for(i=1;i<numInstants;i++)
+ {
+ instantHandler->nextInstant();
+ instantThing=instantHandler->getActualInstant();
+ //borrame
+ int sizeI=instantThing->getSize();
+ for(int j=0;j<sizeI;j++)
+ int q=instantThing->getIndexInConcept(j);
+ //
+ environment->addInstantToThing(nameObject,instantThing);
+ }
+ }
+
+ //doesnt have an all
+ else
+ {
+ instantThing=getInstant(instantCopy);
+ if(instantThing)
+ {
+ environment->addInstantToThing(nameObject,instantThing);
+ delete instantThing;
+ }
+
+ //else throw an exception
+
+ }
+ return true;
+
+ }
+
+ /*
+ * Returns the name of the concept in the concepts defined given the number
+ * of the concept in the instant
+ * @param nameConcept, string where is going to be load the name of the concept
+ * @param numConcept, number of the concept in the instant for which we are looking
+ * for the name
+ */
+ template<class T>
+ void ReaderEnvironment<T>::getConceptName(std::string& nameConcept,int numConcept)
+ {
+ int ncs,conceptIndexInEnvironment,i;
+
+ //getting the names of the concept defined
+ std::vector<std::string> nameConcepts;
+ environment->getConceptsNames(nameConcepts);
+ //name of the concept i
+ std::string nameConcepti;
+ ncs=nameConcepts.size();
+ bool isConcept=false;
+ for(i=0;i< ncs && !isConcept;i++)
+ {
+ nameConcepti=nameConcepts[i];
+ conceptIndexInEnvironment=environment->getIndexConcept(nameConcepti);
+ if(conceptIndexInEnvironment==numConcept)
+ isConcept=true;
+ else
+ nameConcepti.clear();
+ }
+ if(isConcept)
+ nameConcept=nameConcepti;
+ nameConcepti.clear();
+ }
+
+ /*
+ * Returns the number of the concept in the instant string read
+ * @param instant,instant where we are going to search the number of the
+ * concept that is in the position given
+ * @param position, position of the concept (string position) for which we want the number in the instant given
+ * @return the number of concept in the instant
+ */
+ template<class T>
+ int ReaderEnvironment<T>::getNumConcept(std::string& instant,int position )
+ {
+ int splitIndex,counter=0;
+ splitIndex=instant.rfind(" ",position);
+ while(splitIndex>=0)
+ {
+ counter++;
+ if(splitIndex>0)
+ splitIndex=instant.rfind(" ",splitIndex-1);
+ if(splitIndex==0)
+ splitIndex=-1;
+ }
+ return counter;
+ }
+
+ /*
+ * Returns the instant object of the instant string given
+ * 1 1 1 1 and returns an instant object (1,1,1,1)
+ * @param instant, instant for which we want to construct an Instant object
+ * @return an Instant's object
+ * TODO validation of indexes in instant
+ */
+ template<class T>
+ Instant* ReaderEnvironment<T>:: getInstant(std::string instant)
+ {
+ int value,splitIndex;
+ //getting the names of the concept defined
+ std::vector<std::string> nameConcepts;
+ environment->getConceptsNames(nameConcepts);
+ //instant vector
+ std::vector<int>* instantVector=new std::vector<int>();
+
+ std::string concept;
+ splitIndex=instant.find(" ");
+ bool stop=false;
+ int k=0;
+ bool isValid= true;
+ while(!stop && isValid)
+ {
+ if(splitIndex==-1)
+ stop=true;
+
+ concept=instant.substr(0,splitIndex);
+ instant.erase(0,splitIndex+1);
+ value=atoi(concept.c_str());
+ isValid=environment->isValidIndex(value,k);
+ if(isValid)
+ instantVector->push_back(value);
+ splitIndex=instant.find(" ");
+ k++;
+ }
+ Instant* instantThing;
+ if(stop)
+ {
+ instantThing= new Instant(instantVector);
+ delete instantVector;
+ }
+ else
+ instantThing=NULL;
+ return instantThing;
+ }
+
+ /*
+ * add the instants defined in the file for the name of the
+ * object given
+ * @param nameObject, name of the object for which we want to search
+ * its instant
+ */
+ template<class T>
+ bool ReaderEnvironment<T>::addInstantToThing(std::string nameObject,std::string index)
+ {
+ int numInstants,i;
+ std::map<std::string,std::string>::iterator iteratorData;
+ bool added=true;
+
+ //getting the number of instants for the object given
+
+ std::string s(OBJECT + index + POINT + NUMINSTANTS);
+ iteratorData=dataInFile.find(s);
+
+ if(iteratorData!=dataInFile.end())
+ {
+ std::string numIns=iteratorData->second;
+ numInstants=atoi(numIns.c_str());
+ numIns.clear();
+ }
+ //else throw exception
+ //getting the instants
+ s.clear();
+ std::string instant;
+
+ //finding the number of decimals places
+ int num=getNumberOfDecimalPlaces(numInstants);
+ char* indexi=(char*)malloc(sizeof(char)*(num+1));
+ //std::string indexiStr;
+ for(i=1;i<=numInstants && added;i++)
+ {
+ //itoa(i,indexi,10);
+ sprintf(indexi, "%d", i);
+ //indexiStr=indexi;
+ s=OBJECT+index+POINT+INSTANT+indexi;
+ iteratorData=dataInFile.find(s);
+ if(iteratorData!=dataInFile.end())
+ {
+ instant=iteratorData->second;
+ addInstants(nameObject,instant);
+
+ }
+ s.clear();
+ instant.clear();
+ }
+ free(indexi);
+ if(i==numInstants+1)
+ return true;
+ else
+ return false;
+
+ }
+
+ /*
+ * adds the things to the environment
+ */
+ template<class T>
+ bool ReaderEnvironment<T>::addThings()
+ {
+ int numObjects,j;
+ bool addedInstants=true;
+ typename std::map<std::string,std::string>::iterator iteratorData;
+ typename std::map<std::string,T>::iterator iteratorThings;
+ //getting the number of objects
+ iteratorData=dataInFile.find(NUMOBJECTS);
+ if(iteratorData!=dataInFile.end())
+ {
+ std::string numObj=iteratorData->second;
+ numObjects=atoi(numObj.c_str());
+ numObj.clear();
+ }
+ //finding the number of decimals places
+ int num=getNumberOfDecimalPlaces(numObjects);
+ //getting the objects if does come like objects
+ if(things)
+ {
+
+ char* index= (char*)malloc(sizeof(char)*(num+1));
+ std::string objectData;
+ std::string nameObjecti;
+ for(j=1;j<=numObjects && addedInstants;j++)
+ {
+ //itoa(j,index,10);
+ int num2=sprintf(index, "%d", j);
+ objectData=OBJECT+index+POINT+NAME;
+ iteratorData=dataInFile.find(objectData);
+ if(iteratorData!=dataInFile.end())
+ {
+ nameObjecti=iteratorData->second;
+ iteratorThings=things->find(nameObjecti);
+ if(iteratorThings!=things->end())
+ {
+ environment->addThing(nameObjecti,iteratorThings->second);
+ //indexS=index;
+ addedInstants=addInstantToThing(nameObjecti,index);
+ }
+ //throwException
+ //the names given en execution and of the file should be the same
+ //else
+ }
+ objectData.clear();
+ }
+ objectData.clear();
+ free(index);
+ if(j==numObjects+1)
+ return true;
+
+ else
+ return false;
+
+ }
+ //if we have to charge it from a file
+ //if is like that we should ask for the objecti.path
+ //else
+
+ return false;
+ }
+
+
+
+ /*
+ * adds the concepts of the file to the environment
+ */
+ template<class T>
+ bool ReaderEnvironment<T>::addConcepts()
+ {
+ int numConcepts,i;
+ std::map<std::string,std::string>::iterator iteratorData;
+ //getting the number of concepts defined
+ iteratorData=dataInFile.find(NUMCONCEPTS);
+ if(iteratorData!=dataInFile.end())
+ {
+ std::string numberOfConcepts=iteratorData->second;
+ numConcepts=atoi(numberOfConcepts.c_str());
+ }
+ //finding the number of decimals places
+ int num=getNumberOfDecimalPlaces(numConcepts);
+ std::string conceptData;
+ char* index=(char*)malloc(sizeof(char)*(num+1));
+ std::string nameConcepti;
+ std::string sizeConcepti;
+ for(i=1;i<=numConcepts;i++)
+ {
+
+ //itoa(i,index,10);
+ sprintf(index, "%d", i);
+ //finding the name
+ conceptData=CONCEPT+index+POINT+NAME;
+ iteratorData=dataInFile.find(conceptData);
+ if(iteratorData!=dataInFile.end())
+ nameConcepti=iteratorData->second;
+ //finding the size
+ conceptData.clear();
+ conceptData=CONCEPT+index+POINT+SIZE;
+ iteratorData=dataInFile.find(conceptData);
+ if(iteratorData!=dataInFile.end())
+ sizeConcepti=iteratorData->second;
+ //adding the concept
+ environment->addConcept(nameConcepti,atoi(sizeConcepti.c_str()));
+ conceptData.clear();
+ nameConcepti.clear();
+ sizeConcepti.clear();
+
+ }
+
+ free(index);
+ if(i==numConcepts+1)
+ return true;
+ else
+ return false;
+
+
+ }
+ /*
+ * read the configuration file
+ */
+ template<class T>
+ void ReaderEnvironment<T>::readFile(std::string nameFile)
+ {
+ bool readingOtherConcepts = nameFile.compare(this->nameOtherConceptsFile) == 0;
+ bool readingConcepts = nameFile.compare(this->nameConceptFile) == 0 || readingOtherConcepts;
+ bool findedConceptOcurrence = false;
+ int posPoint=0;
+ int conceptValue=0;
+ //std::string conceptKeyPart = "";
+ int pos;
+ //reader of the file
+ std::ifstream configFile;
+ //each line of the file
+ std::string line;
+ //string of the data to save
+ std::string data;
+ //string with the key of the map
+ std::string key;
+ //line size
+ int lineSize=0;
+ //opening the file
+
+ if(nameFile.compare("")!=0)
+ {
+ configFile.open(nameFile.c_str());
+ if(!configFile.is_open())
+ {
+ //should throw an exception
+ return ;
+ }
+ else
+ {
+ //THIS ONLY SAVES NUMBERS OF ONE DIGIT
+ //FIXME
+ char* index= (char*)malloc(sizeof(char)*5);
+ char* dataString= (char*)malloc(sizeof(char)*10);
+ while(!configFile.eof())
+ {
+ //line.clear();
+ std::getline(configFile,line);
+ cleanLine(line);
+ pos=line.find(EQUAL);
+ lineSize=line.size();
+ //if is not a comment
+
+ int c=line.find(COMMENT);
+ if (c !=std::string::npos )
+ findedConceptOcurrence = false;
+
+ else//if(c<0 && pos>=0)
+ {
+ data=line.substr(pos+1,lineSize);
+ key=line.substr(0,pos);
+ if ( readingConcepts && (key.rfind( CONCEPT ))!=std::string::npos )
+ {
+
+ if( (key.rfind( NAME ))!=std::string::npos )
+ {
+ if ( !findedConceptOcurrence )
+ {
+ numberOfConcepts++;
+ findedConceptOcurrence = true;
+ //itoa(numberOfConcepts,index,10);
+ sprintf (index, "%d", numberOfConcepts);
+ }
+ if ( readingOtherConcepts )
+ key = CONCEPT + index + POINT + NAME;
+ }
+ else if ( (key.rfind( SIZE ))!=std::string::npos )
+ {
+ if ( !findedConceptOcurrence)
+ {
+ numberOfConcepts++;
+ findedConceptOcurrence = true;
+ // itoa(numberOfConcepts,index,10);
+ sprintf(index, "%d", numberOfConcepts);
+ }
+ if ( readingOtherConcepts )
+ key = CONCEPT + index + POINT + SIZE;
+ }
+
+ }
+
+
+ int antes = dataInFile.size();
+ if(!key.empty())
+ {
+ if( readingOtherConcepts && key.rfind(NUMCONCEPTS)!=std::string::npos )
+ {
+ int otherConceptsValue = atoi(data.c_str());
+ //itoa(numberOfConcepts+otherConceptsValue,dataString,10);
+ sprintf(dataString,"%d", numberOfConcepts+otherConceptsValue);
+ data = dataString;
+ std::map<std::string,std::string>::iterator iter = dataInFile.find(key);
+ dataInFile.erase(iter);
+ }
+ dataInFile.insert(std::pair<std::string,std::string>(key,data));
+ }
+ int despues = dataInFile.size();
+ //cleaning the data and the key variables
+ data.clear();
+ key.clear();
+ }
+
+
+ }
+ free(index);
+ free(dataString);
+ configFile.close();
+ }
+ }
+ }
+ /*
+ * Returns the number of decimals places of the number given
+ */
+ template<class T>
+ int ReaderEnvironment<T>::getNumberOfDecimalPlaces(int number)
+ {
+ int i=0;
+ while(number>0)
+ {
+ number=number/10;
+ i++;
+ }
+ if(i==0)
+ i=1;
+ return i;
+
+ }
+ /*
+ * Clean the line readed from the file
+ */
+ template<class T>
+ void ReaderEnvironment<T>::cleanLine(std::string & line)
+ {
+ int pos1,pos2,size;
+ pos1=line.find_first_not_of(" ");
+ line.erase(0,pos1);
+ pos2=line.find_last_not_of(" ");
+ size=line.length();
+ line.erase(pos2+1,size-1);
+ }
+
--- /dev/null
+// MACRO
+
+#ifndef __SOMEENVIRONMENT_H_INCLUDED__
+#define __SOMEENVIRONMENT_H_INCLUDED__
+
+// SYSTEM INCLUDES
+
+ #include <iostream>
+ #include <map>
+ #include <vector>
+ #include <string>
+
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+#include "SomeThing.h"
+
+
+// FORWARD REFERENCES
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+
+
+template <class T>
+
+class SomeEnvironment
+ {
+ public:
+ //====== LIFECYCLE ========
+ SomeEnvironment();
+
+ SomeEnvironment(std::map<std::string,int>* concepts,std::map< std::string,SomeThing<T> >* things);
+
+ ~SomeEnvironment();
+
+ //====== OPERATIONS =======
+ /*
+ * Adds a thing to the program
+ * @param name: name of the thing
+ * @param thing: thing to be added
+ * @return true if the thing was succesfully added
+ */
+
+
+ bool addThing(std::string name,T thing);
+
+
+ /*
+ * 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
+ */
+
+ bool addInstantToThing(std::string name,Instant* instant);
+
+ /*
+ * 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
+ */
+
+ bool addThingWithInstant(std::string name,T thing,Instant* instant);
+
+ /*
+ * 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
+ */
+
+
+ bool addConcept(std::string name, int size);
+
+ //bool addConceptToThing(std::string nameConcept,std::string nameThing,int indexInConcept);
+
+ /*
+ * Validate the index of a concept in an instant
+ */
+ bool isValidIndex(int index, int indexInInstant);
+
+ //====== INQUIRY =========
+
+ /*
+ * Get the things of that instant
+ * @param instant: the instant for wich we need to know its things
+ * @return thingsOfInstant: a vector with the pointers to the things
+ * of the instant asked
+ */
+ std::vector<T*>* getThings(Instant* instant);
+
+ /*
+ * 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
+ * @parama instant, instant for wich
+ * @return
+ */
+ void getThings(std::vector<std::string>& names,std::vector<T*>& thingsVector,Instant* instant);
+
+ /*
+ * 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
+ * NOTE SENDS THE POINT TO A COPY OF THE VECTORS OF INSTANTS
+ */
+
+ std::vector<Instant*>* getInstantsOfThing(std::string nameThing);
+
+ /*
+ * Returns the instants define in the environment
+ * @return existing instants in the environment
+ */
+
+ std::vector<Instant*>* getExistingInstants();
+
+ /*
+ * Returns the size of the concept identified by nameConcept
+ * @param nameConcept, name of the concept in the environment
+ * @return size, of the concept given
+ */
+ int getSizeConcept(std::string nameConcept);
+
+ /*
+ * returns the index of the concept in the instants
+ */
+ int getIndexConcept(std::string nameConcept);
+
+ /*
+ * Give the names of the names defined
+ * @param nameConcepts, vector where is goin to be save the names of the concepts
+ */
+ void getConceptsNames(std::vector<std::string>& namesConcepts);
+
+ /*
+ * 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
+ */
+ void getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect);
+
+ /*
+ * returns all the things of the environment
+ * @param vector where is going to be charge the things
+ * PRECONDITION
+ * thingsVector is empty
+ */
+ void getThingsOfEnvironment(std::vector<T*>* thingsVector);
+
+ /*
+ * returns a pointer to the thing with the name given
+ */
+ T* getThingByName(std::string name);
+ /*
+ * returns the number of concepts defined
+ */
+ int getNumberOfConcepts();
+
+ /*
+ * Gets the number of things
+ * @return Returns the number of existing things in the environment
+ */
+ int getNumberOfThings ();
+
+ //====== 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 doesnt exist)
+ */
+
+ bool removeThing(std::string name);
+
+ /*
+ * 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)
+ */
+
+ bool removeThingFromInstant(std::string name, Instant* instant);
+
+
+ /*
+ * 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)
+ */
+ bool removeInstant(Instant* instant);
+
+
+ /*
+ * TODO
+ * Change the instant (any index of any concept) for all the things
+ * that should be find in that instant
+ * @param indexInstant: index of the instant in the existing instants
+ * in the environment
+ * @param indexConcept: index of the concept in the instant to be changed
+ * @param indexInConcept: which value between 0-sizeConcept is going to be saved
+ * @return
+ */
+ void changeInstantForAllThings(int indexInstant, int indexConcept, int indexInConcept);
+
+
+ //void changeInstantOnlyForThing(std::string nameThing, Instant* instant, int indexConcept,);
+ /*
+ * 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
+ */
+
+ bool removeConcept(std::string nameConcept);
+
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+
+ /*
+ * Concepts that was defined
+ * Saving in like (nameConcept,sizeConcept), where the key
+ * is the name of the concept
+ */
+
+ std::map<std::string,int> concepts;
+ /*
+ * The things that this concepts handle
+ * EXAMPLE
+ * in visualization the concepts handle actors, it means that
+ * the actor are them things, but things also store the thing's name
+ * PRECONDITION
+ * each thing has a unique name, and is stored like (nameThing,Thing)
+ * where the key is the name of the thing
+ */
+
+ std::map < std::string,SomeThing<T> > things;
+
+ /*
+ * this is the things of the instant asked
+ * use for returning the data
+ */
+ std::vector<T*> thingsOfInstant;
+
+ /*
+ * this vector saves the instants that
+ * are defined in the Environment
+ */
+ std::vector<Instant*> existingInstants;
+
+ /*
+ * is the relation between the the indexes of the instants and the
+ * concepts in the environment
+ */
+ std::map<std::string,int> indexesConcepts;
+
+ //====== 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
+ */
+ bool isInInstant(SomeThing<T>* something,Instant *instant);
+
+ /*
+ * Remove the instant from the environment
+ * @param instant, to be erased
+ * @return
+ */
+ void removeInstantFromExistingInstants(Instant* instant);
+
+ /*
+ * Adds an instant to the existing instants, verifying if
+ * the instant is already added
+ * @param instant, to be added
+ * @return the index of that instant in the existing instants in the
+ * environment
+ */
+ int addInstant(Instant* instant);
+ /*
+ * 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)
+ */
+ int getIndexInstantInExistingInstants(Instant* instant);
+
+
+
+
+
+
+ };
+//include the implementation of the template
+#include "SomeEnvironment_Txx.h"
+#endif
--- /dev/null
+
+// SYSTEM INCLUDES
+
+#include <map>
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+ //====== LIFECYCLE ========
+ template<class T>
+ SomeEnvironment<T>::SomeEnvironment()
+ {
+ }
+ template<class T>
+ SomeEnvironment<T>::SomeEnvironment(std::map<std::string,int>* concepts,std::map< std::string,SomeThing<T> >* things)
+ {
+ this->concepts=concepts;
+ this->things=things;
+ }
+
+ template<class T>
+ SomeEnvironment<T>::~SomeEnvironment()
+ {
+
+ int size,i;
+
+ //deleting existing instants
+ size=existingInstants.size();
+ for(i=0;i<size;i++)
+ delete existingInstants[i];
+ existingInstants.clear();
+ //deleting concepts
+ concepts.clear();
+ //deleting things
+ things.clear();
+ //indexes of concept
+ indexesConcepts.clear();
+ //things of instant
+ thingsOfInstant.clear();
+ }
+
+ //====== OPERATIONS =======
+ /*
+ * Adds a thing to the program
+ * @param name: name of the thing
+ * @param thing: thing to be added
+ * @return true if the thing was succesfully added
+ */
+
+ template<class T>
+ bool SomeEnvironment<T>:: addThing(std::string name,T thing)
+ {
+ SomeThing<T> something (name);
+ something.setThing(thing);
+ things.insert(std::pair < std::string, SomeThing<T> >(name,something));
+ return true;
+
+ }
+
+ /*
+ * 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<class T>
+ bool SomeEnvironment<T>::addInstantToThing(std::string name,Instant* instant)
+ {
+ typename std::map< std::string,SomeThing<T> >::iterator thingsIterator;
+ thingsIterator=things.find(name);
+ if(thingsIterator != things.end())
+ {
+
+
+ SomeThing<T>* 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<class T>
+ bool SomeEnvironment<T>::addThingWithInstant(std::string name,T thing,Instant* instant)
+ {
+ SomeThing<T> 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<T> >(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<class T>
+ bool SomeEnvironment<T>::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<class T>
+ bool SomeEnvironment<T>::isValidIndex(int index, int indexInInstant)
+ {
+ std::map<std::string,int>::iterator conceptsIterator=concepts.begin();
+ std::map<std::string,int>::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<size)
+ return true;
+ else
+ return false;
+ }
+ conceptNamei.clear();
+ conceptsIterator++;
+ }
+ return false;
+
+ }
+
+ //====== INQUIRY =========
+
+ template<class T>
+ std::vector<T*>* SomeEnvironment<T>::getThings(Instant* instant)
+ {
+ //cleaning things of instant
+ thingsOfInstant.clear();
+ //
+
+ typename std::map < std::string,SomeThing<T> >::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<T>* something=&thingsIterator->second;
+
+ 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<class T>
+ void SomeEnvironment<T>::getThings(std::vector< std::string >& names,std::vector< T* >& thingsVector, Instant* instant)
+ {
+ typename std::map < std::string,SomeThing<T> >::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<T>* 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<class T>
+ std::vector<Instant*>* SomeEnvironment<T>::getInstantsOfThing(std::string nameThing)
+ {
+ typename std::map < std::string,SomeThing<T> >::iterator thingsIterator;
+ thingsIterator=things.find(nameThing);
+ if(thingsIterator!=things.end())
+ {
+ SomeThing<T>* something=&thingsIterator->second;
+ return something->getInstants();
+ }
+ return (std::vector<Instant*>*)NULL;
+ }
+
+ /*
+ * Returns the instants define in the environment
+ * @return existing instants in the environment
+ * A POINTER TO THE EXISTINGINSTANTS
+ */
+ template<class T>
+ std::vector<Instant*>* SomeEnvironment<T>::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<class T>
+ int SomeEnvironment<T>::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<class T>
+ int SomeEnvironment<T>::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<class T>
+ void SomeEnvironment<T>::getConceptsNames(std::vector<std::string>& namesConcepts)
+ {
+ std::map<std::string,int>::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<class T>
+ void SomeEnvironment<T> :: getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect)
+ {
+ std::map<std::string,int>::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++;
+ }
+ }
+
+ /*
+ * returns all the things of the environment
+ */
+ template<class T>
+ void SomeEnvironment<T>::getThingsOfEnvironment(std::vector<T*>* thingsVector)
+ {
+ typename std::map<std::string, SomeThing<T> >::iterator iteratorThings= things.begin();
+ thingsVector->clear();
+ while(iteratorThings!=things.end())
+ {
+ SomeThing<T>* something=&iteratorThings->second;
+ T* thing=something->getThing();
+ thingsVector->push_back(thing);
+ iteratorThings++;
+ }
+
+ }
+ /*
+ * returns a pointer to the thing with the name given
+ */
+ template<class T>
+ T* SomeEnvironment<T>::getThingByName(std::string name)
+ {
+ T* thing=NULL;
+ typename std::map<std::string, SomeThing<T> >::iterator iteratorThings= things.find(name);
+ if(iteratorThings!=things.end())
+ {
+ SomeThing<T>* something=&iteratorThings->second;
+ thing=something->getThing();
+ }
+ return thing;
+ }
+
+
+ /*
+ * 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++)
+ 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++)
+ 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;
+ }
+
+
--- /dev/null
+// MACRO
+
+#ifndef __SOMETHING_H_INCLUDED__
+#define __SOMETHING_H_INCLUDED__
+
+// SYSTEM INCLUDES
+
+// PROJECT INCLUDES
+
+#include <vector>
+#include <iostream>
+
+// LOCAL INCLUDES
+#include "Instant.h"
+
+
+// FORWARD REFERENCES
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+
+
+
+template <class U>
+class SomeThing
+ {
+ public:
+
+
+ //====== LIFECYCLE ========
+
+ SomeThing(std::string name);
+
+
+ ~SomeThing();
+
+
+
+ //====== OPERATIONS =======
+
+ /*
+ * Add a new instant to the thing
+ * @param instant: new instant
+ */
+
+ bool addInstant(Instant* instant);
+
+
+ //====== INQUIRY =========
+ /*
+ * Get the thing stored
+ * @return thing
+ */
+
+ U* getThing();
+
+ /*
+ * Get the name of the thing
+ * @return nameThing
+ */
+
+ std::string getName();
+
+ /*
+ * Get all the instants
+ * @return instants
+ */
+
+ std::vector<Instant*>* getInstants();
+
+ /*
+ * Get the instant that's in the index given
+ * @param indexInstant: index of the instant that they want
+ * @return instants[instantIndex]
+ */
+
+ Instant* getInstant(int indexInstant);
+
+ /*
+ * Get the number of instants that the
+ * thng has.
+ * @return instants.size()
+ */
+
+ int getNumberInstants();
+
+ /*
+ * if this is in the instant given
+ * @param instant: instant to verified if this has it
+ * @return 0<=i<numberOfInstants if this has the instant, -1 otherwise
+ */
+
+ int hasInstant(Instant* instant);
+
+ //====== ACCESS ==========
+ /*
+ * Set the thing
+ * @param U* thing
+ */
+
+ void setThing(U thing);
+
+ /*
+ * Set the name of the thing
+ * @param nameThing
+ */
+
+ void setName(std::string name);
+
+ /*
+ * Set the instants of the thing
+ * @param instants
+ */
+
+ void setInstants(std::vector<Instant*> instants);
+
+ /*
+ * Remove an instant from the thing
+ * @param indexInstant: index of the instant to be removed
+ * @return true if succesful , false otherwise
+ */
+
+ bool removeInstant(int indexInstant);
+
+ /*
+ * Remove an instant from the thing
+ * @param instant: instant to be deleted
+ * @return true if succesful , false otherwise
+ */
+
+ bool removeInstant(Instant* instant);
+
+
+ private:
+
+ //======= ATTRIBUTES=======
+ /*
+ * name of the something
+ * WARNING
+ * has to be different from the
+ * other existing somethings in the program
+ * using the handler
+ */
+ std::string nameThing;
+ /*
+ * the thing that we are handling
+ * it could be any object
+ */
+ U thing;
+ /*
+ * instants that the thing
+ * has defined
+ */
+ std::vector<Instant*> instantsVector;
+
+ };
+//include the implementation of the template
+#include "SomeThing_Txx.h"
+#endif
+
+
+
--- /dev/null
+
+
+// SYSTEM INCLUDES
+/*
+ #include <vector>
+ #include <iostream>
+*/
+// PROJECT INCLUDES
+
+//#include "Instant.h"
+
+// LOCAL INCLUDES
+
+
+// FORWARD REFERENCES
+
+/*
+* COMMENT
+* @param
+* @return
+*/
+
+ //====== LIFECYCLE ========
+ template <class U>
+ SomeThing<U>::SomeThing(std::string name)
+ {
+ nameThing=name;
+ }
+
+ template <class U>
+ SomeThing<U>::~SomeThing()
+ {
+
+ instantsVector.clear();
+ nameThing.clear();
+
+ }
+
+
+ //====== OPERATIONS =======
+
+ /*
+ * Add a new instant to the thing
+ * @param instant: new instant
+ */
+ template <class U>
+ bool SomeThing<U>::addInstant(Instant* instant)
+ {
+ //borrame
+ int sizeInstant=instant->getSize();
+ for(int i=0;i<sizeInstant;i++)
+ int j=instant->getIndexInConcept(i);
+ //
+ int index= hasInstant(instant);
+ if(index==-1)
+ this->instantsVector.push_back(instant);
+ return true;
+ }
+
+ //====== INQUIRY =========
+ /*
+ * Get the thing stored
+ * @return thing
+ */
+ template <class U>
+ U* SomeThing<U>::getThing()
+ {
+ return &thing;
+ }
+ /*
+ * Get the name of the thing
+ * @return nameThing
+ */
+ template <class U>
+ std::string SomeThing<U>::getName()
+ {
+ return nameThing;
+ }
+ /*
+ * Get all the instants
+ * @return instants
+ */
+ template <class U>
+ std::vector<Instant*>* SomeThing<U>::getInstants()
+ {
+ return &instantsVector;
+ }
+ /*
+ * Get the instant that's in the index given
+ * @param indexInstant: index of the instant that they want
+ * @return instants[instantIndex]
+ */
+ template <class U>
+ Instant* SomeThing<U>::getInstant(int indexInstant)
+ {
+ return instantsVector[indexInstant];
+ }
+ /*
+ * Get the number of instants that the
+ * thng has.
+ * @return instants.size()
+ */
+ template <class U>
+ int SomeThing<U>::getNumberInstants()
+ {
+ return this->instantsVector.size();
+
+ }
+ /*
+ * if this is in the instant given
+ * @param instant: instant to verified if this has it
+ * @return 0<=i<numberOfInstants if this has the instant, -1 otherwise
+ */
+ template <class U>
+ int SomeThing<U>::hasInstant(Instant* instant)
+ {
+ int i;
+ int sizeInstants=this->getNumberInstants();
+ bool isEquals=false;
+ for(i=0;i<sizeInstants;i++)
+ {
+ Instant* instanti=this->getInstant(i);
+ isEquals=instanti->isEquals(instant);
+ if(isEquals)
+ return i;
+ }
+ return -1;
+ }
+ //====== ACCESS ==========
+ /*
+ * Set the thing
+ * @param U* thing
+ */
+ template <class U>
+ void SomeThing<U>::setThing(U thing)
+ {
+ this->thing=thing;
+ }
+ /*
+ * Set the name of the thing
+ * @param nameThing
+ */
+ template <class U>
+ void SomeThing<U>::setName(std::string name)
+ {
+ this->nameThing=name;
+ }
+ /*
+ * Set the instants of the thing
+ * @param instants
+ */
+ template <class U>
+ void SomeThing<U>::setInstants(std::vector<Instant*> instants)
+ {
+ this->instantsVector=instants;
+ }
+ /*
+ * Remove an instant from the thing
+ * @param indexInstant: index of the instant to be removed
+ * @return true if succesful , false otherwise
+ */
+ template <class U>
+ bool SomeThing<U>::removeInstant(int indexInstant)
+ {
+ int i;
+ std::vector<Instant*>::iterator instantsIterator=this->instantsVector.begin();
+ int sizeInstants=this->getNumberInstants();
+ for(i=0;i<sizeInstants;i++)
+ {
+ if(i==indexInstant)
+ {
+ this->instantsVector.erase(instantsIterator);
+ return true;
+ }
+ instantsIterator++;
+ }
+ return false;
+ }
+ /*
+ * Remove an instant from the thing
+ * @param instant: instant to be deleted
+ * @return true if succesful , false otherwise
+ */
+ template <class U>
+ bool SomeThing<U>::removeInstant(Instant* instant)
+ {
+ int index=hasInstant(instant);
+ if(index!=-1)
+ {
+ removeInstant(index);
+ return true;
+ }
+ return false;
+ }
+
+
--- /dev/null
+/*=========================================================================
+
+ Program: ViewerNDimensionsException
+ Module: $RCSfile: ViewerNDimensionsException.h,v $
+ Language: C++
+ Date: $Date: 2008/10/31 15:08:40 $
+ Version: $Revision: 1.1 $
+ Objective: Exception of the program when something has setted wrong
+ Authot: Monica Maria Lozano Romero
+
+ Copyright: (c) 2007
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+
+=========================================================================*/
+
+#ifndef __VIEWERNDIMENSIONS_H__INCLUDED
+#define __VIEWERNDIMENSIONS_H__INCLUDED
+
+// SYSTEM INCLUDES
+
+#include <iostream>
+#include <exception>
+
+// PROJECT INCLUDES
+
+
+// LOCAL INCLUDES
+
+// FORWARD REFERENCES
+
+//NAMESPACE
+
+
+ class ViewerNDimensionsException: public std::exception
+ {
+ public:
+ //====== LIFECYCLE ========
+ ViewerNDimensionsException(std::string msg)
+ {
+ this->msg=msg;
+ }
+ //======= INQUIRY ===========
+ virtual const char* what() const throw()
+ {
+ return msg.c_str();
+ }
+
+ private:
+ /*
+ * msg to return
+ */
+ std::string msg;
+ };//viewerNDimensionsException;
+#endif
\ No newline at end of file