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