2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
41 //====== LIFECYCLE ========
43 EnvironmentHandler<P>::EnvironmentHandler(SomeEnvironment<P>* environment)
45 this->environment=environment;
49 EnvironmentHandler<P>::~EnvironmentHandler()
51 //deleting actual instants
52 this->actualInstants.clear();
53 //deleting environment
54 if(this->environment) delete this->environment;
58 //====== OPERATIONS =======
60 * change the actual intants associated to the
64 void EnvironmentHandler<P>::nextInstants(std::vector<std::string> nameConcepts)
66 int size,i,indexConcept,indexInConcept,sizeConcept;
67 size=nameConcepts.size();
68 std::map<std::string,Instant*>::iterator actualInstantsIterator;
69 std::string nameConcepti;
72 nameConcepti=nameConcepts[i];
73 actualInstantsIterator=actualInstants.find(nameConcepti);
74 if(actualInstantsIterator!=actualInstants.end())
76 Instant* instant=actualInstantsIterator->second;
77 indexConcept=environment->getIndexConcept(nameConcepti);
78 indexInConcept=instant->getIndexInConcept(indexConcept);
80 sizeConcept=environment->getSizeConcept(nameConcepti);
81 if(indexInConcept<sizeConcept)
82 instant->setConcept(indexConcept,indexInConcept);
89 * add an actual Instant to a concept, it means, this instant
90 * has all index fixed, except the index in the instant of the concept
91 * identified by nameConcept
94 void EnvironmentHandler<P>::addActualInstantOfCOncept(std::string nameConcept,Instant* instant)
96 actualInstants.insert(std::pair<std::string,int>(nameConcept,instant));
100 * removes the pair in the map of actual concepts
103 void EnvironmentHandler<P>::removeActualInstantOfConcept(std::string nameConcept)
105 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
106 if(actualInstantsIterator!=actualInstants.end())
107 actualInstants.erase(actualInstantsIterator);
110 //====== INQUIRY =========
112 * get all the actual instants
115 void EnvironmentHandler<P>::getActualsInstants(std::vector<Instant*>& instantsVector)
118 std::map<std::string,Instant*>::iterator actualInstantsIterator=
119 actualInstants.begin();
120 while(actualInstantsIterator!=actualInstants.end())
122 Instant* instant=actualInstantsIterator->second;
123 instantsVector.push_back(instant);
124 actualInstantsIterator++;
130 * get the actual instant fot the concept identified by the name
133 Instant* EnvironmentHandler<P>::getActualInstant(std::string nameConcept)
135 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
136 if(actualInstantsIterator!=actualInstants.end())
138 return instant=actualInstantsIterator->second;
142 return (Instant*)NULL;
144 //====== ACCESS ==========