]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/SomeThing_Txx.h
4ca634834042335ac376fe83fa91ec56278877bb
[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                                                                 /// \TODO fix warning unused variable j
53                                                                 int j=instant->getIndexInConcept(i);
54                                                         //
55                                                         int index= hasInstant(instant);
56                                                         if(index==-1)
57                                                                 this->instantsVector.push_back(instant);
58                                                         return true;
59                                                 }
60
61                                         //====== INQUIRY =========
62                                         /*
63                                         *       Get the thing stored
64                                         *       @return thing
65                                         */
66                                         template <class U>
67                                         U* SomeThing<U>::getThing()
68                                                 {
69                                                         return &thing;
70                                                 }
71                                         /*
72                                         *       Get the name of the thing
73                                         *       @return nameThing
74                                         */
75                                         template <class U>
76                                         std::string SomeThing<U>::getName()
77                                                 {
78                                                         return nameThing;
79                                                 }
80                                         /*
81                                         *       Get all the instants
82                                         *       @return instants
83                                         */
84                                         template <class U>
85                                         std::vector<Instant*>* SomeThing<U>::getInstants()
86                                                 {
87                                                         return &instantsVector;
88                                                 }
89                                         /*
90                                         *       Get the instant that's in the index given
91                                         *       @param indexInstant: index of the instant that they want
92                                         *       @return instants[instantIndex]
93                                         */
94                                         template <class U>
95                                         Instant* SomeThing<U>::getInstant(int indexInstant)
96                                                 {
97                                                         return instantsVector[indexInstant];
98                                                 }
99                                         /*
100                                         *       Get the number of instants that the 
101                                         *       thng has.
102                                         *       @return instants.size()
103                                         */
104                                         template <class U>
105                                         int  SomeThing<U>::getNumberInstants()
106                                                 {
107                                                         return this->instantsVector.size();
108                                                         
109                                                 }
110                                         /*
111                                         *  if this is in the instant given
112                                         *  @param instant: instant to verified if this has it
113                                         *  @return  0<=i<numberOfInstants if this has the instant, -1 otherwise
114                                         */
115                                         template <class U>
116                                         int SomeThing<U>::hasInstant(Instant* instant)
117                                                 {
118                                                   int i;
119                                                   int sizeInstants=this->getNumberInstants();
120                                                   bool isEquals=false;  
121                                                   for(i=0;i<sizeInstants;i++)
122                                                                 {
123                                                                         Instant* instanti=this->getInstant(i);
124                                                                         isEquals=instanti->isEquals(instant);
125                                                                         if(isEquals)
126                                                                                 return i;
127                                                                 }
128                                                  return -1;
129                                                 }
130                                         //====== ACCESS ==========
131                                         /*
132                                         *       Set the thing
133                                         *       @param U* thing
134                                         */
135                                         template <class U>
136                                         void SomeThing<U>::setThing(U thing)
137                                                 {
138                                                         this->thing=thing;
139                                                 }
140                                         /*
141                                         *       Set the name of the thing
142                                         *       @param nameThing
143                                         */
144                                         template <class U>
145                                         void SomeThing<U>::setName(std::string name)
146                                                 {
147                                                         this->nameThing=name;
148                                                 }
149                                         /*
150                                         *       Set the instants of the thing
151                                         *       @param instants
152                                         */
153                                         template <class U>
154                                         void SomeThing<U>::setInstants(std::vector<Instant*> instants)
155                                         {
156                                                 this->instantsVector=instants;
157                                         }
158                                         /*
159                                         *       Remove an instant from the thing
160                                         *       @param indexInstant: index of the instant to be removed
161                                         *       @return true if succesful , false otherwise
162                                         */
163                                         template <class U>
164                                         bool SomeThing<U>::removeInstant(int indexInstant)
165                                                 {
166                                                         int i;
167                                                         std::vector<Instant*>::iterator instantsIterator=this->instantsVector.begin();
168                                                         int sizeInstants=this->getNumberInstants();
169                                                         for(i=0;i<sizeInstants;i++)
170                                                                 {
171                                                                         if(i==indexInstant)
172                                                                         {
173                                                                                 this->instantsVector.erase(instantsIterator);
174                                                                                 return true;
175                                                                         }
176                                                                         instantsIterator++;
177                                                                 }
178                                                         return false;
179                                                 }
180                                         /*
181                                         *       Remove an instant from the thing
182                                         *       @param instant: instant to be deleted
183                                         *       @return true if succesful , false otherwise
184                                         */
185                                         template <class U>
186                                         bool SomeThing<U>::removeInstant(Instant* instant)
187                                                 {
188                                                         int index=hasInstant(instant);
189                                                         if(index!=-1)
190                                                                 {
191                                                                         removeInstant(index);
192                                                                         return true;
193                                                                 }
194                                                         return false;
195                                                 }
196                   
197