]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/Instant.cxx
*** empty log message ***
[creaEnvironment.git] / lib / kernel_Environment / Instant.cxx
1
2
3 // SYSTEM INCLUDES
4
5
6 // PROJECT INCLUDES
7 #include <iostream>
8 #include <vector>
9
10 // LOCAL INCLUDES
11 #include "Instant.h"
12
13 // FORWARD REFERENCES
14 //NAMESPACE
15
16
17
18
19                         //====== LIFECYCLE ========
20                         
21                         Instant::Instant(std::vector<int>* instant)
22                                 {
23                                         nTuple=new std::vector<int>();
24                                         setInstant(instant);
25                                 }
26
27                         Instant::Instant()
28                                 {
29                                         nTuple=new std::vector<int>();
30                                 }
31                         
32                         Instant::Instant(int size)
33                                 {
34                                         nTuple= new std::vector<int>();
35                                         int i;
36                                         for(i=0;i<size;i++)
37                                                 nTuple->push_back(0);
38                                                 
39                                 }
40                         Instant::~Instant()
41                         {
42                                 //deleting nTuple
43                                 nTuple->clear();
44                                 
45                         }
46
47                         //====== OPERATIONS =======
48                         /*
49                         * Add a new concept to the instant
50                         * @param indexConcept: index concept that is going
51                         * to be added of the new concept added to the instant
52                         * @return --
53                         * 
54                         */
55                         void Instant::addConcept(int value)
56                                 {
57                                         nTuple->push_back(value);
58                                 }
59                         //======= INQUIRY ===========
60                         /*
61                         * Returns the value nTuple
62                         * @return nTuple
63                         */
64                         std::vector<int>* Instant::getInstant()
65                                 {
66                                         return nTuple;
67                                 }
68                         /*
69                         * Returns the index of the concept that's
70                         * in the instant's  concept index
71                         * @param indexConcept: index of the concept in the instant
72                         * @return indexInConcept
73                         */
74                         int Instant::getIndexInConcept(int indexConcept)
75                                 {
76                                         return (*nTuple)[indexConcept];
77                                 }
78
79                         /*
80                         * returns the number of concepts that the instant has
81                         * @return nTuple.size()
82                         */
83                         int Instant::getSize()
84                                 {
85                                         return nTuple->size();
86                                 }
87                         
88                         /*
89                         * Compares if the instant given is equals to the nTuple
90                         * @param instant: instant for compare
91                         * @return true if is equals to the nTuple, false otherwise
92                         */
93                         bool Instant::isEquals(Instant* instant)
94                                 {
95                                         int sizeInstant=instant->getSize();
96                                         bool equals=true;
97                                         int sizeThisInstant=getSize();
98                                         if(sizeInstant==sizeThisInstant)
99                                                 {
100                                                         int i;
101                                                         for(i=0;i<sizeThisInstant;i++)
102                                                                 {
103                                                                         int indexi=(*nTuple)[i];
104                                                                         int indexInConcept=instant->getIndexInConcept(i);
105                                                                         if(indexi!=indexInConcept)
106                                                                                 equals=false;
107                                                                 }
108                                                         
109                                                 }
110                                         else
111                                                 equals=false;
112                                         return equals;
113                                 }
114
115                         //=========== ACCESS ==========
116                         /*
117                         * Sets the nTuple
118                         * @param instant: the vector that's going to be save in
119                         * nTuple        
120                         */
121                         void Instant::setInstant(std::vector<int>* instant)
122                                 {
123                                         int i,size;
124                                         size=instant->size();
125                                         for(i=0;i<size;i++)
126                                                 {
127                                                         int k=(*instant)[i];
128                                                         nTuple->push_back(k);
129                                                 }
130                                 }
131                         
132                         /*
133                         * Change the  concept's index saved in the nTuple index (the index
134                         * that's is for that concept
135                         * @param indexConcept: Concept that's going to change the value
136                         * @return--
137                         * 
138                         */
139                         void Instant::setConcept(int indexConcept, int index)
140                                 {
141                                         (*nTuple)[indexConcept]=index;
142                                 }
143                         /*
144                         * remove a concept from the instant
145                         * @param indexConcept: Concept that's going to be removec
146                         * @return true if succesful, false otherwise
147                         * 
148                         */
149                         bool Instant::removeConcept(int indexConcept)
150                                 {
151                                         int i;
152                                         std::vector<int>::iterator conceptsIterator=nTuple->begin();
153                                         int size=nTuple->size();
154                                         for(i=0;i<size;i++)
155                                                 {
156                                                         if(i==indexConcept)
157                                                         {
158                                                                 nTuple->erase(conceptsIterator);
159                                                                 return true;
160                                                         }
161                                                         conceptsIterator++;
162                                                 }
163                                         return false;
164                                 }