2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "CommandsRegisterStructure.h"
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file CommandsRegisterStructure.cxx */
12 //------------------------------------------------------------------------------------------------------------
13 // Constructors & Destructors
14 //------------------------------------------------------------------------------------------------------------
17 * Creates the CommandsRegisterStructure
19 CommandsRegisterStructure :: CommandsRegisterStructure()
21 actualIndexToExec = -1;
26 * Destroys the CommandsRegisterStructure
28 CommandsRegisterStructure :: ~CommandsRegisterStructure()
33 //------------------------------------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------------------------------------
38 * Registers a command in the vector with no verification, is should be well constructed
39 * @param theCommand The command to register
41 void CommandsRegisterStructure :: registerCommand(CommandObject * theCommand)
43 int antes =registeredActions.size();
44 levelLastToActual(true);
45 registeredActions.push_back(theCommand);
46 actualIndexToExec = registeredActions.size()-1;
47 lastAction = actualIndexToExec;
48 int despues =registeredActions.size();
54 * Gets the -ACTUAL- command text
57 /*std::string CommandsRegisterStructure :: getActualCommandText()
59 return !isEmpty() ? getCommandAt(actualIndexToExec)->includeToExecute(): " ";
63 * Gets the -LAST- command text
66 /*std::string CommandsRegisterStructure :: getLastCommandText()
68 return !isEmpty() ? getCommandAt(lastAction)->executeCommand(): " ";
72 * Deletes all the registered actions and reinitialize the -ACTUAL- and -LAST-
74 void CommandsRegisterStructure :: clearActions()
76 if(!registeredActions.empty())
78 for(int i=0; i < registeredActions.size(); i++)
80 registeredActions[i] = NULL;
82 registeredActions.clear();
84 actualIndexToExec = -1;
89 * Moves to the the previous position the -ACTUAL-
90 * @return Indicates true if it was done
92 bool CommandsRegisterStructure :: moveBack_Actual()
94 if ( !isEmpty() && hasActualPrevious() )
103 * Moves to the the next position the -ACTUAL-
104 * @return Indicates true if it was done
106 bool CommandsRegisterStructure :: moveForward_Actual()
108 if ( !isEmpty() && hasActualNext() )
117 * Moves to the the previous position the -LAST-
118 * @return Indicates true if it was done
120 bool CommandsRegisterStructure :: moveBack_Last()
122 if ( !isEmpty() && hasLastPrevious() )
131 * Moves to the the next position the -LAST-
132 * @return Indicates true if it was done
134 bool CommandsRegisterStructure :: moveForward_Last()
136 if ( !isEmpty() && hasLastNext() )
145 * Indicates if the -LAST- has a next action or not
146 * @return Returns true if it has
148 bool CommandsRegisterStructure :: hasLastNext()
150 int total = registeredActions.size();
151 return total > 0 ? total -1 > lastAction : false;
155 * Indicates if the -ACTUAL- has a next action or not
156 * @return Returns true if it has
158 bool CommandsRegisterStructure :: hasActualNext()
160 int total = registeredActions.size();
161 return total > 0 ? total -1 > actualIndexToExec : false;
165 * Indicates if the -LAST- has a previous action or not
166 * @return Returns true if it has
168 bool CommandsRegisterStructure :: hasLastPrevious()
170 return ! 0 < lastAction;
174 * Indicates if the -ACTUAL- has a previous action or not
175 * @return Returns true if it has
177 bool CommandsRegisterStructure :: hasActualPrevious()
179 return 0 < actualIndexToExec;
183 * Puts to point CommandsRegisterStructure :: the -ACTUAL- up to the -LAST- .
185 void CommandsRegisterStructure :: levelActualToLast()
187 actualIndexToExec = lastAction;
191 * Puts to point CommandsRegisterStructure :: the -LAST- up to the -ACTUAL- and erases automatically the actions after the
192 * referenced last new position of the registered actions if nothing is given by parameter.
193 * @clearingAfterActual Indicates if is wondered to erase or not the mentioned range
195 void CommandsRegisterStructure :: levelLastToActual( bool clearingAfterActual )
199 lastAction = actualIndexToExec;
200 if( clearingAfterActual )
202 for (int a=registeredActions.size()-1; a>=0 && actualIndexToExec < a; a--)
204 if(actualIndexToExec < a)
206 registeredActions.pop_back();
214 * Clear all the elements in the vector bettween the -LAST- and the end of the vector
216 void CommandsRegisterStructure :: clearAll_afterLast()
218 for (int a=registeredActions.size()-1; a>=0 && lastAction < a; a--)
222 registeredActions.pop_back();
228 * Clear all the elements in the vector bettween the -ACTUAL- and the start of the vector
230 void CommandsRegisterStructure :: clearAll_beforeActual()
232 std::vector <CommandObject*>::iterator frontIter;
233 for (int a=0; a<registeredActions.size() && lastAction < a; a--)
235 frontIter = registeredActions.begin();
236 if( actualIndexToExec > a )
238 registeredActions.erase(frontIter);
244 * Indicates if there are actions in the vector of not
245 * @return Returns true is there are not registered actions
247 bool CommandsRegisterStructure :: isEmpty()
249 return registeredActions.empty();
253 * Indicates the quantity of actions that are registered
254 * @return Returns the total amount of registered actions in the vector
256 int CommandsRegisterStructure :: getCommandsCount()
258 return registeredActions.size();
262 * Gets the -ACTUAL- information data pointer
263 * @return The pointer to the referenced object by the -ACTUAL-
265 CommandObject * CommandsRegisterStructure :: getActual_Pointer ()
267 return getCommandAt(actualIndexToExec);
271 * Gets the -LAST- information data pointer
272 * @return The pointer to the referenced object by the -LAST-
274 CommandObject * CommandsRegisterStructure ::getLast_Pointer ()
276 return getCommandAt(lastAction);
280 * Gets the command at the given position
281 * @return The pointer to the referenced object by the position
283 CommandObject * CommandsRegisterStructure :: getCommandAt(int position)
285 if(position< getCommandsCount())
287 return registeredActions[position];
293 * Gets the index of the actualAction in the vector
294 * @return actualIndexToExec Is the corresponding index
296 int CommandsRegisterStructure :: getActualIndex()
298 return actualIndexToExec;
302 * Gets the index of the lasAction in the vector
303 * @return lasAction Is the corresponding index
305 int CommandsRegisterStructure :: getLasIndex()
311 * Sets the index of the actualAction in the vector
312 * @param newActualIndex Is the corresponding index
314 void CommandsRegisterStructure :: setActualIndex(int newActualIndex)
316 actualIndexToExec = newActualIndex;
320 * Sets the index of the lasAction in the vector
321 * @param newLasIndex Is the corresponding index
323 void CommandsRegisterStructure :: setLasIndex(int newLasIndex)
325 lastAction = newLasIndex;
329 * Gets the registered commands vector size
330 * @return Returns the vector size
332 int CommandsRegisterStructure :: getRegistereCommandsCount()
334 return registeredActions.size();
338 * Gets the total registered commands
339 * @return Returns the total of commands
341 int CommandsRegisterStructure :: getTotalCommandsCount()
344 for( int i=0; i< registeredActions.size(); i++)
346 totalAccum+= registeredActions[i]->count();