From f23e62ed22294c025c467c2bed69be676be8fba8 Mon Sep 17 00:00:00 2001 From: Juan Prieto Date: Fri, 31 Oct 2008 15:08:31 +0000 Subject: [PATCH] *** empty log message *** --- CMakeLists.txt | 35 + appli/template_appli/CMakeLists.txt | 33 + appli/template_wx_appli/CMakeLists.txt | 40 ++ lib/CMakeLists.txt | 2 + lib/kernel_Environment/CMakeLists.txt | 81 +++ .../ConceptInstantHandler.cxx | 304 ++++++++ .../ConceptInstantHandler.h | 286 ++++++++ lib/kernel_Environment/EnvironmentHandler.h | 86 +++ .../EnvironmentHandler_Txx.h | 119 +++ .../HandlerConceptsException.h | 39 + lib/kernel_Environment/Instant.cxx | 164 +++++ lib/kernel_Environment/Instant.h | 116 +++ lib/kernel_Environment/InstantHandler.h | 286 ++++++++ lib/kernel_Environment/InstantHandler_Txx.h | 662 +++++++++++++++++ lib/kernel_Environment/InstantPlayer.h | 228 ++++++ lib/kernel_Environment/InstantPlayer_Txx.h | 336 +++++++++ lib/kernel_Environment/ReaderEnvironment.h | 182 +++++ .../ReaderEnvironment_Txx.h | 678 ++++++++++++++++++ lib/kernel_Environment/SomeEnvironment.h | 319 ++++++++ lib/kernel_Environment/SomeEnvironment_Txx.h | 619 ++++++++++++++++ lib/kernel_Environment/SomeThing.h | 166 +++++ lib/kernel_Environment/SomeThing_Txx.h | 196 +++++ .../ViewerNDimensionsException.h | 59 ++ 23 files changed, 5036 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 appli/template_appli/CMakeLists.txt create mode 100644 appli/template_wx_appli/CMakeLists.txt create mode 100644 lib/CMakeLists.txt create mode 100644 lib/kernel_Environment/CMakeLists.txt create mode 100644 lib/kernel_Environment/ConceptInstantHandler.cxx create mode 100644 lib/kernel_Environment/ConceptInstantHandler.h create mode 100644 lib/kernel_Environment/EnvironmentHandler.h create mode 100644 lib/kernel_Environment/EnvironmentHandler_Txx.h create mode 100644 lib/kernel_Environment/HandlerConceptsException.h create mode 100644 lib/kernel_Environment/Instant.cxx create mode 100644 lib/kernel_Environment/Instant.h create mode 100644 lib/kernel_Environment/InstantHandler.h create mode 100644 lib/kernel_Environment/InstantHandler_Txx.h create mode 100644 lib/kernel_Environment/InstantPlayer.h create mode 100644 lib/kernel_Environment/InstantPlayer_Txx.h create mode 100644 lib/kernel_Environment/ReaderEnvironment.h create mode 100644 lib/kernel_Environment/ReaderEnvironment_Txx.h create mode 100644 lib/kernel_Environment/SomeEnvironment.h create mode 100644 lib/kernel_Environment/SomeEnvironment_Txx.h create mode 100644 lib/kernel_Environment/SomeThing.h create mode 100644 lib/kernel_Environment/SomeThing_Txx.h create mode 100644 lib/kernel_Environment/ViewerNDimensionsException.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e7beb4d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +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 diff --git a/appli/template_appli/CMakeLists.txt b/appli/template_appli/CMakeLists.txt new file mode 100644 index 0000000..3b02804 --- /dev/null +++ b/appli/template_appli/CMakeLists.txt @@ -0,0 +1,33 @@ +#---------------------------------------------------------------------------- +# 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} ) +#---------------------------------------------------------------------------- + + diff --git a/appli/template_wx_appli/CMakeLists.txt b/appli/template_wx_appli/CMakeLists.txt new file mode 100644 index 0000000..fd728c2 --- /dev/null +++ b/appli/template_wx_appli/CMakeLists.txt @@ -0,0 +1,40 @@ +#---------------------------------------------------------------------------- +# 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} ) +#---------------------------------------------------------------------------- + + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..777742c --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,2 @@ +# Add a SUBDIRS command for each of your libraries +SUBDIRS(kernel_Environment) diff --git a/lib/kernel_Environment/CMakeLists.txt b/lib/kernel_Environment/CMakeLists.txt new file mode 100644 index 0000000..53973d6 --- /dev/null +++ b/lib/kernel_Environment/CMakeLists.txt @@ -0,0 +1,81 @@ +#---------------------------------------------------------------------------- +# 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} ) diff --git a/lib/kernel_Environment/ConceptInstantHandler.cxx b/lib/kernel_Environment/ConceptInstantHandler.cxx new file mode 100644 index 0000000..91f5fa7 --- /dev/null +++ b/lib/kernel_Environment/ConceptInstantHandler.cxx @@ -0,0 +1,304 @@ + + +// SYSTEM INCLUDES +#include +#include +#include +#include +#include +#include + +// 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(actualIndex0) + 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; + } + + + + diff --git a/lib/kernel_Environment/ConceptInstantHandler.h b/lib/kernel_Environment/ConceptInstantHandler.h new file mode 100644 index 0000000..59c6860 --- /dev/null +++ b/lib/kernel_Environment/ConceptInstantHandler.h @@ -0,0 +1,286 @@ +/*========================================================================= + + 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 +#include +#include +#include + +// 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 diff --git a/lib/kernel_Environment/EnvironmentHandler.h b/lib/kernel_Environment/EnvironmentHandler.h new file mode 100644 index 0000000..624e2a4 --- /dev/null +++ b/lib/kernel_Environment/EnvironmentHandler.h @@ -0,0 +1,86 @@ + + +// SYSTEM INCLUDES +#include +#include +#include +#include + +// PROJECT INCLUDES + +#include "EnvironmentEnvironmentHandler" + +// LOCAL INCLUDES + +// FORWARD REFERENCES + +/* +* COMMENT +* @param +* @return +*/ +#ifndef __EnvironmentHandler_h__INCLUDED +template + +class EnvironmentHandler + { + public: + //====== LIFECYCLE ======== + EnvironmentHandler(SomeEnvironment

