]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/ComposedCommand.cxx
13cd2c1d358fe3cea66448837bfc715e86b7f13c
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / ComposedCommand.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "ComposedCommand.h"
6
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file ComposedCommand.cxx */
11
12 //------------------------------------------------------------------------------------------------------------
13 // Constructors & Destructors
14 //------------------------------------------------------------------------------------------------------------
15
16
17         ComposedCommand :: ComposedCommand( )
18         {
19
20         }
21
22         ComposedCommand :: ~ComposedCommand( )
23         {
24                 clear();        
25         }
26
27 //------------------------------------------------------------------------------------------------------------
28 // Methods
29 //------------------------------------------------------------------------------------------------------------
30         
31         /*
32         * Adds a command to the list of command
33         * @param nwCommand Is the new command to include
34         */
35         void ComposedCommand :: addCommand(CommandObject * nwCommand)
36         {       
37                 internalCommands.push_back(nwCommand);
38         }
39
40         /*
41         * Virtual method implentation that includes the commands list into the given queue for execution
42         * @param executionQueue Is the queue in which is included the command
43         */
44         void ComposedCommand :: includeToExecute(std::deque<CommandObject* > &executionQueue)
45         {
46         std::deque<CommandObject *>::iterator actualCommandIter = internalCommands.end();
47                 while( actualCommandIter != internalCommands.begin())
48                 {
49                         (*actualCommandIter)->includeToExecute(executionQueue);                 
50                         actualCommandIter--;                    
51                 }       
52         }
53
54         /*
55         * Virtual method implementation that returns 1 as the ExecutableCommand is just one command effective
56         * @return The value of commands that represents this
57         */
58         int ComposedCommand :: count()
59         {
60                 int count = 0;
61                 int i =0;
62                 while( i<internalCommands.size() )
63                 {
64                         count += internalCommands[i]->count();  
65                         i++;
66                 }
67                 return count;
68         }
69
70         /*
71         * Virtual method implentation that that clears the commands inside the composed command calling each one to clean it self
72         */
73         void ComposedCommand :: clear()
74         {               
75                 while( internalCommands.size()>0 )
76                 {
77                         internalCommands.back()->clear();
78                         internalCommands.pop_back();
79                 }
80                 internalCommands.clear();
81         }
82                 
83