Main Page
Groups
Namespace List
Class Hierarchy
Alphabetical List
Compound List
File
List
Namespace Members
Compound Members
File Members
Concepts
itkMacro.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030
#ifndef __itkMacro_h
00031
#define __itkMacro_h
00032
00033
#include "itkWin32Header.h"
00034
#include "itkConfigure.h"
00035
00036
#include <string>
00037
00038
00039
#if !defined(CMAKE_NO_ANSI_STRING_STREAM)
00040
# include <sstream>
00041
#elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
00042
# include <strstream>
00043
# define ITK_NO_ANSI_STRING_STREAM
00044
#else
00045
# include <strstream.h>
00046
# define ITK_NO_ANSI_STRING_STREAM
00047
#endif
00048
00053
namespace itk
00054 {
00055 }
00056
00059 #define itkNotUsed(x)
00060
00075
#if defined(_MSC_VER) && (_MSC_VER <= 1300)
00076
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00077
#endif
00078
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
00079
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00080
#endif
00081
#if defined(__SVR4) && !defined(__SUNPRO_CC)
00082
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00083
#endif
00084
00085
#if defined(_MSC_VER) && (_MSC_VER <= 1300)
00086
#define ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00087
#endif
00088
00089
#ifdef ITK_NO_INCLASS_MEMBER_INITIALIZATION
00090
# define itkStaticConstMacro(name,type,value) enum { name = value }
00091
#else
00092 # define itkStaticConstMacro(name,type,value) static const type name = value
00093
#endif
00094
00095
#ifdef ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00096
# define itkGetStaticConstMacro(name) name
00097
#else
00098 # define itkGetStaticConstMacro(name) (Self::name)
00099
#endif
00100
00101
00103 #define itkSetMacro(name,type) \
00104
virtual void Set##name (const type _arg) \
00105
{ \
00106
itkDebugMacro("setting " #name " to " << _arg); \
00107
if (this->m_##name != _arg) \
00108
{ \
00109
this->m_##name = _arg; \
00110
this->Modified(); \
00111
} \
00112
}
00113
00115
#define itkGetMacro(name,type) \
00116 virtual type Get##name () \
00117
{ \
00118
itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00119
return this->m_##name; \
00120
}
00121
00125
#define itkGetConstMacro(name,type) \
00126
virtual type Get##name () const \
00127 { \
00128
itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00129
return this->m_##name; \
00130
}
00131
00136
#define itkGetConstReferenceMacro(name,type) \
00137
virtual const type & Get##name () const \
00138
{ \
00139 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00140
return this->m_##name; \
00141
}
00142
00146
#define itkSetStringMacro(name) \
00147
virtual void Set##name (const char* _arg) \
00148
{ \
00149
if ( _arg && (_arg == this->m_##name) ) { return;} \
00150 if (_arg) \
00151
{ \
00152
this->m_##name = _arg;\
00153
} \
00154
else \
00155
{ \
00156
this->m_##name = ""; \
00157
} \
00158
this->Modified(); \
00159
}
00160
00161
00165
#define itkGetStringMacro(name) \
00166
virtual const char* Get##name () const \
00167
{ \
00168
return this->m_##name.c_str(); \
00169
}
00170
00174
#define itkSetClampMacro(name,type,min,max) \
00175
virtual void Set##name (type _arg) \
00176
{ \
00177
itkDebugMacro("setting " << #name " to " << _arg ); \
00178
if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00179 { \
00180
this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00181
this->Modified(); \
00182
} \
00183
}
00184
00189
#define itkSetObjectMacro(name,type) \
00190
virtual void Set##name (type* _arg) \
00191
{ \
00192
itkDebugMacro("setting " << #name " to " << _arg ); \
00193
if (this->m_##name != _arg) \
00194
{ \
00195 this->m_##name = _arg; \
00196
this->Modified(); \
00197
} \
00198
}
00199
00202
#define itkGetObjectMacro(name,type) \
00203
virtual type * Get##name () \
00204
{ \
00205
itkDebugMacro("returning " #name " address " << this->m_##name ); \
00206
return this->m_##name.GetPointer(); \
00207
}
00208
00213
#define itkSetConstObjectMacro(name,type) \
00214
virtual void Set##name (const type* _arg) \
00215
{ \
00216
itkDebugMacro("setting " << #name " to " << _arg ); \
00217
if (this->m_##name != _arg) \
00218
{ \
00219
this->m_##name = _arg; \
00220
this->Modified(); \
00221 } \
00222
}
00223
00224
00227
#define itkGetConstObjectMacro(name,type) \
00228
virtual const type * Get##name () const \
00229
{ \
00230
itkDebugMacro("returning " #name " address " << this->m_##name ); \
00231
return this->m_##name.GetPointer(); \
00232
}
00233
00236 #define itkGetConstReferenceObjectMacro(name,type) \
00237
virtual const typename type::Pointer & Get##name () const \
00238
{ \
00239
itkDebugMacro("returning " #name " address " << this->m_##name ); \
00240
return this->m_##name; \
00241
}
00242
00245
#define itkBooleanMacro(name) \
00246 virtual void name##On () { this->Set##name(true);} \
00247
virtual void name##Off () { this->Set##name(false);}
00248
00252
#define itkSetVectorMacro(name,type,count) \
00253
virtual void Set##name(type data[]) \
00254
{ \
00255
unsigned int i; \
00256 for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00257
if ( i < count ) \
00258
{ \
00259
this->Modified(); \
00260
for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00261
} \
00262
}
00263
00266
#define itkGetVectorMacro(name,type,count) \
00267
virtual type *Get##name () const \
00268
{ \
00269
return this->m_##name; \
00270
}
00271
00283
#define itkNewMacro(x) \
00284
static Pointer New(void) \
00285
{ \
00286
Pointer smartPtr; \
00287
x *rawPtr = ::itk::ObjectFactory<x>::Create(); \
00288
if(rawPtr == NULL) \
00289
{ \
00290
rawPtr = new x; \
00291
} \
00292
smartPtr = rawPtr; \
00293
rawPtr->UnRegister(); \
00294
return smartPtr; \
00295
}
00296
00303
#define itkFactorylessNewMacro(x) \
00304
static Pointer New(void) \
00305
{ \
00306
Pointer smartPtr; \
00307
x *rawPtr = new x; \
00308
smartPtr = rawPtr; \
00309
rawPtr->UnRegister(); \
00310
return smartPtr; \
00311
}
00312
00315
#define itkTypeMacro(thisClass,superclass) \
00316
virtual const char *GetNameOfClass() const \
00317 {return #thisClass;}
00318
00319
00320
namespace itk
00321 {
00328
extern ITKCommon_EXPORT void OutputWindowDisplayText(
const char*);
00329
extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(
const char*);
00330 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(
const char*);
00331
extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(
const char*);
00332
extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(
const char*);
00333 }
00334
00338
#ifdef ITK_LEAN_AND_MEAN
00339
#define itkDebugMacro(x)
00340
#else
00341
#define itkDebugMacro(x) \
00342
{ if (this->GetDebug() && itk::Object::GetGlobalWarningDisplay()) \
00343
{ ::itk::OStringStream itkmsg; \
00344
itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00345
<< this->GetNameOfClass() << " (" << this << "): " x \
00346
<< "\n\n"; \
00347
::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00348
}
00349
#endif
00350
00351
00355
#ifdef ITK_LEAN_AND_MEAN
00356
#define itkWarningMacro(x)
00357 #else
00358
#define itkWarningMacro(x) \
00359
{ if (itk::Object::GetGlobalWarningDisplay()) \
00360
{ ::itk::OStringStream itkmsg; \
00361
itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00362
<< this->GetNameOfClass() << " (" << this << "): " x \
00363
<< "\n\n"; \
00364
itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00365
}
00366
#endif
00367
00368
namespace itk
00369 {
00370
00376
#if !defined(ITK_NO_ANSI_STRING_STREAM)
00377
class OStringStream:
public std::ostringstream
00378 {
00379
public:
00380
OStringStream() {}
00381
private:
00382
OStringStream(
const OStringStream&);
00383
void operator=(
const OStringStream&);
00384 };
00385
#else
00386
namespace OStringStreamDetail
00387 {
00388
class Cleanup
00389 {
00390
public:
00391 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00392 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00393
static void IgnoreUnusedVariable(
const Cleanup&) {}
00394
protected:
00395 std::ostrstream& m_OStrStream;
00396 };
00397 }
00398
00399
class OStringStream:
public std::ostrstream
00400 {
00401
public:
00402
typedef std::ostrstream
Superclass;
00403
OStringStream() {}
00404 std::string str()
00405 {
00406 OStringStreamDetail::Cleanup cleanup(*
this);
00407
OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00408
int pcount = this->pcount();
00409
const char* ptr = this->Superclass::str();
00410
return std::string(ptr?ptr:
"", pcount);
00411 }
00412
private:
00413
OStringStream(
const OStringStream&);
00414
void operator=(
const OStringStream&);
00415 };
00416
#endif
00417
00418 }
00419
00420
#include "itkExceptionObject.h"
00421
00425
#define itkExceptionMacro(x) \
00426
{ \
00427
::itk::OStringStream message; \
00428
message << "itk::ERROR: " << this->GetNameOfClass() \
00429
<< "(" << this << "): " x; \
00430
throw ::itk::ExceptionObject(__FILE__, __LINE__, message.str().c_str()); \
00431
}
00432
00433
#define itkGenericExceptionMacro(x) \
00434
{ \
00435
::itk::OStringStream message; \
00436
message << "itk::ERROR: " x; \
00437
throw ::itk::ExceptionObject(__FILE__, __LINE__, message.str().c_str()); \
00438
}
00439
00440
#ifdef ITK_LEAN_AND_MEAN
00441
#define itkGenericOutputMacro(x)
00442
#else
00443
#define itkGenericOutputMacro(x) \
00444 { if (::itk::Object::GetGlobalWarningDisplay()) \
00445
{ ::itk::OStringStream itkmsg; \
00446
itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00447
x << "\n\n"; \
00448
itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00449
}
00450
#endif
00451
00452
00453 #endif //end of itkMacro.h
00454
00455
Generated at Sat Mar 31 02:23:55 2007 for ITK by
1.3.8 written by Dimitri van Heesch,
© 1997-2000