ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
itkCommand.h
Go to the documentation of this file.
1
/*=========================================================================
2
*
3
* Copyright Insight Software Consortium
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*=========================================================================*/
18
#ifndef __itkCommand_h
19
#define __itkCommand_h
20
21
#include "
itkObject.h
"
22
#include "
itkObjectFactory.h
"
23
24
namespace
itk
25
{
43
// The superclass that all commands should be subclasses of
44
class
ITKCommon_EXPORT
Command
:
public
Object
45
{
46
public
:
48
typedef
Command
Self
;
49
typedef
Object
Superclass
;
50
typedef
SmartPointer< Self >
Pointer
;
51
typedef
SmartPointer< const Self >
ConstPointer
;
52
54
itkTypeMacro(
Command
,
Object
);
55
57
virtual
void
Execute(
Object
*caller,
const
EventObject
& event) = 0;
58
62
virtual
void
Execute(
const
Object
*caller,
const
EventObject
& event) = 0;
63
64
protected
:
65
Command
();
66
~
Command
();
67
private
:
68
Command
(
const
Self
&);
//purposely not implemented
69
void
operator=(
const
Self
&);
//purposely not implemented
70
};
71
72
// some implementations for several callback types
73
83
template
<
class
T >
84
class
MemberCommand
:
public
Command
85
{
86
public
:
88
typedef
void ( T::*
TMemberFunctionPointer
)(
Object
*,
const
EventObject
&);
89
typedef
void ( T::*
TConstMemberFunctionPointer
)(
const
Object
*,
90
const
EventObject
&);
92
94
typedef
MemberCommand
Self
;
95
typedef
SmartPointer< Self >
Pointer
;
96
98
itkNewMacro(
Self
);
99
101
itkTypeMacro(
MemberCommand
,
Command
);
102
105
void
SetCallbackFunction
(T *
object
,
106
TMemberFunctionPointer
memberFunction)
107
{
108
m_This
= object;
109
m_MemberFunction
= memberFunction;
110
}
111
112
void
SetCallbackFunction
(T *
object
,
113
TConstMemberFunctionPointer
memberFunction)
114
{
115
m_This
= object;
116
m_ConstMemberFunction
= memberFunction;
117
}
118
120
virtual
void
Execute
(
Object
*caller,
const
EventObject
& event)
121
{
122
if
(
m_MemberFunction
)
123
{
124
( ( *m_This ).*(
m_MemberFunction
) )( caller, event );
125
}
126
}
128
130
virtual
void
Execute
(
const
Object
*caller,
const
EventObject
& event)
131
{
132
if
(
m_ConstMemberFunction
)
133
{
134
( ( *m_This ).*(
m_ConstMemberFunction
) )( caller, event );
135
}
136
}
138
139
protected
:
140
141
T *
m_This
;
142
TMemberFunctionPointer
m_MemberFunction
;
143
TConstMemberFunctionPointer
m_ConstMemberFunction
;
144
MemberCommand
():
m_MemberFunction
(0),
m_ConstMemberFunction
(0) {}
145
virtual
~MemberCommand
(){}
146
private
:
147
MemberCommand
(
const
Self
&);
//purposely not implemented
148
void
operator=
(
const
Self
&);
//purposely not implemented
149
};
150
160
template
<
class
T >
161
class
ReceptorMemberCommand
:
public
Command
162
{
163
public
:
165
typedef
void ( T::*
TMemberFunctionPointer
)(
const
EventObject
&);
166
168
typedef
ReceptorMemberCommand
Self
;
169
typedef
SmartPointer< Self >
Pointer
;
170
172
itkNewMacro(
Self
);
173
175
itkTypeMacro(
ReceptorMemberCommand
,
Command
);
176
179
void
SetCallbackFunction
(T *
object
,
180
TMemberFunctionPointer
memberFunction)
181
{
182
m_This
= object;
183
m_MemberFunction
= memberFunction;
184
}
185
187
virtual
void
Execute
(
Object
*,
const
EventObject
& event)
188
{
189
if
(
m_MemberFunction
)
190
{
191
( ( *m_This ).*(
m_MemberFunction
) )( event );
192
}
193
}
195
197
virtual
void
Execute
(
const
Object
*,
const
EventObject
& event)
198
{
199
if
(
m_MemberFunction
)
200
{
201
( ( *m_This ).*(
m_MemberFunction
) )( event );
202
}
203
}
205
206
protected
:
207
T *
m_This
;
208
TMemberFunctionPointer
m_MemberFunction
;
209
ReceptorMemberCommand
():
m_MemberFunction
(0) {}
210
virtual
~ReceptorMemberCommand
() {}
211
private
:
212
ReceptorMemberCommand
(
const
Self
&);
//purposely not implemented
213
void
operator=
(
const
Self
&);
//purposely not implemented
214
};
215
225
template
<
class
T >
226
class
SimpleMemberCommand
:
public
Command
227
{
228
public
:
230
typedef
void ( T::*
TMemberFunctionPointer
)();
231
233
typedef
SimpleMemberCommand
Self
;
234
typedef
SmartPointer< Self >
Pointer
;
235
237
itkTypeMacro(
SimpleMemberCommand
,
Command
);
238
240
itkNewMacro(
Self
);
241
243
void
SetCallbackFunction
(T *
object
,
244
TMemberFunctionPointer
memberFunction)
245
{
246
m_This
= object;
247
m_MemberFunction
= memberFunction;
248
}
249
251
virtual
void
Execute
(
Object
*,
const
EventObject
&)
252
{
253
if
(
m_MemberFunction
)
254
{
255
( ( *m_This ).*(
m_MemberFunction
) )( );
256
}
257
}
259
260
virtual
void
Execute
(
const
Object
*,
const
EventObject
&)
261
{
262
if
(
m_MemberFunction
)
263
{
264
( ( *m_This ).*(
m_MemberFunction
) )( );
265
}
266
}
267
268
protected
:
269
T *
m_This
;
270
TMemberFunctionPointer
m_MemberFunction
;
271
SimpleMemberCommand
():
m_MemberFunction
(0) {}
272
virtual
~SimpleMemberCommand
() {}
273
private
:
274
SimpleMemberCommand
(
const
Self
&);
//purposely not implemented
275
void
operator=
(
const
Self
&);
//purposely not implemented
276
};
277
287
template
<
class
T >
288
class
SimpleConstMemberCommand
:
public
Command
289
{
290
public
:
292
typedef
void ( T::*
TMemberFunctionPointer
)()
const
;
293
295
typedef
SimpleConstMemberCommand
Self
;
296
typedef
SmartPointer< Self >
Pointer
;
297
299
itkTypeMacro(
SimpleConstMemberCommand
,
Command
);
300
302
itkNewMacro(
Self
);
303
305
void
SetCallbackFunction
(
const
T *
object
,
306
TMemberFunctionPointer
memberFunction)
307
{
308
m_This
= object;
309
m_MemberFunction
= memberFunction;
310
}
311
313
virtual
void
Execute
(
Object
*,
const
EventObject
&)
314
{
315
if
(
m_MemberFunction
)
316
{
317
( ( *m_This ).*(
m_MemberFunction
) )( );
318
}
319
}
321
322
virtual
void
Execute
(
const
Object
*,
const
EventObject
&)
323
{
324
if
(
m_MemberFunction
)
325
{
326
( ( *m_This ).*(
m_MemberFunction
) )( );
327
}
328
}
329
330
protected
:
331
const
T *
m_This
;
332
TMemberFunctionPointer
m_MemberFunction
;
333
SimpleConstMemberCommand
():
m_MemberFunction
(0) {}
334
virtual
~SimpleConstMemberCommand
() {}
335
private
:
336
SimpleConstMemberCommand
(
const
Self
&);
//purposely not implemented
337
void
operator=
(
const
Self
&);
//purposely not implemented
338
};
339
352
class
CStyleCommand
:
public
Command
353
{
354
public
:
356
typedef
void ( *
FunctionPointer
)(
Object
*,
const
EventObject
&,
void
*);
357
typedef
void ( *
ConstFunctionPointer
)(
const
Object
*,
358
const
EventObject
&,
void
*);
359
typedef
void ( *
DeleteDataFunctionPointer
)(
void
*);
361
363
typedef
CStyleCommand
Self
;
364
typedef
SmartPointer< Self >
Pointer
;
365
367
itkTypeMacro(
CStyleCommand
,
Command
);
368
370
itkNewMacro(
Self
);
371
374
void
SetClientData
(
void
*cd) {
m_ClientData
= cd; }
375
377
void
SetCallback
(
FunctionPointer
f)
378
{
m_Callback
= f; }
379
void
SetConstCallback
(
ConstFunctionPointer
f)
380
{
m_ConstCallback
= f; }
382
384
void
SetClientDataDeleteCallback
(
DeleteDataFunctionPointer
f)
385
{
m_ClientDataDeleteCallback
= f; }
386
388
void
Execute
(
Object
*caller,
const
EventObject
& event)
389
{
390
if
(
m_Callback
)
391
{
392
m_Callback
(caller, event,
m_ClientData
);
393
}
394
}
396
398
void
Execute
(
const
Object
*caller,
const
EventObject
& event)
399
{
400
if
(
m_ConstCallback
)
401
{
402
m_ConstCallback
(caller, event,
m_ClientData
);
403
}
404
}
406
407
protected
:
408
CStyleCommand
():
m_ClientData
(0),
m_Callback
(0),
m_ConstCallback
(0),
409
m_ClientDataDeleteCallback
(0)
410
{
411
// not implemented
412
}
413
414
~CStyleCommand
()
415
{
416
if
(
m_ClientDataDeleteCallback
)
417
{
418
m_ClientDataDeleteCallback
(
m_ClientData
);
419
}
420
}
421
422
void
*
m_ClientData
;
423
FunctionPointer
m_Callback
;
424
ConstFunctionPointer
m_ConstCallback
;
425
DeleteDataFunctionPointer
m_ClientDataDeleteCallback
;
426
};
427
}
// end namespace itk
428
429
#endif
430
Generated on Tue Jul 10 2012 23:21:42 for ITK by
1.8.1