]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/SomeThing_Txx.h
c46ad8d91923bb08fa316dedc63ee1b009233c23
[creaEnvironment.git] / lib / kernel_Environment / SomeThing_Txx.h
1
2
3 // SYSTEM INCLUDES
4 /*
5         #include <vector>
6         #include <iostream>
7 */
8 // PROJECT INCLUDES
9
10 //#include "Instant.h"
11
12 // LOCAL INCLUDES
13
14
15 // FORWARD REFERENCES
16
17 /*
18 *       COMMENT
19 *       @param
20 *       @return
21 */
22
23                                         //====== LIFECYCLE ========
24                                         template <class U>
25                                         SomeThing<U>::SomeThing(std::string name)
26                                                 {
27                                                         nameThing=name;
28                                                 }
29                         
30                                         template <class U>
31                                         SomeThing<U>::~SomeThing()
32                                                 {
33                                                         
34                                                         instantsVector.clear();
35                                                         nameThing.clear();
36                                                         
37                                                 }
38                                         
39
40                                         //====== OPERATIONS =======
41                                         
42                                         /*
43                                         *       Add a new instant to the thing
44                                         *       @param instant: new instant
45                                         */
46                                         template <class U>
47                                         bool SomeThing<U>::addInstant(Instant* instant)
48                                                 {
49                                                         //borrame 
50                                                         int sizeInstant=instant->getSize();
51                                                         for(int i=0;i<sizeInstant;i++)
52                                                                 int j=instant->getIndexInConcept(i);
53                                                         //
54                                                         int index= hasInstant(instant);
55                                                         if(index==-1)
56                                                                 this->instantsVector.push_back(instant);
57                                                         return true;
58                                                 }
59
60                                         //====== INQUIRY =========
61                                         /*
62                                         *       Get the thing stored
63                                         *       @return thing
64                                         */
65                                         template <class U>
66                                         U* SomeThing<U>::getThing()
67                                                 {
68                                                         return &thing;
69                                                 }
70                                         /*
71                                         *       Get the name of the thing
72                                         *       @return nameThing
73                                         */
74                                         template <class U>
75                                         std::string SomeThing<U>::getName()
76                                                 {
77                                                         return nameThing;
78                                                 }
79                                         /*
80                                         *       Get all the instants
81                                         *       @return instants
82                                         */
83                                         template <class U>
84                                         std::vector<Instant*>* SomeThing<U>::getInstants()
85                                                 {
86                                                         return &instantsVector;
87                                                 }
88                                         /*
89                                         *       Get the instant that's in the index given
90                                         *       @param indexInstant: index of the instant that they want
91                                         *       @return instants[instantIndex]
92                                         */
93                                         template <class U>
94                                         Instant* SomeThing<U>::getInstant(int indexInstant)
95                                                 {
96                                                         return instantsVector[indexInstant];
97                                                 }
98                                         /*
99                                         *       Get the number of instants that the 
100                                         *       thng has.
101                                         *       @return instants.size()
102                                         */
103                                         template <class U>
104                                         int  SomeThing<U>::getNumberInstants()
105                                                 {
106                                                         return this->instantsVector.size();
107                                                         
108                                                 }
109                                         /*
110                                         *  if this is in the instant given
111                                         *  @param instant: instant to verified if this has it
112                                         *  @return  0<=i<numberOfInstants if this has the instant, -1 otherwise
113                                         */
114                                         template <class U>
115                                         int SomeThing<U>::hasInstant(Instant* instant)
116                                                 {
117                                                   int i;
118                                                   int sizeInstants=this->getNumberInstants();
119                                                   bool isEquals=false;  
120                                                   for(i=0;i<sizeInstants;i++)
121                                                                 {
122                                                                         Instant* instanti=this->getInstant(i);
123                                                                         isEquals=instanti->isEquals(instant);
124                                                                         if(isEquals)
125                                                                                 return i;
126                                                                 }
127                                                  return -1;
128                                                 }
129                                         //====== ACCESS ==========
130                                         /*
131                                         *       Set the thing
132                                         *       @param U* thing
133                                         */
134                                         template <class U>
135                                         void SomeThing<U>::setThing(U thing)
136                                                 {
137                                                         this->thing=thing;
138                                                 }
139                                         /*
140                                         *       Set the name of the thing
141                                         *       @param nameThing
142                                         */
143                                         template <class U>
144                                         void SomeThing<U>::setName(std::string name)
145                                                 {
146                                                         this->nameThing=name;
147                                                 }
148                                         /*
149                                         *       Set the instants of the thing
150                                         *       @param instants
151                                         */
152                                         template <class U>
153                                         void SomeThing<U>::setInstants(std::vector<Instant*> instants)
154                                         {
155                                                 this->instantsVector=instants;
156                                         }
157                                         /*
158                                         *       Remove an instant from the thing
159                                         *       @param indexInstant: index of the instant to be removed
160                                         *       @return true if succesful , false otherwise
161                                         */
162                                         template <class U>
163                                         bool SomeThing<U>::removeInstant(int indexInstant)
164                                                 {
165                                                         int i;
166                                                         std::vector<Instant*>::iterator instantsIterator=this->instantsVector.begin();
167                                                         int sizeInstants=this->getNumberInstants();
168                                                         for(i=0;i<sizeInstants;i++)
169                                                                 {
170                                                                         if(i==indexInstant)
171                                                                         {
172                                                                                 this->instantsVector.erase(instantsIterator);
173                                                                                 return true;
174                                                                         }
175                                                                         instantsIterator++;
176                                                                 }
177                                                         return false;
178                                                 }
179                                         /*
180                                         *       Remove an instant from the thing
181                                         *       @param instant: instant to be deleted
182                                         *       @return true if succesful , false otherwise
183                                         */
184                                         template <class U>
185                                         bool SomeThing<U>::removeInstant(Instant* instant)
186                                                 {
187                                                         int index=hasInstant(instant);
188                                                         if(index!=-1)
189                                                                 {
190                                                                         removeInstant(index);
191                                                                         return true;
192                                                                 }
193                                                         return false;
194                                                 }
195                   
196