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