]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/EnvironmentHandler_Txx.h
27621b02c873ab7605cdd052fb4602247507c1b4
[creaEnvironment.git] / lib / kernel_Environment / EnvironmentHandler_Txx.h
1 // SYSTEM INCLUDES
2
3
4 // PROJECT INCLUDES
5
6
7 // LOCAL INCLUDES
8 #include "Instant.h"
9
10
11 // FORWARD REFERENCES
12
13 //NAMESPACE
14
15                                                 //====== LIFECYCLE ========
16                                                 template<class P>       
17                                                 EnvironmentHandler<P>::EnvironmentHandler(SomeEnvironment<P>* environment)
18                                                         {
19                                                                 this->environment=environment;
20                                                         }
21                                                 
22                                                 template<class P>       
23                                                 EnvironmentHandler<P>::~EnvironmentHandler()
24                                                         {
25                                                                 //deleting actual instants
26                                                                 this->actualInstants.clear();
27                                                                 //deleting environment
28                                                                 if(this->environment) delete this->environment;
29
30                                                         }
31                                                                                                         
32                                                 //====== OPERATIONS =======
33                                                 /*
34                                                 * change the actual intants associated to the
35                                                 * names given
36                                                 */
37                                                 template<class P>       
38                                                 void EnvironmentHandler<P>::nextInstants(std::vector<std::string> nameConcepts)
39                                                         {
40                                                                 int size,i,indexConcept,indexInConcept,sizeConcept;
41                                                                 size=nameConcepts.size();
42                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator;
43                                                                 std::string nameConcepti;
44                                                                 for(i=0;i<size;i++)
45                                                                         {
46                                                                                 nameConcepti=nameConcepts[i];
47                                                                                 actualInstantsIterator=actualInstants.find(nameConcepti);
48                                                                                 if(actualInstantsIterator!=actualInstants.end())
49                                                                                         {
50                                                                                                 Instant* instant=actualInstantsIterator->second;
51                                                                                                 indexConcept=environment->getIndexConcept(nameConcepti);
52                                                                                                 indexInConcept=instant->getIndexInConcept(indexConcept);
53                                                                                                 indexInConcept++;
54                                                                                                 sizeConcept=environment->getSizeConcept(nameConcepti);
55                                                                                                 if(indexInConcept<sizeConcept)
56                                                                                                         instant->setConcept(indexConcept,indexInConcept);
57                                                                                         }
58                                                                         }
59
60                                                         }
61                                                 
62                                                 /*
63                                                 * add an actual Instant to a concept, it means, this instant
64                                                 * has all index fixed, except the index in the instant of the concept
65                                                 * identified by nameConcept
66                                                 */
67                                                 template<class P>       
68                                                 void EnvironmentHandler<P>::addActualInstantOfCOncept(std::string nameConcept,Instant* instant)
69                                                         {
70                                                                 actualInstants.insert(std::pair<std::string,int>(nameConcept,instant));
71                                                         }
72                                                 
73                                                 /*
74                                                 * removes the  pair in the map of actual concepts
75                                                 */
76                                                 template<class P>
77                                                 void EnvironmentHandler<P>::removeActualInstantOfConcept(std::string nameConcept)
78                                                         {
79                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
80                                                                 if(actualInstantsIterator!=actualInstants.end())
81                                                                                 actualInstants.erase(actualInstantsIterator);
82                                                         
83                                                         }
84                                                 //====== INQUIRY =========
85                                                 /*
86                                                 * get all the actual instants
87                                                 */
88                                                 template<class P>       
89                                                 void  EnvironmentHandler<P>::getActualsInstants(std::vector<Instant*>& instantsVector)
90                                                         {
91                                                                 
92                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=
93                                                                         actualInstants.begin();
94                                                                 while(actualInstantsIterator!=actualInstants.end())
95                                                                         {
96                                                                                 Instant* instant=actualInstantsIterator->second;
97                                                                                 instantsVector.push_back(instant);
98                                                                                 actualInstantsIterator++;
99                                                                         }
100
101                                                         }
102                                                 
103                                                 /*
104                                                 * get the actual instant fot the concept identified by the name
105                                                 */
106                                                 template<class P>       
107                                                 Instant* EnvironmentHandler<P>::getActualInstant(std::string nameConcept)
108                                                         {
109                                                                 std::map<std::string,Instant*>::iterator actualInstantsIterator=actualInstants.find(nameConcept);
110                                                                 if(actualInstantsIterator!=actualInstants.end())
111                                                                         {
112                                                                                 return instant=actualInstantsIterator->second;
113                                                                                 
114                                                                         }
115                                                                 else
116                                                                         return (Instant*)NULL;
117                                                         }
118                                                 //====== ACCESS ==========
119