* environment); + ~EnvironmentHandler(); + + //====== OPERATIONS ======= + /* + * change the actual intants associated to the + * names given + */ + void nextInstants(std::vector 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& 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 actualInstants; + /* + * Environment that's being handled + */ + + SomeEnvironment

* environment; + //====== PRIVATE METHODS========= + + + }; +//include the implementation of the template +#include "EnvironmentHandler_Txx.h" +#endif diff --git a/lib/kernel_Environment/EnvironmentHandler_Txx.h b/lib/kernel_Environment/EnvironmentHandler_Txx.h new file mode 100644 index 0000000..27621b0 --- /dev/null +++ b/lib/kernel_Environment/EnvironmentHandler_Txx.h @@ -0,0 +1,119 @@ +// SYSTEM INCLUDES + + +// PROJECT INCLUDES + + +// LOCAL INCLUDES +#include "Instant.h" + + +// FORWARD REFERENCES + +//NAMESPACE + + //====== LIFECYCLE ======== + template + EnvironmentHandler

::EnvironmentHandler(SomeEnvironment

* environment) + { + this->environment=environment; + } + + template + EnvironmentHandler

::~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 + void EnvironmentHandler

::nextInstants(std::vector nameConcepts) + { + int size,i,indexConcept,indexInConcept,sizeConcept; + size=nameConcepts.size(); + std::map::iterator actualInstantsIterator; + std::string nameConcepti; + for(i=0;isecond; + indexConcept=environment->getIndexConcept(nameConcepti); + indexInConcept=instant->getIndexInConcept(indexConcept); + indexInConcept++; + sizeConcept=environment->getSizeConcept(nameConcepti); + if(indexInConceptsetConcept(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 + void EnvironmentHandler

::addActualInstantOfCOncept(std::string nameConcept,Instant* instant) + { + actualInstants.insert(std::pair(nameConcept,instant)); + } + + /* + * removes the pair in the map of actual concepts + */ + template + void EnvironmentHandler

::removeActualInstantOfConcept(std::string nameConcept) + { + std::map::iterator actualInstantsIterator=actualInstants.find(nameConcept); + if(actualInstantsIterator!=actualInstants.end()) + actualInstants.erase(actualInstantsIterator); + + } + //====== INQUIRY ========= + /* + * get all the actual instants + */ + template + void EnvironmentHandler

::getActualsInstants(std::vector& instantsVector) + { + + std::map::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 + Instant* EnvironmentHandler

::getActualInstant(std::string nameConcept) + { + std::map::iterator actualInstantsIterator=actualInstants.find(nameConcept); + if(actualInstantsIterator!=actualInstants.end()) + { + return instant=actualInstantsIterator->second; + + } + else + return (Instant*)NULL; + } + //====== ACCESS ========== + \ No newline at end of file diff --git a/lib/kernel_Environment/HandlerConceptsException.h b/lib/kernel_Environment/HandlerConceptsException.h new file mode 100644 index 0000000..9d04d2c --- /dev/null +++ b/lib/kernel_Environment/HandlerConceptsException.h @@ -0,0 +1,39 @@ + +// SYSTEM INCLUDES + +#include +#include +// 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 diff --git a/lib/kernel_Environment/Instant.cxx b/lib/kernel_Environment/Instant.cxx new file mode 100644 index 0000000..6629a00 --- /dev/null +++ b/lib/kernel_Environment/Instant.cxx @@ -0,0 +1,164 @@ + + +// SYSTEM INCLUDES + + +// PROJECT INCLUDES +#include +#include + +// LOCAL INCLUDES +#include "Instant.h" + +// FORWARD REFERENCES +//NAMESPACE + + + + + //====== LIFECYCLE ======== + + Instant::Instant(std::vector* instant) + { + nTuple=new std::vector(); + setInstant(instant); + } + + Instant::Instant() + { + nTuple=new std::vector(); + } + + Instant::Instant(int size) + { + nTuple= new std::vector(); + int i; + for(i=0;ipush_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* 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;igetIndexInConcept(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* instant) + { + int i,size; + size=instant->size(); + for(i=0;ipush_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::iterator conceptsIterator=nTuple->begin(); + int size=nTuple->size(); + for(i=0;ierase(conceptsIterator); + return true; + } + conceptsIterator++; + } + return false; + } diff --git a/lib/kernel_Environment/Instant.h b/lib/kernel_Environment/Instant.h new file mode 100644 index 0000000..ac4993b --- /dev/null +++ b/lib/kernel_Environment/Instant.h @@ -0,0 +1,116 @@ + + +// SYSTEM INCLUDES + +/* + #include + #include +*/ + +// 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* 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* 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* 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* nTuple; + + }; +#endif + + + diff --git a/lib/kernel_Environment/InstantHandler.h b/lib/kernel_Environment/InstantHandler.h new file mode 100644 index 0000000..053ea9a --- /dev/null +++ b/lib/kernel_Environment/InstantHandler.h @@ -0,0 +1,286 @@ +/*========================================================================= + + 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 +#include +#include +#include + +// PROJECT INCLUDES + +#include "SomeEnvironment.h" +#include "ConceptInstantHandler.h" +#include "ViewerNDimensionsException.h" + +// LOCAL INCLUDES + +// FORWARD REFERENCES + + + +/* +* COMMENT +* @param +* @return +*/ + +template + +class InstantHandler + { + public: + //========== CONSTANTS ======= + + //====== LIFECYCLE ======== + InstantHandler(SomeEnvironment

* 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& namesConcepts,std::vector& 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

* 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

* environment; + + /* + * concepts to change in the actual instant + */ + std::vector 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 diff --git a/lib/kernel_Environment/InstantHandler_Txx.h b/lib/kernel_Environment/InstantHandler_Txx.h new file mode 100644 index 0000000..6c33f6f --- /dev/null +++ b/lib/kernel_Environment/InstantHandler_Txx.h @@ -0,0 +1,662 @@ +/*========================================================================= + + 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 + InstantHandler

::InstantHandler(SomeEnvironment

* 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 + InstantHandler

::~InstantHandler() + { + int i,size; + //deleting conceptsToChange + size=getSizeConceptsToChange(); + for(i=0;iconceptsToChange.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 + bool InstantHandler

::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 + void InstantHandler

::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 + void InstantHandler

::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 + void InstantHandler

::removeAllConcepts() + { + int size,i; + size=getSizeConceptsToChange(); + for(i=0;i + void InstantHandler

::removeConceptToHandled(std::string nameConcept) + { + int size,i; + size=getSizeConceptsToChange(); + std::vector::iterator iteratorConcepts=conceptsToChange.begin(); + ConceptInstantHandler* concepti; + std::string nameConcepti; + bool isConcept=false; + for(i=0;igetName(); + 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 + void InstantHandler

::resetConceptsHandled() + { + int size,i; + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + int indexInInstant=-1; + for(i=0;isetActualIndex(0); + indexInInstant=concepti->getIndexInInstant(); + actualInstant->setConcept(indexInInstant,0); + } + setHasNext(); + setHasPrevious(); + } + /* + * Pause + */ + /* + template + void InstantHandler

::pause() + { + time_t seconds=time(NULL); + pauseTime=seconds*1000; + } + */ + //====== INQUIRY ========= + + /* + * get the actual instant fot the concept identified by the name + */ + template + Instant* InstantHandler

::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 + bool InstantHandler

::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 + bool InstantHandler

::hasPreviousInstant() + { + return hasPrevious; + } + /* + * returns the number con conceptsToHandled + */ + template + int InstantHandler

::getSizeConceptsToChange() + { + return conceptsToChange.size(); + } + /* + * returns the number of possibles instants of the handler + * it depends of the concepts added in conceptsTochange + */ + template + int InstantHandler

::getNumOfInstants() + { + int i,size,numInstants=1; + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + for(i=0;igetMaximumIndex(); + } + return numInstants; + + } + + /* + * Returns the names of the concepts handled and its modes + * DEPRECATED + */ + template + void InstantHandler

::getConceptsInfo(std::vector& namesConcepts,std::vector& modes) + { + int size,i; + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + for(i=0;igetName()); + modes.push_back(concepti->getMode()); + } + } + /* + * Returns the name of the concept that handled the real time + * DEPRECATED + */ + template + void InstantHandler

::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 + void InstantHandler

::setEnvironment(SomeEnvironment

* environment) + { + this->environment=environment; + } + /* + * Sets the actual instant of the instant handler + */ + template + void InstantHandler

::setActualInstant(Instant* instant) + { + if(!actualInstant) + actualInstant=new Instant(instant->getInstant()); + else + { + int i,size; + size=actualInstant->getSize(); + for(i=0;isetConcept(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 + void InstantHandler

::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 + void InstantHandler

::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 + void InstantHandler

::setModeOfConcept(std::string nameConcept,int mode) + { + int size,i; + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + std::string nameConcepti; + bool isConcept=false; + for(i=0;igetName(); + if(nameConcepti.compare(nameConcept)==0) + { + isConcept=true; + concepti->setMode(mode); + } + + } + } + /* + * Set handler + */ + template + void InstantHandler

::set() + { + if(getSizeConceptsToChange()!=0) + actualConcept=conceptsToChange[getSizeConceptsToChange()-1]; + } + /* + * Set the increase Value for changing the instant + */ + template + void InstantHandler

::setIncreaseValue(int increase) + { + int size,i; + size=conceptsToChange.size(); + ConceptInstantHandler* concepti; + for(i=0;isetIncreaseValue(increase); + } + + } + /* + * Set the decrease Value for changing the instant + */ + template + void InstantHandler

::setDecreaseValue(int decrease) + { + int size,i; + size=conceptsToChange.size(); + ConceptInstantHandler* concepti; + for(i=0;isetDecreaseValue(decrease); + } + } + + //====== PRIVATE METHODS========= + + /* + * Sets if the instant has next or not + */ + + template + void InstantHandler

::setHasNext() + { + int i, sizeConceptsToChange; + ConceptInstantHandler* concepti; + hasNext=false; + sizeConceptsToChange=getSizeConceptsToChange(); + for(i=0;ihasNextIndex()) + hasNext=true; + } + + + } + /* + * Sets if the instant has previous or not + */ + template + void InstantHandler

::setHasPrevious() + { + int i, sizeConceptsToChange; + ConceptInstantHandler* concepti; + hasPrevious=false; + sizeConceptsToChange=getSizeConceptsToChange(); + for(i=0;ihasPreviousIndex()) + hasPrevious=true; + } + } + /* + * actualize the actual index of the concepts handled + */ + template + void InstantHandler

::setConceptsToChange() + { + int i,sizeConceptsToChange, indexInInstant,indexInConcept; + sizeConceptsToChange=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + for(i=0;igetIndexInInstant(); + indexInConcept=actualInstant->getIndexInConcept(indexInInstant); + concepti->setActualIndex(indexInConcept); + } + } + /* + * resets all the next concepts to zero + */ + template + void InstantHandler

::resetNextConcepts() + { + int i,index,size; + index=actualConcept->getPosition(); + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + for(i=index+1;isetActualIndex(0); + concepti->resetInitialTime(); + actualInstant->setConcept(concepti->getIndexInInstant(),0); + } + + } + /* + * Sets the next index of concepts to handled to the maximum value + */ + template + void InstantHandler

::setNextConcepts() + { + int i, index,size; + index=actualConcept->getPosition(); + size=getSizeConceptsToChange(); + ConceptInstantHandler* concepti; + for(i=index+1;isetActualIndex(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 + void InstantHandler

::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]; + } + } + + } + + + diff --git a/lib/kernel_Environment/InstantPlayer.h b/lib/kernel_Environment/InstantPlayer.h new file mode 100644 index 0000000..9c5766b --- /dev/null +++ b/lib/kernel_Environment/InstantPlayer.h @@ -0,0 +1,228 @@ +/*========================================================================= + + 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 InstantPlayer + { + + public: + //====== CONSTANTS ======= + const static int REAL_TIME=1; + const static int PLUS_PLUS=2; + + //========= LYFECYCLE ========== + InstantPlayer(SomeEnvironment* 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* 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& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException); + /* + * Returns the names of the concepts handled and its modes + * DEPRECATED + */ + void getConceptsInfo(std::vector& namesConcepts,std::vector& 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* 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* environmment); + /* + * Set Actual Instant + */ + void setActualInstant(Instant* actualInstant); + /* + * Set Actual Instant + */ + void setActualInstant(std::vector* 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* thingsOfInstant; + + + + }; +//include the implementation of the template +#include "InstantPlayer_Txx.h" +#endif + + + diff --git a/lib/kernel_Environment/InstantPlayer_Txx.h b/lib/kernel_Environment/InstantPlayer_Txx.h new file mode 100644 index 0000000..ae3361d --- /dev/null +++ b/lib/kernel_Environment/InstantPlayer_Txx.h @@ -0,0 +1,336 @@ +/*========================================================================= + + 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 + InstantPlayer::InstantPlayer(SomeEnvironment* environment)throw (ViewerNDimensionsException) + { + this->environment=environment; + if(environment) + this->instantHandler= new InstantHandler(this->environment); + else + throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL"); + //this->thingsOfInstant=NULL; + //this->timeReproduction=100; + } + + template + InstantPlayer::~InstantPlayer() + { + if(instantHandler) delete instantHandler; + } + + + //========= OPERATIONS ========= + /* + * When the user wants to play the dimensions selected by the user + * and are already defined + * @return + */ + /* + template + void InstantPlayer::play() + { + //setTimeConceptToMode(REAL_TIME); + instantHandler->nextInstant(); + } + /* + * Paused the reproduction of the dimension played + * @return + */ + template + void InstantPlayer::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 + + bool InstantPlayer::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 + bool InstantPlayer::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 + void InstantPlayer::stop() + { + //setTimeConceptToMode(REAL_TIME); + instantHandler->resetConceptsHandled(); + + } + /* + * Removes all the concept handled + */ + template + void InstantPlayer::removeAllConcepts() + { + instantHandler->removeAllConcepts(); + + } + + /* + * Removes the concept with the name given + * @param nameConcept, name of the concept to remove + */ + template + void InstantPlayer::removeConceptToHandled(std::string nameConcept) + { + instantHandler->removeConceptToHandled(nameConcept); + } + //====== INQUIRY ======== + + /* + * Returns the things of the actual instant + */ + template + std::vector* InstantPlayer::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 + Instant* InstantPlayer::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 + bool InstantPlayer::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 + void InstantPlayer::getThingsWithName(std::vector& 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 + void InstantPlayer::getConceptsInfo(std::vector& namesConcepts,std::vector& modes) + { + instantHandler->getConceptsInfo(namesConcepts,modes); + } + /* + * Returns the name of the concept that handled the real time + * DEPRECATED + */ + template + void InstantPlayer::getTimeConcept(std::string& nameConcept) + { + instantHandler->getTimeConcept(nameConcept); + } + /* + * get the number of instants that is playing + */ + template + int InstantPlayer::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 + void InstantPlayer::getConceptsActualIndexes(std::map* conceptsAndIndexes)throw (ViewerNDimensionsException) + { + std::vector conceptsNames; + environment->getConceptsNames(conceptsNames); + int instantIndex,i,size,index; + size=conceptsNames.size(); + Instant* actualInstant= getActualInstant(); + std::string conceptNamei; + for(i=0;igetIndexConcept(conceptNamei); + index=actualInstant->getIndexInConcept(instantIndex); + conceptsAndIndexes->insert(std::pair(conceptNamei,index)); + conceptNamei.clear(); + + } + + } + + //========= ACCESS ========= + /* + * Sets the time of reproduction of the concept + * that managed the real time + */ + template + void InstantPlayer::setTimeReproduction(double time) + { + //this->timeReproduction=time; + instantHandler->setTimeReproduction(time); + } + /* + * Sets the environment + */ + template + void InstantPlayer::setEnvironment(SomeEnvironment* environmment) + { + this->environment=environmment; + } + /* + * Set Actual Instant + */ + template + void InstantPlayer::setActualInstant(Instant* actualInstant) + { + instantHandler->setActualInstant(actualInstant); + } + /* + * Set Actual Instant + */ + template + void InstantPlayer::setActualInstant(std::vector* actualInstant) + { + Instant* instant=new Instant(actualInstant); + instantHandler->setActualInstant(instant); + delete instant; + } + /* + * Set the increase Value for changing the instant + */ + template + void InstantPlayer::setIncreaseValue(int increase) + { + instantHandler->setIncreaseValue(increase); + } + /* + * Set the decrease Value for changing the instant + */ + template + void InstantPlayer::setDecreaseValue(int decrease) + { + instantHandler->setDecreaseValue(decrease); + } + + /* + * Set the mode of a concept that's being handled + */ + /* + template + void InstantPlayer::setModeOfConcept(std::string nameConcept,int mode) + { + instantHandler->setModeOfConcept(nameConcept,mode); + } + /* + * Set actual time to the instant handler + */ + /* + template + void InstantPlayer::setActualTime(double actualTime) + { + instantHandler->setActualTime(actualTime); + } + /* + * set the modes of the concept that handled the time + * to the plus plus mode + */ + /* + template + void InstantPlayer::setTimeConceptToMode(int mode) + { + std::string nameConcept; + getTimeConcept(nameConcept); + setModeOfConcept(nameConcept,mode); + } + */ diff --git a/lib/kernel_Environment/ReaderEnvironment.h b/lib/kernel_Environment/ReaderEnvironment.h new file mode 100644 index 0000000..2e497fc --- /dev/null +++ b/lib/kernel_Environment/ReaderEnvironment.h @@ -0,0 +1,182 @@ +// MACRO +#ifndef __READERENVIRONMENT_H_INCLUDED__ +#define __READERENVIRONMENT_H_INCLUDED__ + +// SYSTEM INCLUDES + +// PROJECT INCLUDES +#include +#include +#include +#include + +// LOCAL INCLUDES +//#ifndef __INSTANTHANDLER_H_INCLUDED +#include "InstantHandler.h" +//#endif + +// FORWARD REFERENCES + +/* +* COMMENT +* @param +* @return +*/ + + + +template +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* things); + ReaderEnvironment(std::string nameConceptFile,std::string nameObjectFile,std::map* things); + ReaderEnvironment(std::string nameOtherConceptsFile, std::string nameConceptFile,std::string nameObjectFile, std::map* things); + ~ReaderEnvironment(); + + //====== OPERATIONS ======= + /* + * @return environment builded + */ + SomeEnvironment* getEnvironment(); + + //====== ACCESS ========== + + + + private: + + //======= ATTRIBUTES======= + /* + * Environment + */ + SomeEnvironment* environment; + /* + * things of the environment + */ + std::map* 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 dataInFile; + /* + * instant handler + */ + InstantHandler* 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 + + + diff --git a/lib/kernel_Environment/ReaderEnvironment_Txx.h b/lib/kernel_Environment/ReaderEnvironment_Txx.h new file mode 100644 index 0000000..e492d6a --- /dev/null +++ b/lib/kernel_Environment/ReaderEnvironment_Txx.h @@ -0,0 +1,678 @@ +// SYSTEM INCLUDES + + +// PROJECT INCLUDES + + +// LOCAL INCLUDES + +// FORWARD REFERENCES + +//NAMESPACE + + + + + //====== LIFECYCLE ======== + template + ReaderEnvironment::ReaderEnvironment(std::string nameConfigurationFile,std::map* things) + { + this->nameConfigurationFile=nameConfigurationFile; + this->things=things; + this->instantHandler=NULL; + this->nameOtherConceptsFile = nameOtherConceptsFile; + this->environment= new SomeEnvironment(); + //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 + ReaderEnvironment::ReaderEnvironment(std::string nameConceptFile,std::string nameObjectFile,std::map* things) + { + this->nameConceptFile=nameConceptFile; + this->nameObjectFile=nameObjectFile; + this->things=things; + this->nameOtherConceptsFile = nameOtherConceptsFile; + this->environment= new SomeEnvironment(); + //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 + ReaderEnvironment :: ReaderEnvironment(std::string nameOtherConceptsFile, std::string nameConceptFile,std::string nameObjectFile, std::map* things) + { + this->nameConceptFile=nameConceptFile; + this->nameObjectFile=nameObjectFile; + this->nameOtherConceptsFile = nameOtherConceptsFile; + this->things=things; + this->environment= new SomeEnvironment(); + //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 + ReaderEnvironment::~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 + SomeEnvironment* ReaderEnvironment::getEnvironment() + { + return this->environment; + } + /* + * build the environment + */ + template + void ReaderEnvironment::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(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 + bool ReaderEnvironment::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;inextInstant(); + instantThing=instantHandler->getActualInstant(); + //borrame + int sizeI=instantThing->getSize(); + for(int j=0;jgetIndexInConcept(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 + void ReaderEnvironment::getConceptName(std::string& nameConcept,int numConcept) + { + int ncs,conceptIndexInEnvironment,i; + + //getting the names of the concept defined + std::vector 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 + int ReaderEnvironment::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 + Instant* ReaderEnvironment:: getInstant(std::string instant) + { + int value,splitIndex; + //getting the names of the concept defined + std::vector nameConcepts; + environment->getConceptsNames(nameConcepts); + //instant vector + std::vector* instantVector=new std::vector(); + + 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 + bool ReaderEnvironment::addInstantToThing(std::string nameObject,std::string index) + { + int numInstants,i; + std::map::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 + bool ReaderEnvironment::addThings() + { + int numObjects,j; + bool addedInstants=true; + typename std::map::iterator iteratorData; + typename std::map::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 + bool ReaderEnvironment::addConcepts() + { + int numConcepts,i; + std::map::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 + void ReaderEnvironment::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::iterator iter = dataInFile.find(key); + dataInFile.erase(iter); + } + dataInFile.insert(std::pair(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 + int ReaderEnvironment::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 + void ReaderEnvironment::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); + } + diff --git a/lib/kernel_Environment/SomeEnvironment.h b/lib/kernel_Environment/SomeEnvironment.h new file mode 100644 index 0000000..82a9dde --- /dev/null +++ b/lib/kernel_Environment/SomeEnvironment.h @@ -0,0 +1,319 @@ +// MACRO + +#ifndef __SOMEENVIRONMENT_H_INCLUDED__ +#define __SOMEENVIRONMENT_H_INCLUDED__ + +// SYSTEM INCLUDES + + #include + #include + #include + #include + + +// PROJECT INCLUDES + + +// LOCAL INCLUDES + +#include "SomeThing.h" + + +// FORWARD REFERENCES + +/* +* COMMENT +* @param +* @return +*/ + + + +template + +class SomeEnvironment + { + public: + //====== LIFECYCLE ======== + SomeEnvironment(); + + SomeEnvironment(std::map* concepts,std::map< std::string,SomeThing >* 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* 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& names,std::vector& 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* getInstantsOfThing(std::string nameThing); + + /* + * Returns the instants define in the environment + * @return existing instants in the environment + */ + + std::vector* 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& 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& conceptNameVect, std::vector& 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* 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 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 > things; + + /* + * this is the things of the instant asked + * use for returning the data + */ + std::vector thingsOfInstant; + + /* + * this vector saves the instants that + * are defined in the Environment + */ + std::vector existingInstants; + + /* + * is the relation between the the indexes of the instants and the + * concepts in the environment + */ + std::map 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* 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 diff --git a/lib/kernel_Environment/SomeEnvironment_Txx.h b/lib/kernel_Environment/SomeEnvironment_Txx.h new file mode 100644 index 0000000..db1b11f --- /dev/null +++ b/lib/kernel_Environment/SomeEnvironment_Txx.h @@ -0,0 +1,619 @@ + +// SYSTEM INCLUDES + +#include + +// PROJECT INCLUDES + + +// LOCAL INCLUDES + + + +// FORWARD REFERENCES + +//NAMESPACE + + //====== LIFECYCLE ======== + template + SomeEnvironment::SomeEnvironment() + { + } + template + SomeEnvironment::SomeEnvironment(std::map* concepts,std::map< std::string,SomeThing >* things) + { + this->concepts=concepts; + this->things=things; + } + + template + SomeEnvironment::~SomeEnvironment() + { + + int size,i; + + //deleting existing instants + size=existingInstants.size(); + for(i=0;i + bool SomeEnvironment:: addThing(std::string name,T thing) + { + SomeThing something (name); + something.setThing(thing); + things.insert(std::pair < std::string, SomeThing >(name,something)); + return true; + + } + + /* + * Add thing with the name given to the instant given + * PRECONDITION + * the thing that has that name IS ALREADY ADDED TO THE PROGRAM + * @param name: name of the EXISTANT thing + * @param instant: instant associated to the thing + * @return true if the thing was succesfully added + */ + template + bool SomeEnvironment::addInstantToThing(std::string name,Instant* instant) + { + typename std::map< std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + if(thingsIterator != things.end()) + { + + + SomeThing* something=&thingsIterator->second; + //getting the address of the instant added to the environment + // in the existing instants; EVERYTHING IS HANDLED INSIDE + + //saving instants + int indexInstantInside=addInstant(instant); + //borrame + //int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + something->addInstant(instantInExistingInstants); + return true; + } + return false; + + } + return false; + } + /* + * Add thing with the name given, and the data given in the instant given + * @param name: name of the thing + * @param thing: information of the thing to be added + * @param instant: instant associated to the thing + * @return true if the thing was succesfully added + */ + template + bool SomeEnvironment::addThingWithInstant(std::string name,T thing,Instant* instant) + { + SomeThing something(name); + something.setThing(thing); + //saving instants + int indexInstantInside=addInstant(instant); + //borrame + //int indexInstantInside=getIndexInstantInExistingInstants(instant); + if(indexInstantInside!=-1) + { + Instant* instantInExistingInstants = existingInstants[indexInstantInside]; + something.addInstant(instantInExistingInstants); + things.insert(std::pair< std::string, SomeThing >(name,something)); + return true; + } + return false; + } + /* + * Add a concept to the environment + * @param name: name of the concept + * @param size: size of the concept, it means that its indexes are + * distributed 0..size-1 + * @return true if succesful, false otherwise + */ + + template + bool SomeEnvironment::addConcept(std::string name, int size) + { + concepts.insert(std::pair< std::string,int >(name,size)); + int sizeMap=concepts.size(); + indexesConcepts.insert(std::pair< std::string,int >(name,sizeMap-1)); + return true; + } + /* + * Validate the index of a concept in an instant + */ + template + bool SomeEnvironment::isValidIndex(int index, int indexInInstant) + { + std::map::iterator conceptsIterator=concepts.begin(); + std::map::iterator conceptsIndexesIterator; + std::string conceptNamei; + int indexInInstantConcepti,size; + while(conceptsIterator!=concepts.end()) + { + conceptNamei=conceptsIterator->first; + size=conceptsIterator->second; + indexInInstantConcepti=getIndexConcept(conceptNamei); + if(indexInInstantConcepti==indexInInstant) + { + if(index + std::vector* SomeEnvironment::getThings(Instant* instant) + { + //cleaning things of instant + thingsOfInstant.clear(); + // + + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator = things.begin(); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + T* thing=something->getThing(); + thingsOfInstant.push_back(thing); + + } + thingsIterator++; + } + } + + return &thingsOfInstant; + + } + + /* + * Returns the things with their names in the environment + * @param names, vector where is goint to be safe the names + * of the things in the environment. + * @param things, vector where is going to be save the things + * @return + */ + template + void SomeEnvironment::getThings(std::vector< std::string >& names,std::vector< T* >& thingsVector, Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.begin(); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + { + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + std::string nameThingInEnvironment=thingsIterator->first; + T* thing=something->getThing(); + thingsVector.push_back(thing); + names.push_back(nameThingInEnvironment); + + } + thingsIterator++; + } + } + } + /* + * Returns the instants where the thing identified by the name + * it should appears + * @param nameThing, name of the thing in the environment + * @return instants of that thing + */ + template + std::vector* SomeEnvironment::getInstantsOfThing(std::string nameThing) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(nameThing); + if(thingsIterator!=things.end()) + { + SomeThing* something=&thingsIterator->second; + return something->getInstants(); + } + return (std::vector*)NULL; + } + + /* + * Returns the instants define in the environment + * @return existing instants in the environment + * A POINTER TO THE EXISTINGINSTANTS + */ + template + std::vector* SomeEnvironment::getExistingInstants() + { + return &existingInstants; + } + + + /* + * Returns the size of the concept identified by nameConcept + * @param nameConcept, name of the concept in the environment + * @return size, of the concept given or -1 if the concept doesnt + * exist + */ + template + int SomeEnvironment::getSizeConcept(std::string nameConcept) + { + std::map< std::string, int>::iterator conceptsIterator; + conceptsIterator= concepts.find(nameConcept); + if(conceptsIterator!= concepts.end()) + { + return conceptsIterator->second; + } + else + return -1; + } + /* + * returns the index of the concept in the instants + */ + template + int SomeEnvironment::getIndexConcept(std::string nameConcept) + { + std::map< std::string, int>::iterator indexesConceptsIterator; + indexesConceptsIterator= indexesConcepts.find(nameConcept); + if(indexesConceptsIterator!= indexesConcepts.end()) + { + return indexesConceptsIterator->second; + } + else + return -1; + } + /* + * NEW + * Give the names of the names defined + * @param nameConcepts, vector where is goin to be save the names of the concepts + */ + template + void SomeEnvironment::getConceptsNames(std::vector& namesConcepts) + { + std::map::iterator iteratorConcepts=concepts.begin(); + std::string nameConcept; + while(iteratorConcepts!=concepts.end()) + { + nameConcept=iteratorConcepts->first; + namesConcepts.push_back(nameConcept); + iteratorConcepts++; + } + } + /* + * Method that retorns the name of each concept and the size of it. + * @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts + * @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts + */ + template + void SomeEnvironment :: getConceptsInformation(std::vector& conceptNameVect, std::vector& conceptSizeVect) + { + std::map::iterator iteratorConcepts=concepts.begin(); + while(iteratorConcepts!=concepts.end()) + { + std::string aName = iteratorConcepts->first; + int aSize = iteratorConcepts->second; + conceptNameVect.push_back( aName ); + conceptSizeVect.push_back( aSize ); + iteratorConcepts++; + } + } + + /* + * returns all the things of the environment + */ + template + void SomeEnvironment::getThingsOfEnvironment(std::vector* thingsVector) + { + typename std::map >::iterator iteratorThings= things.begin(); + thingsVector->clear(); + while(iteratorThings!=things.end()) + { + SomeThing* something=&iteratorThings->second; + T* thing=something->getThing(); + thingsVector->push_back(thing); + iteratorThings++; + } + + } + /* + * returns a pointer to the thing with the name given + */ + template + T* SomeEnvironment::getThingByName(std::string name) + { + T* thing=NULL; + typename std::map >::iterator iteratorThings= things.find(name); + if(iteratorThings!=things.end()) + { + SomeThing* something=&iteratorThings->second; + thing=something->getThing(); + } + return thing; + } + + + /* + * returns the number of concepts defined + */ + template + int SomeEnvironment::getNumberOfConcepts() + { + return this->concepts.size(); + } + + /* + * Gets the number of things + * @return Returns the number of existing things in the environment + */ + template + int SomeEnvironment::getNumberOfThings () + { + return things.size(); + } + + + //====== ACCESS ========== + /* + * Remove a thing from all the instants, it means from the program + * @param name: name of the thing + * @return: true if the removed is succesful (false if the thing doesn exist) + */ + template + bool SomeEnvironment::removeThing(std::string name) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + if(thingsIterator!=things.end()) + { + things.erase(thingsIterator); + return true; + } + return false; + } + /* + * Removes the thing with the name given, from the instant + * given + * @param name: name of the thing + * @param Instant: Instant from which it will be removed + * @return true: if the removed is succesful (false if the thing doesn exist) + */ + template + bool SomeEnvironment::removeThingFromInstant(std::string name, Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.find(name); + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + instantInExistingInstants=existingInstants[indexInstantInside]; + + if(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + { + something->removeInstant(instant); + return true; + } + } + return false; + } + + /* + * Remove Instant from the program, it means, that from all the + * somethings that have that instant, after call this method them + * doesnt have that instant anymore + * @param instant: instant that is going to be removed + * @return true: if the removed is succesful (false other wise) + */ + template + bool SomeEnvironment::removeInstant(Instant* instant) + { + typename std::map < std::string,SomeThing >::iterator thingsIterator; + thingsIterator=things.begin(); + bool ok=false; + + //setting the environment instant + int indexInstantInside=getIndexInstantInExistingInstants(instant); + Instant* instantInExistingInstants=NULL; + if(indexInstantInside!=-1) + instantInExistingInstants=existingInstants[indexInstantInside]; + + while(thingsIterator!=things.end() && instantInExistingInstants) + { + SomeThing* something=&thingsIterator->second; + bool isInInstantB=isInInstant(something,instantInExistingInstants); + if(isInInstantB) + ok = something->removeInstant(instantInExistingInstants); + thingsIterator++; + + } + //removing from inside instants + removeInstantFromExistingInstants(instant); + return ok; + + } + /* + * Remove a dimension from the environment + * THE REMOVE OF THE CONCEPT IS WHEN IS BEING DEFINED THE ENVIRONMENT ,NO IN + * EXECUTION + * PRECONDITION + * the name of the concept given is already added to the environment + * @param nameConcept, name of the concept to remove + */ + template + bool SomeEnvironment::removeConcept(std::string nameConcept) + { + std::map < std::string,int >::iterator conceptsIterator; + conceptsIterator=concepts.find(nameConcept); + if(conceptsIterator!=concepts.end()) + { + concepts.erase(conceptsIterator); + return true; + } + return false; + } + //====== PRIVATE METHODS========= + /* + * Checks if in the instant given the something given has it + * @param instant, instant to check + * @param something;, something to check in the instant + * @return + */ + template + bool SomeEnvironment::isInInstant(SomeThing* something,Instant *instant) + { + //borrame + for(int i=0;igetSize();i++) + int k=instant->getIndexInConcept(i); + // + int index=something->hasInstant(instant); + if(index!=-1) + return true; + else + return false; + } + /* + * Remove the instant from the environment + * @param instant, to be erased + * @return + */ + template + void SomeEnvironment::removeInstantFromExistingInstants(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end()&& !isEquals) + { + isEquals=(*existingInstantsIterator)->isEquals(instant); + if(isEquals) + existingInstants.erase(existingInstantsIterator); + existingInstantsIterator++; + + } + + } + + /* + * Adds an instant to the existing instants, verifying if + * the instant is already added + * @param instant, to be added + * @return + */ + template + int SomeEnvironment::addInstant(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + int i=0; + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end() && !isEquals) + { + Instant* existingInstant=*existingInstantsIterator; + //borrame + int sizeI=existingInstant->getSize(); + for(int k=0;kgetIndexInConcept(k); + // + isEquals=existingInstant->isEquals(instant); + existingInstantsIterator++; + if(!isEquals) + i++; + + } + if(!isEquals) + { + //copying the instant's information + std::vector* instantVector=new std::vector(); + int sizeInstant=instant->getSize(); + int k; + for(k=0;kgetIndexInConcept(k); + instantVector->push_back(d); + } + // + //saving the instant given in the handler + Instant* instantToAdded= new Instant(instantVector); + existingInstants.push_back(instantToAdded); + i=existingInstants.size()-1; + } + return i; + } + /* + * Return the index in the existing instants of the instant + * that the user had given + * @param instant, instant for which we are looking the index in + * the existings intants in the environment + * @return an index in (0,existingInstants.size()-1)or -1 if the instant hasnt + * being defined + */ + template + int SomeEnvironment::getIndexInstantInExistingInstants(Instant* instant) + { + std::vector::iterator existingInstantsIterator=existingInstants.begin(); + int i=0; + bool isEquals=false; + while(existingInstantsIterator!=existingInstants.end() && !isEquals) + { + isEquals=(*existingInstantsIterator)->isEquals(instant); + existingInstantsIterator++; + if(!isEquals) + i++; + + } + if(!isEquals) + return -1; + else + return i; + } + + diff --git a/lib/kernel_Environment/SomeThing.h b/lib/kernel_Environment/SomeThing.h new file mode 100644 index 0000000..7ddaf99 --- /dev/null +++ b/lib/kernel_Environment/SomeThing.h @@ -0,0 +1,166 @@ +// MACRO + +#ifndef __SOMETHING_H_INCLUDED__ +#define __SOMETHING_H_INCLUDED__ + +// SYSTEM INCLUDES + +// PROJECT INCLUDES + +#include +#include + +// LOCAL INCLUDES +#include "Instant.h" + + +// FORWARD REFERENCES + +/* +* COMMENT +* @param +* @return +*/ + + + + +template +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* 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 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 instantsVector; + + }; +//include the implementation of the template +#include "SomeThing_Txx.h" +#endif + + + diff --git a/lib/kernel_Environment/SomeThing_Txx.h b/lib/kernel_Environment/SomeThing_Txx.h new file mode 100644 index 0000000..c46ad8d --- /dev/null +++ b/lib/kernel_Environment/SomeThing_Txx.h @@ -0,0 +1,196 @@ + + +// SYSTEM INCLUDES +/* + #include + #include +*/ +// PROJECT INCLUDES + +//#include "Instant.h" + +// LOCAL INCLUDES + + +// FORWARD REFERENCES + +/* +* COMMENT +* @param +* @return +*/ + + //====== LIFECYCLE ======== + template + SomeThing::SomeThing(std::string name) + { + nameThing=name; + } + + template + SomeThing::~SomeThing() + { + + instantsVector.clear(); + nameThing.clear(); + + } + + + //====== OPERATIONS ======= + + /* + * Add a new instant to the thing + * @param instant: new instant + */ + template + bool SomeThing::addInstant(Instant* instant) + { + //borrame + int sizeInstant=instant->getSize(); + for(int i=0;igetIndexInConcept(i); + // + int index= hasInstant(instant); + if(index==-1) + this->instantsVector.push_back(instant); + return true; + } + + //====== INQUIRY ========= + /* + * Get the thing stored + * @return thing + */ + template + U* SomeThing::getThing() + { + return &thing; + } + /* + * Get the name of the thing + * @return nameThing + */ + template + std::string SomeThing::getName() + { + return nameThing; + } + /* + * Get all the instants + * @return instants + */ + template + std::vector* SomeThing::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 + Instant* SomeThing::getInstant(int indexInstant) + { + return instantsVector[indexInstant]; + } + /* + * Get the number of instants that the + * thng has. + * @return instants.size() + */ + template + int SomeThing::getNumberInstants() + { + return this->instantsVector.size(); + + } + /* + * if this is in the instant given + * @param instant: instant to verified if this has it + * @return 0<=i + int SomeThing::hasInstant(Instant* instant) + { + int i; + int sizeInstants=this->getNumberInstants(); + bool isEquals=false; + for(i=0;igetInstant(i); + isEquals=instanti->isEquals(instant); + if(isEquals) + return i; + } + return -1; + } + //====== ACCESS ========== + /* + * Set the thing + * @param U* thing + */ + template + void SomeThing::setThing(U thing) + { + this->thing=thing; + } + /* + * Set the name of the thing + * @param nameThing + */ + template + void SomeThing::setName(std::string name) + { + this->nameThing=name; + } + /* + * Set the instants of the thing + * @param instants + */ + template + void SomeThing::setInstants(std::vector 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 + bool SomeThing::removeInstant(int indexInstant) + { + int i; + std::vector::iterator instantsIterator=this->instantsVector.begin(); + int sizeInstants=this->getNumberInstants(); + for(i=0;iinstantsVector.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 + bool SomeThing::removeInstant(Instant* instant) + { + int index=hasInstant(instant); + if(index!=-1) + { + removeInstant(index); + return true; + } + return false; + } + + diff --git a/lib/kernel_Environment/ViewerNDimensionsException.h b/lib/kernel_Environment/ViewerNDimensionsException.h new file mode 100644 index 0000000..db38b7c --- /dev/null +++ b/lib/kernel_Environment/ViewerNDimensionsException.h @@ -0,0 +1,59 @@ +/*========================================================================= + + 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 +#include + +// 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 -- 2.45.0