creaContours_lib
CommandsRegisterStructure.cxx
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
15 #
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
20 # liability.
21 #
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25 
26 
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
31 
32 //----------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //----------------------------------------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------------------------------------
38 // Constructors & Destructors
39 //------------------------------------------------------------------------------------------------------------
40 
41 /*
42  * Creates the CommandsRegisterStructure
43  */
45  {
46  actualIndexToExec = -1;
47  lastAction = -1;
48  }
49 
50  /*
51  * Destroys the CommandsRegisterStructure
52  */
54  {
55  clearActions();
56  }
57 
58 //------------------------------------------------------------------------------------------------------------
59 // Methods
60 //------------------------------------------------------------------------------------------------------------
61 
67  {
68  //int antes =registeredActions.size();
69  levelLastToActual(true);
70  registeredActions.push_back(theCommand);
73  //int despues =registeredActions.size();
74  //int otr = 0;
75  }
76 
77 
78  /*
79  * Gets the -ACTUAL- command text
80  * @return
81  */
82  /*std::string CommandsRegisterStructure :: getActualCommandText()
83  {
84  return !isEmpty() ? getCommandAt(actualIndexToExec)->includeToExecute(): " ";
85  }*/
86 
87  /*
88  * Gets the -LAST- command text
89  * @return
90  */
91  /*std::string CommandsRegisterStructure :: getLastCommandText()
92  {
93  return !isEmpty() ? getCommandAt(lastAction)->executeCommand(): " ";
94  }*/
95 
96  /*
97  * Deletes all the registered actions and reinitialize the -ACTUAL- and -LAST-
98  */
100  {
101  if(!registeredActions.empty())
102  {
103  for(int i=0; i < registeredActions.size(); i++)
104  {
105  registeredActions[i] = NULL;
106  }
107  registeredActions.clear();
108  lastAction = -1;
109  actualIndexToExec = -1;
110  }
111  }
112 
113  /*
114  * Moves to the the previous position the -ACTUAL-
115  * @return Indicates true if it was done
116  */
118  {
119  if ( !isEmpty() && hasActualPrevious() )
120  {
122  return true;
123  }
124  return false;
125  }
126 
127  /*
128  * Moves to the the next position the -ACTUAL-
129  * @return Indicates true if it was done
130  */
132  {
133  if ( !isEmpty() && hasActualNext() )
134  {
136  return true;
137  }
138  return false;
139  }
140 
141  /*
142  * Moves to the the previous position the -LAST-
143  * @return Indicates true if it was done
144  */
146  {
147  if ( !isEmpty() && hasLastPrevious() )
148  {
149  lastAction--;
150  return true;
151  }
152  return false;
153  }
154 
155  /*
156  * Moves to the the next position the -LAST-
157  * @return Indicates true if it was done
158  */
160  {
161  if ( !isEmpty() && hasLastNext() )
162  {
163  lastAction++;
164  return true;
165  }
166  return false;
167  }
168 
169  /*
170  * Indicates if the -LAST- has a next action or not
171  * @return Returns true if it has
172  */
174  {
175  int total = registeredActions.size();
176  return total > 0 ? total -1 > lastAction : false;
177  }
178 
179  /*
180  * Indicates if the -ACTUAL- has a next action or not
181  * @return Returns true if it has
182  */
184  {
185  int total = registeredActions.size();
186  return total > 0 ? total -1 > actualIndexToExec : false;
187  }
188 
189  /*
190  * Indicates if the -LAST- has a previous action or not
191  * @return Returns true if it has
192  */
194  {
195  return ! 0 < lastAction;
196  }
197 
198  /*
199  * Indicates if the -ACTUAL- has a previous action or not
200  * @return Returns true if it has
201  */
203  {
204  return 0 < actualIndexToExec;
205  }
206 
207  /*
208  * Puts to point CommandsRegisterStructure :: the -ACTUAL- up to the -LAST- .
209  */
211  {
213  }
214 
215  /*
216  * Puts to point CommandsRegisterStructure :: the -LAST- up to the -ACTUAL- and erases automatically the actions after the
217  * referenced last new position of the registered actions if nothing is given by parameter.
218  * @clearingAfterActual Indicates if is wondered to erase or not the mentioned range
219  */
220  void CommandsRegisterStructure :: levelLastToActual( bool clearingAfterActual )
221  {
222  if ( !isEmpty() )
223  {
225  if( clearingAfterActual )
226  {
227  for (int a=registeredActions.size()-1; a>=0 && actualIndexToExec < a; a--)
228  {
229  if(actualIndexToExec < a)
230  {
231  registeredActions.pop_back();
232  }
233  }
234  }
235  }
236  }
237 
238  /*
239  * Clear all the elements in the vector bettween the -LAST- and the end of the vector
240  */
242  {
243  for (int a=registeredActions.size()-1; a>=0 && lastAction < a; a--)
244  {
245  if( lastAction < a )
246  {
247  registeredActions.pop_back();
248  }
249  }
250  }
251 
252  /*
253  * Clear all the elements in the vector bettween the -ACTUAL- and the start of the vector
254  */
256  {
257  std::vector <CommandObject*>::iterator frontIter;
258  for (int a=0; a<registeredActions.size() && lastAction < a; a--)
259  {
260  frontIter = registeredActions.begin();
261  if( actualIndexToExec > a )
262  {
263  registeredActions.erase(frontIter);
264  }
265  }
266  }
267 
273  {
274  return registeredActions.empty();
275  }
276 
282  {
283  return registeredActions.size();
284  }
285 
286  /*
287  * Gets the -ACTUAL- information data pointer
288  * @return The pointer to the referenced object by the -ACTUAL-
289  */
291  {
293  }
294 
295  /*
296  * Gets the -LAST- information data pointer
297  * @return The pointer to the referenced object by the -LAST-
298  */
300  {
301  return getCommandAt(lastAction);
302  }
303 
304  /*
305  * Gets the command at the given position
306  * @return The pointer to the referenced object by the position
307  */
309  {
310  if(position< getCommandsCount())
311  {
312  return registeredActions[position];
313  }
314  return NULL;
315  }
316 
317  /*
318  * Gets the index of the actualAction in the vector
319  * @return actualIndexToExec Is the corresponding index
320  */
322  {
323  return actualIndexToExec;
324  }
325 
326  /*
327  * Gets the index of the lasAction in the vector
328  * @return lasAction Is the corresponding index
329  */
331  {
332  return lastAction;
333  }
334 
335  /*
336  * Sets the index of the actualAction in the vector
337  * @param newActualIndex Is the corresponding index
338  */
340  {
341  actualIndexToExec = newActualIndex;
342  }
343 
344  /*
345  * Sets the index of the lasAction in the vector
346  * @param newLasIndex Is the corresponding index
347  */
349  {
350  lastAction = newLasIndex;
351  }
352 
353  /*
354  * Gets the registered commands vector size
355  * @return Returns the vector size
356  */
358  {
359  return registeredActions.size();
360  }
361 
362  /*
363  * Gets the total registered commands
364  * @return Returns the total of commands
365  */
367  {
368  int totalAccum = 0;
369  for( int i=0; i< registeredActions.size(); i++)
370  {
371  totalAccum+= registeredActions[i]->count();
372  }
373  return totalAccum;
374  }
375 
376