]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/EnvironmentHandler_Txx.h
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / EnvironmentHandler_Txx.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27 // SYSTEM INCLUDES
28
29
30 // PROJECT INCLUDES
31
32
33 // LOCAL INCLUDES
34 #include "Instant.h"
35
36
37 // FORWARD REFERENCES
38
39 //NAMESPACE
40
41                                                 //====== LIFECYCLE ========
42                                                 template<class P>       
43                                                 EnvironmentHandler<P>::EnvironmentHandler(SomeEnvironment<P>* environment)
44                                                         {
45                                                                 this->environment=environment;
46                                                         }
47                                                 
48                                                 template<class P>       
49                                                 EnvironmentHandler<P>::~EnvironmentHandler()
50                                                         {
51                                                                 //deleting actual instants
52                                                                 this->actualInstants.clear();
53                                                                 //deleting environment
54                                                                 if(this->environment) delete this->environment;
55
56                                                         }
57                                                                                                         
58                                                 //====== OPERATIONS =======
59                                                 /*
60                                                 * change the actual intants associated to the
61                                                 * names given
62                                                 */
63                                                 template<class P>       
64                                                 void EnvironmentHandler<P>::nextInstants(std::vector<std::string> nameConcepts)
65                                                         {
66                                                                 int size,i,indexConcept,indexInConcept,sizeConcept;
67                                                                 size=nameConcepts.size();
68                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator;
69                                                                 std::string nameConcepti;
70                                                                 for(i=0;i<size;i++)
71                                                                         {
72                                                                                 nameConcepti=nameConcepts[i];
73                                                                                 actualInstantsIterator=actualInstants.find(nameConcepti);
74                                                                                 if(actualInstantsIterator!=actualInstants.end())
75                                                                                         {
76                                                                                                 Instant* instant=actualInstantsIterator->second;
77                                                                                                 indexConcept=environment->getIndexConcept(nameConcepti);
78                                                                                                 indexInConcept=instant->getIndexInConcept(indexConcept);
79                                                                                                 indexInConcept++;
80                                                                                                 sizeConcept=environment->getSizeConcept(nameConcepti);
81                                                                                                 if(indexInConcept<sizeConcept)
82                                                                                                         instant->setConcept(indexConcept,indexInConcept);
83                                                                                         }
84                                                                         }
85
86                                                         }
87                                                 
88                                                 /*
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
92                                                 */
93                                                 template<class P>       
94                                                 void EnvironmentHandler<P>::addActualInstantOfCOncept(std::string nameConcept,Instant* instant)
95                                                         {
96                                                                 actualInstants.insert(std::pair<std::string,int>(nameConcept,instant));
97                                                         }
98                                                 
99                                                 /*
100                                                 * removes the  pair in the map of actual concepts
101                                                 */
102                                                 template<class P>
103                                                 void EnvironmentHandler<P>::removeActualInstantOfConcept(std::string nameConcept)
104                                                         {
105                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
106                                                                 if(actualInstantsIterator!=actualInstants.end())
107                                                                                 actualInstants.erase(actualInstantsIterator);
108                                                         
109                                                         }
110                                                 //====== INQUIRY =========
111                                                 /*
112                                                 * get all the actual instants
113                                                 */
114                                                 template<class P>       
115                                                 void  EnvironmentHandler<P>::getActualsInstants(std::vector<Instant*>& instantsVector)
116                                                         {
117                                                                 
118                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=
119                                                                         actualInstants.begin();
120                                                                 while(actualInstantsIterator!=actualInstants.end())
121                                                                         {
122                                                                                 Instant* instant=actualInstantsIterator->second;
123                                                                                 instantsVector.push_back(instant);
124                                                                                 actualInstantsIterator++;
125                                                                         }
126
127                                                         }
128                                                 
129                                                 /*
130                                                 * get the actual instant fot the concept identified by the name
131                                                 */
132                                                 template<class P>       
133                                                 Instant* EnvironmentHandler<P>::getActualInstant(std::string nameConcept)
134                                                         {
135                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
136                                                                 if(actualInstantsIterator!=actualInstants.end())
137                                                                         {
138                                                                                 return instant=actualInstantsIterator->second;
139                                                                                 
140                                                                         }
141                                                                 else
142                                                                         return (Instant*)NULL;
143                                                         }
144                                                 //====== ACCESS ==========
145