anatomist  5.1.2
3D neuroimaging data viewer
Processor.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANA_PROCESSOR_PROCESSOR_H
36 #define ANA_PROCESSOR_PROCESSOR_H
37 
38 
39 //--- header files ------------------------------------------------------------
40 
44 
45 #include <queue>
46 #include <stack>
47 
48 
49 namespace anatomist
50 {
51  class Command;
52  struct CommandContext;
53 
54 
55  //--- class declarations ----------------------------------------------------
56 
66  class Processor : public Observable
67  {
68  public:
70  virtual ~Processor();
71 
76  void execute(Command* c);
83  Command* execute( const std::string & cname,
84  const std::string & params = "",
85  CommandContext* cc = 0 );
92  Command* execute( const std::string & cname,
93  carto::Object params = carto::none(),
94  CommandContext* cc = 0 );
96  bool undo();
98  bool redo();
99  void allowExecWhileIdle( bool );
100  bool execWhileIdle() const;
101  bool idle() const;
102 
105 
106  class Memo
107  {
108  public:
109  enum Type { EXECUTE, UNDO, REDO };
110  Memo(Type t, Command* c);
111  Type type() const;
112  Command* command() const;
113 
114  private:
115  Type _type;
116  Command* _command;
117  };
118 
120 
121  private:
124 
126  Processor(const Processor&);
127 
129  Processor& operator=(const Processor&);
130 
132 
135 
137  std::queue<Command*> _todo;
138 
140  std::stack<Command*> _done;
141 
143  std::stack<Command*> _undone;
144 
146  bool _idle;
147  bool _allowExecWhileIdle;
148 
150  };
151 
152 
153  //--- global variables ------------------------------------------------------
154 
156  extern Processor* theProcessor;
157 
158 
159  //--- inline methods --------------------------------------------------------
160 
161  inline
163  : _type(t), _command(c)
164  {
165  }
166 
167 
168  inline
171  {
172  return _type;
173  }
174 
175 
176  inline
177  Command*
179  {
180  return _command;
181  }
182 
183 }
184 
185 #endif
The abstract base class for commands.
Definition: Command.h:60
This class can be subclassed to represent an object that the programmer wants to have observed.
Definition: Observable.h:68
Command * command() const
Definition: Processor.h:178
Memo(Type t, Command *c)
Definition: Processor.h:162
The command processor receives commands to manage and execute.
Definition: Processor.h:67
bool undo()
Undo last done command.
bool redo()
Redo last undone command.
Command * execute(const std::string &cname, const std::string &params="", CommandContext *cc=0)
build and execute a command
bool execWhileIdle() const
void allowExecWhileIdle(bool)
void execute(Command *c)
Give a command to execute.
Command * execute(const std::string &cname, carto::Object params=carto::none(), CommandContext *cc=0)
build and execute a command
Processor * theProcessor
Pointer to the command processor of the application.
Object none()
Context for commands processor readers (APipeReader etc)
Definition: context.h:48