CommandsRegisterStructure.cxx

Go to the documentation of this file.
00001 
00002 //----------------------------------------------------------------------------------------------------------------
00003 // Class definition include
00004 //----------------------------------------------------------------------------------------------------------------
00005 #include "CommandsRegisterStructure.h"
00006 
00007 //----------------------------------------------------------------------------------------------------------------
00008 // Class implementation
00009 //----------------------------------------------------------------------------------------------------------------
00012 //------------------------------------------------------------------------------------------------------------
00013 // Constructors & Destructors
00014 //------------------------------------------------------------------------------------------------------------
00015 
00016 /*
00017         * Creates the CommandsRegisterStructure
00018         */
00019         CommandsRegisterStructure :: CommandsRegisterStructure()
00020         { 
00021                 actualIndexToExec = -1;         
00022                 lastAction = -1;
00023         }
00024 
00025         /*
00026         * Destroys the CommandsRegisterStructure
00027         */
00028         CommandsRegisterStructure :: ~CommandsRegisterStructure()
00029         { 
00030                 clearActions();         
00031         }
00032 
00033 //------------------------------------------------------------------------------------------------------------
00034 // Methods
00035 //------------------------------------------------------------------------------------------------------------
00036 
00041         void CommandsRegisterStructure :: registerCommand(CommandObject * theCommand)
00042         {
00043                 //int antes =registeredActions.size();
00044                 levelLastToActual(true);
00045                 registeredActions.push_back(theCommand);
00046                 actualIndexToExec = registeredActions.size()-1;
00047                 lastAction = actualIndexToExec;
00048                 //int despues =registeredActions.size();
00049                 //int otr = 0;
00050         }
00051 
00052 
00053         /*
00054         * Gets the -ACTUAL- command text 
00055         * @return
00056         */
00057         /*std::string CommandsRegisterStructure :: getActualCommandText()
00058         { 
00059                 return !isEmpty() ? getCommandAt(actualIndexToExec)->includeToExecute(): " ";
00060         }*/
00061 
00062         /*
00063         * Gets the -LAST- command text 
00064         * @return
00065         */
00066         /*std::string CommandsRegisterStructure :: getLastCommandText()
00067         { 
00068                 return !isEmpty() ? getCommandAt(lastAction)->executeCommand(): " ";
00069         }*/
00070 
00071         /*
00072         * Deletes all the registered actions and reinitialize the -ACTUAL- and  -LAST- 
00073         */
00074         void CommandsRegisterStructure ::  clearActions()
00075         { 
00076                 if(!registeredActions.empty())
00077                 {
00078                         for(int i=0; i < registeredActions.size(); i++)
00079                         {
00080                                 registeredActions[i] = NULL;
00081                         }
00082                         registeredActions.clear();              
00083                         lastAction = -1;                
00084                         actualIndexToExec = -1;
00085                 }
00086         }
00087 
00088         /*
00089         * Moves to the the previous position the -ACTUAL- 
00090         * @return Indicates true if it was done
00091         */
00092         bool CommandsRegisterStructure :: moveBack_Actual()
00093         { 
00094                 if ( !isEmpty() &&  hasActualPrevious() )
00095                 {
00096                         actualIndexToExec--;
00097                         return true;
00098                 }
00099                 return false;
00100         }
00101 
00102         /*
00103         * Moves to the the next position the -ACTUAL- 
00104         * @return Indicates true if it was done
00105         */
00106         bool CommandsRegisterStructure :: moveForward_Actual()
00107         {
00108                 if ( !isEmpty() &&  hasActualNext() )
00109                 {
00110                         actualIndexToExec++;
00111                         return true;
00112                 }
00113                 return false;
00114         }
00115 
00116         /*
00117         * Moves to the the previous position the -LAST- 
00118         * @return Indicates true if it was done
00119         */
00120         bool CommandsRegisterStructure :: moveBack_Last()
00121         { 
00122                 if ( !isEmpty() && hasLastPrevious() )
00123                 {
00124                         lastAction--;
00125                         return true;
00126                 }
00127                 return false;
00128         }
00129 
00130         /*
00131         * Moves to the the next position the -LAST- 
00132         * @return Indicates true if it was done
00133         */
00134         bool CommandsRegisterStructure :: moveForward_Last()
00135         {
00136                 if ( !isEmpty() && hasLastNext() )
00137                 {
00138                         lastAction++;
00139                         return true;
00140                 }
00141                 return false;
00142         }
00143 
00144         /*
00145         * Indicates if the -LAST-  has a next action or not
00146         * @return Returns true if it has
00147         */
00148         bool CommandsRegisterStructure :: hasLastNext()
00149         {
00150                 int total = registeredActions.size();
00151                 return total > 0 ? total -1 > lastAction : false;
00152         }
00153 
00154         /*
00155         * Indicates if the -ACTUAL-  has a next action or not
00156         * @return Returns true if it has
00157         */
00158         bool CommandsRegisterStructure :: hasActualNext()
00159         {
00160                 int total = registeredActions.size();
00161                 return total > 0 ? total -1 > actualIndexToExec : false;
00162         }
00163 
00164         /*
00165         * Indicates if the -LAST-  has a previous action or not
00166         * @return Returns true if it has
00167         */
00168         bool CommandsRegisterStructure :: hasLastPrevious()
00169         {
00170                 return ! 0 < lastAction;
00171         }
00172 
00173         /*
00174         * Indicates if the -ACTUAL-  has a previous action or not
00175         * @return Returns true if it has
00176         */
00177         bool CommandsRegisterStructure :: hasActualPrevious()
00178         {
00179                 return 0 < actualIndexToExec;
00180         }
00181 
00182         /*
00183         * Puts to point CommandsRegisterStructure ::  the -ACTUAL-  up to the -LAST-  . 
00184         */
00185         void CommandsRegisterStructure :: levelActualToLast()
00186         { 
00187                 actualIndexToExec = lastAction;
00188         }
00189 
00190         /*
00191         * Puts to point CommandsRegisterStructure ::  the -LAST-  up to the -ACTUAL-  and erases automatically the actions after the 
00192         * referenced last new position of the registered actions if nothing is given by parameter.
00193         * @clearingAfterActual Indicates if is wondered to erase or not the mentioned range 
00194         */
00195         void CommandsRegisterStructure :: levelLastToActual( bool clearingAfterActual )
00196         {
00197                 if ( !isEmpty() )
00198                 {
00199                         lastAction = actualIndexToExec;
00200                         if( clearingAfterActual )
00201                         {
00202                                 for (int a=registeredActions.size()-1; a>=0 && actualIndexToExec < a; a--)
00203                                 {
00204                                         if(actualIndexToExec < a)
00205                                         {
00206                                                 registeredActions.pop_back();
00207                                         }
00208                                 }                               
00209                         }                       
00210                 }
00211         }
00212 
00213         /*
00214         * Clear all the elements in the vector bettween the -LAST-  and the end of the vector
00215         */
00216         void CommandsRegisterStructure ::  clearAll_afterLast()
00217         {
00218                 for (int a=registeredActions.size()-1; a>=0 && lastAction < a; a--)
00219                 {
00220                         if( lastAction < a )
00221                         {
00222                                 registeredActions.pop_back();
00223                         }
00224                 }               
00225         }
00226 
00227         /*
00228         * Clear all the elements in the vector bettween the -ACTUAL-  and the start of the vector       
00229         */
00230         void CommandsRegisterStructure ::  clearAll_beforeActual()
00231         { 
00232                 std::vector <CommandObject*>::iterator frontIter;
00233                 for (int a=0; a<registeredActions.size() && lastAction < a; a--)
00234                 {
00235                         frontIter = registeredActions.begin();
00236                         if( actualIndexToExec > a )
00237                         {
00238                                 registeredActions.erase(frontIter);
00239                         }
00240                 }       
00241         }
00242 
00247         bool CommandsRegisterStructure :: isEmpty()
00248         { 
00249                 return registeredActions.empty();
00250         }
00251 
00256         int CommandsRegisterStructure ::  getCommandsCount()
00257         { 
00258                 return registeredActions.size();
00259         }
00260 
00261         /*
00262         * Gets the -ACTUAL-   information data pointer
00263         * @return The pointer to the referenced object by the -ACTUAL- 
00264         */
00265         CommandObject * CommandsRegisterStructure :: getActual_Pointer ()
00266         {
00267                 return  getCommandAt(actualIndexToExec);
00268         }
00269 
00270         /*
00271         * Gets the -LAST-   information data pointer 
00272         * @return The pointer to the referenced object by the -LAST- 
00273         */
00274         CommandObject * CommandsRegisterStructure ::getLast_Pointer ()
00275         { 
00276                 return  getCommandAt(lastAction);
00277         }
00278 
00279         /*
00280         * Gets the command at the given position 
00281         * @return The pointer to the referenced object by the position
00282         */
00283         CommandObject * CommandsRegisterStructure :: getCommandAt(int position)
00284         {
00285                 if(position< getCommandsCount())
00286                 {
00287                         return registeredActions[position];
00288                 }
00289                 return NULL;
00290         }
00291 
00292         /*
00293         * Gets the index of the actualAction in the vector
00294         * @return actualIndexToExec Is the corresponding index
00295         */
00296         int CommandsRegisterStructure :: getActualIndex()
00297         {
00298                 return actualIndexToExec;
00299         }
00300 
00301         /*
00302         * Gets the index of the lasAction in the vector
00303         * @return lasAction Is the corresponding index
00304         */
00305         int CommandsRegisterStructure :: getLasIndex()
00306         {
00307                 return lastAction;
00308         }
00309 
00310         /*
00311         * Sets the index of the actualAction in the vector
00312         * @param newActualIndex Is the corresponding index
00313         */
00314         void CommandsRegisterStructure :: setActualIndex(int newActualIndex)
00315         {
00316                 actualIndexToExec = newActualIndex;
00317         }
00318 
00319         /*
00320         * Sets the index of the lasAction in the vector
00321         * @param newLasIndex Is the corresponding index
00322         */
00323         void CommandsRegisterStructure :: setLasIndex(int newLasIndex)
00324         {
00325                 lastAction = newLasIndex;
00326         }
00327 
00328         /*
00329         * Gets the registered commands vector size
00330         * @return Returns the vector size
00331         */
00332         int CommandsRegisterStructure :: getRegistereCommandsCount()
00333         {
00334                 return registeredActions.size();
00335         }
00336 
00337         /*
00338         * Gets the total registered commands 
00339         * @return Returns the total of commands
00340         */
00341         int CommandsRegisterStructure :: getTotalCommandsCount()
00342         {
00343                 int totalAccum = 0;
00344                 for( int i=0; i< registeredActions.size(); i++)
00345                 {
00346                         totalAccum+= registeredActions[i]->count();
00347                 }
00348                 return totalAccum;
00349         }
00350    
00351  

Generated on Wed Jun 27 23:28:33 2012 for creaContours_lib by  doxygen 1.5.7.1