ITK
4.4.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
68
private
:
69
Command
(
const
Self
&);
//purposely not implemented
70
void
operator=(
const
Self
&);
//purposely not implemented
71
};
72
73
// some implementations for several callback types
74
84
template
<
class
T >
85
class
MemberCommand
:
public
Command
86
{
87
public
:
89
typedef
void ( T::*
TMemberFunctionPointer
)(
Object
*,
const
EventObject
&);
90
typedef
void ( T::*
TConstMemberFunctionPointer
)(
const
Object
*,
91
const
EventObject
&);
93
95
typedef
MemberCommand
Self
;
96
typedef
SmartPointer< Self >
Pointer
;
97
99
itkNewMacro(
Self
);
100
102
itkTypeMacro(
MemberCommand
,
Command
);
103
106
void
SetCallbackFunction
(T *
object
,
107
TMemberFunctionPointer
memberFunction)
108
{
109
m_This
= object;
110
m_MemberFunction
= memberFunction;
111
}
112
113
void
SetCallbackFunction
(T *
object
,
114
TConstMemberFunctionPointer
memberFunction)
115
{
116
m_This
= object;
117
m_ConstMemberFunction
= memberFunction;
118
}
119
121
virtual
void
Execute
(
Object
*caller,
const
EventObject
& event)
122
{
123
if
(
m_MemberFunction
)
124
{
125
( ( *m_This ).*(
m_MemberFunction
) )( caller, event );
126
}
127
}
129
131
virtual
void
Execute
(
const
Object
*caller,
const
EventObject
& event)
132
{
133
if
(
m_ConstMemberFunction
)
134
{
135
( ( *m_This ).*(
m_ConstMemberFunction
) )( caller, event );
136
}
137
}
139
140
protected
:
141
142
T *
m_This
;
143
TMemberFunctionPointer
m_MemberFunction
;
144
TConstMemberFunctionPointer
m_ConstMemberFunction
;
145
MemberCommand
():
m_MemberFunction
(0),
m_ConstMemberFunction
(0) {}
146
virtual
~MemberCommand
(){}
147
148
private
:
149
MemberCommand
(
const
Self
&);
//purposely not implemented
150
void
operator=
(
const
Self
&);
//purposely not implemented
151
};
152
162
template
<
class
T >
163
class
ReceptorMemberCommand
:
public
Command
164
{
165
public
:
167
typedef
void ( T::*
TMemberFunctionPointer
)(
const
EventObject
&);
168
170
typedef
ReceptorMemberCommand
Self
;
171
typedef
SmartPointer< Self >
Pointer
;
172
174
itkNewMacro(
Self
);
175
177
itkTypeMacro(
ReceptorMemberCommand
,
Command
);
178
181
void
SetCallbackFunction
(T *
object
,
182
TMemberFunctionPointer
memberFunction)
183
{
184
m_This
= object;
185
m_MemberFunction
= memberFunction;
186
}
187
189
virtual
void
Execute
(
Object
*,
const
EventObject
& event)
190
{
191
if
(
m_MemberFunction
)
192
{
193
( ( *m_This ).*(
m_MemberFunction
) )( event );
194
}
195
}
197
199
virtual
void
Execute
(
const
Object
*,
const
EventObject
& event)
200
{
201
if
(
m_MemberFunction
)
202
{
203
( ( *m_This ).*(
m_MemberFunction
) )( event );
204
}
205
}
207
208
protected
:
209
T *
m_This
;
210
TMemberFunctionPointer
m_MemberFunction
;
211
ReceptorMemberCommand
():
m_MemberFunction
(0) {}
212
virtual
~ReceptorMemberCommand
() {}
213
214
private
:
215
ReceptorMemberCommand
(
const
Self
&);
//purposely not implemented
216
void
operator=
(
const
Self
&);
//purposely not implemented
217
};
218
228
template
<
class
T >
229
class
SimpleMemberCommand
:
public
Command
230
{
231
public
:
233
typedef
void ( T::*
TMemberFunctionPointer
)();
234
236
typedef
SimpleMemberCommand
Self
;
237
typedef
SmartPointer< Self >
Pointer
;
238
240
itkTypeMacro(
SimpleMemberCommand
,
Command
);
241
243
itkNewMacro(
Self
);
244
246
void
SetCallbackFunction
(T *
object
,
247
TMemberFunctionPointer
memberFunction)
248
{
249
m_This
= object;
250
m_MemberFunction
= memberFunction;
251
}
252
254
virtual
void
Execute
(
Object
*,
const
EventObject
&)
255
{
256
if
(
m_MemberFunction
)
257
{
258
( ( *m_This ).*(
m_MemberFunction
) )( );
259
}
260
}
262
263
virtual
void
Execute
(
const
Object
*,
const
EventObject
&)
264
{
265
if
(
m_MemberFunction
)
266
{
267
( ( *m_This ).*(
m_MemberFunction
) )( );
268
}
269
}
270
271
protected
:
272
T *
m_This
;
273
TMemberFunctionPointer
m_MemberFunction
;
274
SimpleMemberCommand
():
m_MemberFunction
(0) {}
275
virtual
~SimpleMemberCommand
() {}
276
277
private
:
278
SimpleMemberCommand
(
const
Self
&);
//purposely not implemented
279
void
operator=
(
const
Self
&);
//purposely not implemented
280
};
281
291
template
<
class
T >
292
class
SimpleConstMemberCommand
:
public
Command
293
{
294
public
:
296
typedef
void ( T::*
TMemberFunctionPointer
)()
const
;
297
299
typedef
SimpleConstMemberCommand
Self
;
300
typedef
SmartPointer< Self >
Pointer
;
301
303
itkTypeMacro(
SimpleConstMemberCommand
,
Command
);
304
306
itkNewMacro(
Self
);
307
309
void
SetCallbackFunction
(
const
T *
object
,
310
TMemberFunctionPointer
memberFunction)
311
{
312
m_This
= object;
313
m_MemberFunction
= memberFunction;
314
}
315
317
virtual
void
Execute
(
Object
*,
const
EventObject
&)
318
{
319
if
(
m_MemberFunction
)
320
{
321
( ( *m_This ).*(
m_MemberFunction
) )( );
322
}
323
}
325
326
virtual
void
Execute
(
const
Object
*,
const
EventObject
&)
327
{
328
if
(
m_MemberFunction
)
329
{
330
( ( *m_This ).*(
m_MemberFunction
) )( );
331
}
332
}
333
334
protected
:
335
const
T *
m_This
;
336
TMemberFunctionPointer
m_MemberFunction
;
337
SimpleConstMemberCommand
():
m_MemberFunction
(0) {}
338
virtual
~SimpleConstMemberCommand
() {}
339
340
private
:
341
SimpleConstMemberCommand
(
const
Self
&);
//purposely not implemented
342
void
operator=
(
const
Self
&);
//purposely not implemented
343
};
344
357
class
CStyleCommand
:
public
Command
358
{
359
public
:
361
typedef
void ( *
FunctionPointer
)(
Object
*,
const
EventObject
&,
void
*);
362
typedef
void ( *
ConstFunctionPointer
)(
const
Object
*,
363
const
EventObject
&,
void
*);
364
typedef
void ( *
DeleteDataFunctionPointer
)(
void
*);
366
368
typedef
CStyleCommand
Self
;
369
typedef
SmartPointer< Self >
Pointer
;
370
372
itkTypeMacro(
CStyleCommand
,
Command
);
373
375
itkNewMacro(
Self
);
376
379
void
SetClientData
(
void
*cd) {
m_ClientData
= cd; }
380
382
void
SetCallback
(
FunctionPointer
f)
383
{
m_Callback
= f; }
384
void
SetConstCallback
(
ConstFunctionPointer
f)
385
{
m_ConstCallback
= f; }
387
389
void
SetClientDataDeleteCallback
(
DeleteDataFunctionPointer
f)
390
{
m_ClientDataDeleteCallback
= f; }
391
393
void
Execute
(
Object
*caller,
const
EventObject
& event)
394
{
395
if
(
m_Callback
)
396
{
397
m_Callback
(caller, event,
m_ClientData
);
398
}
399
}
401
403
void
Execute
(
const
Object
*caller,
const
EventObject
& event)
404
{
405
if
(
m_ConstCallback
)
406
{
407
m_ConstCallback
(caller, event,
m_ClientData
);
408
}
409
}
411
412
protected
:
413
CStyleCommand
():
m_ClientData
(0),
m_Callback
(0),
m_ConstCallback
(0),
414
m_ClientDataDeleteCallback
(0)
415
{
416
// not implemented
417
}
418
419
~CStyleCommand
()
420
{
421
if
(
m_ClientDataDeleteCallback
)
422
{
423
m_ClientDataDeleteCallback
(
m_ClientData
);
424
}
425
}
426
427
void
*
m_ClientData
;
428
FunctionPointer
m_Callback
;
429
ConstFunctionPointer
m_ConstCallback
;
430
DeleteDataFunctionPointer
m_ClientDataDeleteCallback
;
431
};
432
}
// end namespace itk
433
434
#endif
435
Generated on Mon May 13 2013 00:46:27 for ITK by
1.8.3.1