| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkMacro.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:41 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
Portions of this code are covered under the VTK copyright. |
| 13 |
|
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. |
| 14 |
|
|
| 15 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 16 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 17 |
IND |
*****PURPOSE. See the above copyright notices for more information. |
| 18 |
|
|
| 19 |
|
=========================================================================*/ |
| 20 |
|
/** |
| 21 |
|
* itkMacro.h defines standard system-wide macros, constants, and other |
| 22 |
|
* parameters. One of its most important functions is to define macros used |
| 23 |
|
* to interface to instance variables in a standard fashion. For example, |
| 24 |
|
* these macros manage modified time, debugging information, and provide a |
| 25 |
|
* standard interface to set and get instance variables. Macros are |
| 26 |
|
* available for built-in types; for string classe; vector arrays; |
| 27 |
|
* object pointers; and debug, warning, and error printout information. |
| 28 |
|
*/ |
| 29 |
|
|
| 30 |
|
#ifndef __itkMacro_h |
| 31 |
|
#define __itkMacro_h |
| 32 |
|
|
| 33 |
|
#include "itkWin32Header.h" |
| 34 |
|
#include "itkConfigure.h" |
| 35 |
|
|
| 36 |
|
#include <string> |
| 37 |
|
|
| 38 |
|
// Determine type of string stream to use. |
| 39 |
|
#if !defined(CMAKE_NO_ANSI_STRING_STREAM) |
| 40 |
|
# include <sstream> |
| 41 |
|
#elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS) |
| 42 |
|
# include <strstream> |
| 43 |
|
# define ITK_NO_ANSI_STRING_STREAM |
| 44 |
|
#else |
| 45 |
|
# include <strstream.h> |
| 46 |
|
# define ITK_NO_ANSI_STRING_STREAM |
| 47 |
|
#endif |
| 48 |
|
|
| 49 |
|
/** \namespace itk |
| 50 |
|
* \brief The "itk" namespace contains all Insight Segmentation and |
| 51 |
|
* Registration Toolkit (ITK) classes. There are several nested namespaces |
| 52 |
|
* within the itk:: namespace. */ |
| 53 |
|
namespace itk |
| 54 |
|
{ |
| 55 |
|
} // end namespace itk - this is here for documentation purposes |
| 56 |
|
|
| 57 |
|
/** A convenience macro marks variables as not being used by a method, |
| 58 |
|
* avoiding compile-time warnings. */ |
| 59 |
|
#define itkNotUsed(x) |
| 60 |
|
|
| 61 |
|
/** Macro to initialize static constants. This is used frequently to replace |
| 62 |
|
* the use of enum's within a class. Some compilers do not allow an enum of |
| 63 |
|
* one class to be passed as template argument to another class. Other |
| 64 |
|
* uses of this macro as possible. |
| 65 |
|
* |
| 66 |
|
* This is based (verbatim) on the BOOST_STATIC_CONSTANT macro. The original |
| 67 |
|
* Boost documentation is below. |
| 68 |
|
* |
| 69 |
|
* BOOST_STATIC_CONSTANT workaround --------------------------------------- // |
| 70 |
|
* On compilers which don't allow in-class initialization of static integral |
| 71 |
|
* constant members, we must use enums as a workaround if we want the constants |
| 72 |
|
* to be available at compile-time. This macro gives us a convenient way to |
| 73 |
|
* declare such constants. |
| 74 |
|
*/ |
| 75 |
|
#if defined(_MSC_VER) && (_MSC_VER <= 1300) |
| 76 |
|
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION |
| 77 |
|
#endif |
| 78 |
|
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540) |
| 79 |
|
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION |
| 80 |
|
#endif |
| 81 |
|
#if defined(__SVR4) && !defined(__SUNPRO_CC) |
| 82 |
|
# define ITK_NO_INCLASS_MEMBER_INITIALIZATION |
| 83 |
|
#endif |
| 84 |
|
|
| 85 |
|
#if defined(_MSC_VER) && (_MSC_VER <= 1300) |
| 86 |
|
#define ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS |
| 87 |
|
#endif |
| 88 |
|
|
| 89 |
|
#ifdef ITK_NO_INCLASS_MEMBER_INITIALIZATION |
| 90 |
|
# define itkStaticConstMacro(name,type,value) enum { name = value } |
| 91 |
|
#else |
| 92 |
|
# define itkStaticConstMacro(name,type,value) static const type name = value |
| 93 |
|
#endif |
| 94 |
|
|
| 95 |
|
#ifdef ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS |
| 96 |
|
# define itkGetStaticConstMacro(name) name |
| 97 |
|
#else |
| 98 |
|
# define itkGetStaticConstMacro(name) (Self::name) |
| 99 |
|
#endif |
| 100 |
|
|
| 101 |
|
/** Set an input. This defines the Set"name"Input() method */ |
| 102 |
|
#define itkSetInputMacro(name, type, number) \ |
| 103 |
|
virtual void Set##name##Input(const type *_arg) \ |
| 104 |
|
{ \ |
| 105 |
|
itkDebugMacro("setting input " #name " to " << _arg); \ |
| 106 |
|
if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \ |
| 107 |
IND |
******{ \ |
| 108 |
IND |
******this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \ |
| 109 |
IND |
******this->Modified(); \ |
| 110 |
IND |
******} \ |
| 111 |
|
} \ |
| 112 |
IND |
**virtual void SetInput##number(const type *_arg) \ |
| 113 |
|
{ \ |
| 114 |
IND |
****itkDebugMacro("setting input " #number " to " << _arg); \ |
| 115 |
|
if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \ |
| 116 |
IND |
******{ \ |
| 117 |
IND |
******this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \ |
| 118 |
IND |
******this->Modified(); \ |
| 119 |
IND |
******} \ |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
/** Get an input. This defines the Get"name"Input() method */ |
| 124 |
|
#define itkGetInputMacro(name, type, number) \ |
| 125 |
IND |
**virtual const type * Get##name##Input() const \ |
| 126 |
|
{ \ |
| 127 |
LEN,IND |
****itkDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \ |
| 128 |
IND |
****return static_cast<const type *>(this->ProcessObject::GetInput( number )); \ |
| 129 |
|
} \ |
| 130 |
IND |
**virtual const type * GetInput##number() const \ |
| 131 |
|
{ \ |
| 132 |
LEN,IND |
****itkDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \ |
| 133 |
IND |
****return static_cast<const type *>(this->ProcessObject::GetInput( number )); \ |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
/** Set built-in type. Creates member Set"name"() (e.g., SetVisibility()); */ |
| 138 |
|
#define itkSetMacro(name,type) \ |
| 139 |
IND |
**virtual void Set##name (const type _arg) \ |
| 140 |
|
{ \ |
| 141 |
IND |
****itkDebugMacro("setting " #name " to " << _arg); \ |
| 142 |
|
if (this->m_##name != _arg) \ |
| 143 |
IND |
******{ \ |
| 144 |
IND |
******this->m_##name = _arg; \ |
| 145 |
IND |
******this->Modified(); \ |
| 146 |
IND |
******} \ |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
/** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); */ |
| 150 |
|
#define itkGetMacro(name,type) \ |
| 151 |
IND |
**virtual type Get##name () \ |
| 152 |
|
{ \ |
| 153 |
IND |
****itkDebugMacro("returning " << #name " of " << this->m_##name ); \ |
| 154 |
IND |
****return this->m_##name; \ |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
/** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); |
| 158 |
|
* This is the "const" form of the itkGetMacro. It should be used unless |
| 159 |
|
* the member can be changed through the "Get" access routine. */ |
| 160 |
|
#define itkGetConstMacro(name,type) \ |
| 161 |
IND |
**virtual type Get##name () const \ |
| 162 |
|
{ \ |
| 163 |
IND |
****itkDebugMacro("returning " << #name " of " << this->m_##name ); \ |
| 164 |
IND |
****return this->m_##name; \ |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
/** Get built-in type. Creates member Get"name"() (e.g., GetVisibility()); |
| 168 |
|
* This is the "const" form of the itkGetMacro. It should be used unless |
| 169 |
|
* the member can be changed through the "Get" access routine. |
| 170 |
|
* This versions returns a const reference to the variable. */ |
| 171 |
|
#define itkGetConstReferenceMacro(name,type) \ |
| 172 |
IND |
**virtual const type & Get##name () const \ |
| 173 |
|
{ \ |
| 174 |
IND |
****itkDebugMacro("returning " << #name " of " << this->m_##name ); \ |
| 175 |
IND |
****return this->m_##name; \ |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
/** Set character string. Creates member Set"name"() |
| 179 |
|
* (e.g., SetFilename(char *)). The macro assumes that |
| 180 |
|
* the class member (name) is declared a type std::string. */ |
| 181 |
|
#define itkSetStringMacro(name) \ |
| 182 |
IND |
**virtual void Set##name (const char* _arg) \ |
| 183 |
|
{ \ |
| 184 |
IND |
****if ( _arg && (_arg == this->m_##name) ) { return;} \ |
| 185 |
IND |
****if (_arg) \ |
| 186 |
IND |
******{ \ |
| 187 |
IND |
******this->m_##name = _arg;\ |
| 188 |
IND |
******} \ |
| 189 |
IND |
*****else \ |
| 190 |
IND |
******{ \ |
| 191 |
IND |
******this->m_##name = ""; \ |
| 192 |
IND |
******} \ |
| 193 |
IND |
****this->Modified(); \ |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
|
| 197 |
|
/** Get character string. Creates member Get"name"() |
| 198 |
|
* (e.g., SetFilename(char *)). The macro assumes that |
| 199 |
|
* the class member (name) is declared a type std::string. */ |
| 200 |
|
#define itkGetStringMacro(name) \ |
| 201 |
IND |
**virtual const char* Get##name () const \ |
| 202 |
|
{ \ |
| 203 |
IND |
****return this->m_##name.c_str(); \ |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
/** Set built-in type where value is constrained between min/max limits. |
| 207 |
|
* Create member Set"name"() (e.q., SetRadius()). #defines are |
| 208 |
|
* convienience for clamping open-ended values. */ |
| 209 |
|
#define itkSetClampMacro(name,type,min,max) \ |
| 210 |
IND |
**virtual void Set##name (type _arg) \ |
| 211 |
|
{ \ |
| 212 |
IND |
****itkDebugMacro("setting " << #name " to " << _arg ); \ |
| 213 |
|
if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \ |
| 214 |
IND |
******{ \ |
| 215 |
IND |
******this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \ |
| 216 |
IND |
******this->Modified(); \ |
| 217 |
IND |
******} \ |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
/** Set pointer to object; uses Object reference counting methodology. |
| 221 |
|
* Creates method Set"name"() (e.g., SetPoints()). Note that using |
| 222 |
|
* smart pointers requires using real pointers when setting input, |
| 223 |
|
* but returning smart pointers on output. */ |
| 224 |
|
#define itkSetObjectMacro(name,type) \ |
| 225 |
IND |
**virtual void Set##name (type* _arg) \ |
| 226 |
|
{ \ |
| 227 |
IND |
****itkDebugMacro("setting " << #name " to " << _arg ); \ |
| 228 |
|
if (this->m_##name != _arg) \ |
| 229 |
IND |
******{ \ |
| 230 |
IND |
******this->m_##name = _arg; \ |
| 231 |
IND |
******this->Modified(); \ |
| 232 |
IND |
******} \ |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
/** Get a smart pointer to an object. Creates the member |
| 236 |
|
* Get"name"() (e.g., GetPoints()). */ |
| 237 |
|
#define itkGetObjectMacro(name,type) \ |
| 238 |
IND |
**virtual type * Get##name () \ |
| 239 |
|
{ \ |
| 240 |
IND |
****itkDebugMacro("returning " #name " address " << this->m_##name ); \ |
| 241 |
IND |
****return this->m_##name.GetPointer(); \ |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
/** Set const pointer to object; uses Object reference counting methodology. |
| 245 |
|
* Creates method Set"name"() (e.g., SetPoints()). Note that using |
| 246 |
|
* smart pointers requires using real pointers when setting input, |
| 247 |
|
* but returning smart pointers on output. */ |
| 248 |
|
#define itkSetConstObjectMacro(name,type) \ |
| 249 |
IND |
**virtual void Set##name (const type* _arg) \ |
| 250 |
|
{ \ |
| 251 |
IND |
****itkDebugMacro("setting " << #name " to " << _arg ); \ |
| 252 |
|
if (this->m_##name != _arg) \ |
| 253 |
IND |
******{ \ |
| 254 |
IND |
******this->m_##name = _arg; \ |
| 255 |
IND |
******this->Modified(); \ |
| 256 |
IND |
******} \ |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
|
/** Get a smart const pointer to an object. Creates the member |
| 261 |
|
* Get"name"() (e.g., GetPoints()). */ |
| 262 |
|
#define itkGetConstObjectMacro(name,type) \ |
| 263 |
IND |
**virtual const type * Get##name () const \ |
| 264 |
|
{ \ |
| 265 |
IND |
****itkDebugMacro("returning " #name " address " << this->m_##name ); \ |
| 266 |
IND |
****return this->m_##name.GetPointer(); \ |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
/** Get a const reference to a smart pointer to an object. |
| 270 |
|
* Creates the member Get"name"() (e.g., GetPoints()). */ |
| 271 |
|
#define itkGetConstReferenceObjectMacro(name,type) \ |
| 272 |
IND |
**virtual const typename type::Pointer & Get##name () const \ |
| 273 |
|
{ \ |
| 274 |
IND |
****itkDebugMacro("returning " #name " address " << this->m_##name ); \ |
| 275 |
IND |
****return this->m_##name; \ |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
/** Create members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()). |
| 279 |
|
* Set method must be defined to use this macro. */ |
| 280 |
|
#define itkBooleanMacro(name) \ |
| 281 |
IND |
**virtual void name##On () { this->Set##name(true);} \ |
| 282 |
IND |
**virtual void name##Off () { this->Set##name(false);} |
| 283 |
|
|
| 284 |
|
/** General set vector macro creates a single method that copies specified |
| 285 |
|
* number of values into object. |
| 286 |
|
* Examples: void SetColor(c,3) */ |
| 287 |
|
#define itkSetVectorMacro(name,type,count) \ |
| 288 |
IND |
**virtual void Set##name(type data[]) \ |
| 289 |
|
{ \ |
| 290 |
IND |
****unsigned int i; \ |
| 291 |
IND |
****for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \ |
| 292 |
IND |
****if ( i < count ) \ |
| 293 |
|
{ \ |
| 294 |
|
this->Modified(); \ |
| 295 |
IND |
******for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\ |
| 296 |
IND |
******} \ |
| 297 |
|
} |
| 298 |
|
|
| 299 |
|
/** Get vector macro. Returns pointer to type (i.e., array of type). |
| 300 |
|
* This is for efficiency. */ |
| 301 |
|
#define itkGetVectorMacro(name,type,count) \ |
| 302 |
IND |
**virtual type *Get##name () const \ |
| 303 |
|
{ \ |
| 304 |
IND |
****return this->m_##name; \ |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
/** Define two object creation methods. The first method, New(), |
| 308 |
|
* creates an object from a class, potentially deferring to a factory. |
| 309 |
|
* The second method, CreateAnother(), creates an object from an |
| 310 |
|
* instance, potentially deferring to a factory. This second method |
| 311 |
|
* allows you to create an instance of an object that is exactly the |
| 312 |
|
* same type as the referring object. This is useful in cases where |
| 313 |
|
* an object has been cast back to a base class. |
| 314 |
|
* |
| 315 |
|
* These creation methods first try asking the object factory to create |
| 316 |
|
* an instance, and then default to the standard "new" operator if the |
| 317 |
|
* factory fails. |
| 318 |
|
* |
| 319 |
|
* These routines assigns the raw pointer to a smart pointer and then call |
| 320 |
|
* UnRegister() on the rawPtr to compensate for LightObject's constructor |
| 321 |
|
* initializing an object's reference count to 1 (needed for proper |
| 322 |
|
* initialization of process objects and data objects cycles). */ |
| 323 |
|
#define itkNewMacro(x) \ |
| 324 |
|
static Pointer New(void) \ |
| 325 |
IND |
{ \ |
| 326 |
|
Pointer smartPtr; \ |
| 327 |
|
x *rawPtr = ::itk::ObjectFactory<x>::Create(); \ |
| 328 |
|
if(rawPtr == NULL) \ |
| 329 |
|
{ \ |
| 330 |
|
rawPtr = new x; \ |
| 331 |
|
} \ |
| 332 |
|
smartPtr = rawPtr; \ |
| 333 |
|
rawPtr->UnRegister(); \ |
| 334 |
|
return smartPtr; \ |
| 335 |
IND |
} \ |
| 336 |
|
virtual ::itk::LightObject::Pointer CreateAnother(void) const \ |
| 337 |
IND |
{ \ |
| 338 |
|
::itk::LightObject::Pointer smartPtr; \ |
| 339 |
|
smartPtr = x::New().GetPointer(); \ |
| 340 |
|
return smartPtr; \ |
| 341 |
IND |
} |
| 342 |
|
|
| 343 |
|
|
| 344 |
|
/** Define two object creation methods. The first method, New(), |
| 345 |
|
* creates an object from a class but does not defer to a factory. |
| 346 |
|
* The second method, CreateAnother(), creates an object from an |
| 347 |
|
* instance, again without deferring to a factory. This second method |
| 348 |
|
* allows you to create an instance of an object that is exactly the |
| 349 |
|
* same type as the referring object. This is useful in cases where |
| 350 |
|
* an object has been cast back to a base class. |
| 351 |
|
* |
| 352 |
|
* These creation methods first try asking the object factory to create |
| 353 |
|
* an instance, and then default to the standard "new" operator if the |
| 354 |
|
* factory fails. |
| 355 |
|
* |
| 356 |
|
* These routines assigns the raw pointer to a smart pointer and then call |
| 357 |
|
* UnRegister() on the rawPtr to compensate for LightObject's constructor |
| 358 |
|
* initializing an object's reference count to 1 (needed for proper |
| 359 |
|
* initialization of process objects and data objects cycles). */ |
| 360 |
|
#define itkFactorylessNewMacro(x) \ |
| 361 |
|
static Pointer New(void) \ |
| 362 |
IND |
{ \ |
| 363 |
|
Pointer smartPtr; \ |
| 364 |
|
x *rawPtr = new x; \ |
| 365 |
|
smartPtr = rawPtr; \ |
| 366 |
|
rawPtr->UnRegister(); \ |
| 367 |
|
return smartPtr; \ |
| 368 |
IND |
} \ |
| 369 |
|
virtual LightObject::Pointer CreateAnother(void) const \ |
| 370 |
IND |
{ \ |
| 371 |
|
LightObject::Pointer smartPtr; \ |
| 372 |
|
smartPtr = x::New().GetPointer(); \ |
| 373 |
|
return smartPtr; \ |
| 374 |
IND |
} |
| 375 |
|
|
| 376 |
|
/** Macro used to add standard methods to all classes, mainly type |
| 377 |
|
* information. */ |
| 378 |
|
#define itkTypeMacro(thisClass,superclass) \ |
| 379 |
IND |
****virtual const char *GetNameOfClass() const \ |
| 380 |
IND |
********{return #thisClass;} |
| 381 |
|
|
| 382 |
|
|
| 383 |
|
namespace itk |
| 384 |
|
{ |
| 385 |
|
/** |
| 386 |
|
* The following is used to output debug, warning, and error messages. |
| 387 |
|
* Use a global function which actually calls: |
| 388 |
|
* OutputWindow::GetInstance()->DisplayText(); |
| 389 |
|
* This is to avoid Object #include of OutputWindow |
| 390 |
|
* while OutputWindow #includes Object. */ |
| 391 |
|
extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*); |
| 392 |
|
extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*); |
| 393 |
|
extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*); |
| 394 |
|
extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*); |
| 395 |
|
extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*); |
| 396 |
|
} // end namespace itk |
| 397 |
|
|
| 398 |
|
/** This macro is used to print debug (or other information). They are |
| 399 |
|
* also used to catch errors, etc. Example usage looks like: |
| 400 |
|
* itkDebugMacro(<< "this is debug info" << this->SomeVariable); */ |
| 401 |
|
#if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__) |
| 402 |
|
#define itkDebugMacro(x) |
| 403 |
|
#else |
| 404 |
|
#define itkDebugMacro(x) \ |
| 405 |
|
{ if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \ |
| 406 |
|
{ ::itk::OStringStream itkmsg; \ |
| 407 |
IND |
******itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \ |
| 408 |
|
<< this->GetNameOfClass() << " (" << this << "): " x \ |
| 409 |
|
<< "\n\n"; \ |
| 410 |
|
::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \ |
| 411 |
|
} |
| 412 |
|
#endif |
| 413 |
|
|
| 414 |
|
|
| 415 |
|
/** This macro is used to print warning information (i.e., unusual circumstance |
| 416 |
|
* but not necessarily fatal.) Example usage looks like: |
| 417 |
|
* itkWarningMacro(<< "this is warning info" << this->SomeVariable); */ |
| 418 |
|
#ifdef ITK_LEAN_AND_MEAN |
| 419 |
|
#define itkWarningMacro(x) |
| 420 |
|
#else |
| 421 |
|
#define itkWarningMacro(x) \ |
| 422 |
IND |
{ if (itk::Object::GetGlobalWarningDisplay()) \ |
| 423 |
|
{ ::itk::OStringStream itkmsg; \ |
| 424 |
IND |
******itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \ |
| 425 |
|
<< this->GetNameOfClass() << " (" << this << "): " x \ |
| 426 |
|
<< "\n\n"; \ |
| 427 |
|
itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \ |
| 428 |
|
} |
| 429 |
|
#endif |
| 430 |
|
|
| 431 |
|
namespace itk |
| 432 |
|
{ |
| 433 |
|
|
| 434 |
|
/** |
| 435 |
|
* itk::OStringStream wrapper to hide differences between |
| 436 |
|
* std::ostringstream and the old ostrstream. Necessary for |
| 437 |
|
* portability. |
| 438 |
|
*/ |
| 439 |
|
#if !defined(ITK_NO_ANSI_STRING_STREAM) |
| 440 |
|
class OStringStream: public std::ostringstream |
| 441 |
|
{ |
| 442 |
|
public: |
| 443 |
|
OStringStream() {} |
| 444 |
|
private: |
| 445 |
|
OStringStream(const OStringStream&); |
| 446 |
|
void operator=(const OStringStream&); |
| 447 |
|
}; |
| 448 |
|
#else |
| 449 |
|
namespace OStringStreamDetail |
| 450 |
|
{ |
| 451 |
|
class Cleanup |
| 452 |
IND |
**{ |
| 453 |
IND |
**public: |
| 454 |
|
Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {} |
| 455 |
|
~Cleanup() { m_OStrStream.rdbuf()->freeze(0); } |
| 456 |
IND |
****static void IgnoreUnusedVariable(const Cleanup&) {} |
| 457 |
IND |
**protected: |
| 458 |
IND |
****std::ostrstream& m_OStrStream; |
| 459 |
IND |
**}; |
| 460 |
|
}//namespace OStringStreamDetail |
| 461 |
|
|
| 462 |
|
class OStringStream: public std::ostrstream |
| 463 |
|
{ |
| 464 |
|
public: |
| 465 |
|
typedef std::ostrstream Superclass; |
| 466 |
|
OStringStream() {} |
| 467 |
|
std::string str() |
| 468 |
|
{ |
| 469 |
IND |
******OStringStreamDetail::Cleanup cleanup(*this); |
| 470 |
IND |
******OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup); |
| 471 |
IND |
******int pcount = this->pcount(); |
| 472 |
IND |
******const char* ptr = this->Superclass::str(); |
| 473 |
IND |
******return std::string(ptr?ptr:"", pcount); |
| 474 |
|
} |
| 475 |
|
private: |
| 476 |
|
OStringStream(const OStringStream&); |
| 477 |
|
void operator=(const OStringStream&); |
| 478 |
|
}; |
| 479 |
|
#endif |
| 480 |
|
|
| 481 |
|
}//namespace itk |
| 482 |
|
|
| 483 |
|
#if defined(ITK_CPP_FUNCTION) |
| 484 |
|
#if defined(__BORLANDC__) |
| 485 |
|
#define ITK_LOCATION __FUNC__ |
| 486 |
|
#elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
| 487 |
|
#define ITK_LOCATION __FUNCSIG__ |
| 488 |
|
#elif defined(__GNUC__) |
| 489 |
|
#define ITK_LOCATION __PRETTY_FUNCTION__ |
| 490 |
IND |
**#else |
| 491 |
|
#define ITK_LOCATION __FUNCTION__ |
| 492 |
|
#endif |
| 493 |
|
#else |
| 494 |
|
#define ITK_LOCATION "unknown" |
| 495 |
|
#endif |
| 496 |
|
|
| 497 |
|
#include "itkExceptionObject.h" |
| 498 |
|
|
| 499 |
|
/** The exception macro is used to print error information (i.e., usually |
| 500 |
|
* a condition that results in program failure). Example usage looks like: |
| 501 |
|
* itkExceptionMacro(<< "this is error info" << this->SomeVariable); */ |
| 502 |
|
#define itkExceptionMacro(x) \ |
| 503 |
|
{ \ |
| 504 |
|
::itk::OStringStream message; \ |
| 505 |
|
message << "itk::ERROR: " << this->GetNameOfClass() \ |
| 506 |
IND |
**********<< "(" << this << "): " x; \ |
| 507 |
LEN |
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \ |
| 508 |
|
throw e_; /* Explicit naming to work around Intel compiler bug. */ \ |
| 509 |
|
} |
| 510 |
|
|
| 511 |
|
#define itkGenericExceptionMacro(x) \ |
| 512 |
|
{ \ |
| 513 |
|
::itk::OStringStream message; \ |
| 514 |
|
message << "itk::ERROR: " x; \ |
| 515 |
LEN |
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \ |
| 516 |
|
throw e_; /* Explicit naming to work around Intel compiler bug. */ \ |
| 517 |
|
} |
| 518 |
|
|
| 519 |
|
#ifdef ITK_LEAN_AND_MEAN |
| 520 |
|
#define itkGenericOutputMacro(x) |
| 521 |
|
#else |
| 522 |
|
#define itkGenericOutputMacro(x) \ |
| 523 |
|
{ if (::itk::Object::GetGlobalWarningDisplay()) \ |
| 524 |
|
{ ::itk::OStringStream itkmsg; \ |
| 525 |
|
itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \ |
| 526 |
|
x << "\n\n"; \ |
| 527 |
|
itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \ |
| 528 |
|
} |
| 529 |
|
#endif |
| 530 |
|
|
| 531 |
|
|
| 532 |
EML |
|
| 533 |
|
//---------------------------------------------------------------------------- |
| 534 |
|
// Macros for simplifying the use of logging |
| 535 |
|
// |
| 536 |
|
#define itkLogMacro( x, y) \ |
| 537 |
|
{ \ |
| 538 |
|
if (this->GetLogger() ) \ |
| 539 |
|
{ \ |
| 540 |
|
this->GetLogger()->Write(::itk::LoggerBase::x, y); \ |
| 541 |
|
} \ |
| 542 |
IND |
} |
| 543 |
|
|
| 544 |
|
|
| 545 |
|
#define itkLogMacroStatic( obj, x, y) \ |
| 546 |
IND |
{ \ |
| 547 |
|
if (obj->GetLogger() ) \ |
| 548 |
|
{ \ |
| 549 |
|
obj->GetLogger()->Write(::itk::LoggerBase::x, y); \ |
| 550 |
|
} \ |
| 551 |
IND |
} |
| 552 |
|
|
| 553 |
|
|
| 554 |
|
//---------------------------------------------------------------------------- |
| 555 |
|
// Setup legacy code policy. |
| 556 |
|
|
| 557 |
|
// Define itkLegacy macro to mark legacy methods where they are |
| 558 |
|
// declared in their class. Example usage: |
| 559 |
|
// |
| 560 |
|
// // @deprecated Replaced by MyOtherMethod() as of ITK 2.0. |
| 561 |
|
// itkLegacy(void MyMethod()); |
| 562 |
|
#if defined(ITK_LEGACY_REMOVE) |
| 563 |
IND |
**// Remove legacy methods completely. |
| 564 |
|
# define itkLegacy(method) |
| 565 |
|
#elif defined(ITK_LEGACY_SILENT) || defined(ITK_WRAPPING_CXX) |
| 566 |
IND |
**// Provide legacy methods with no warnings. |
| 567 |
|
# define itkLegacy(method) method |
| 568 |
|
#else |
| 569 |
IND |
**// Setup compile-time warnings for uses of deprecated methods if |
| 570 |
IND |
**// possible on this compiler. |
| 571 |
LEN |
# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
| 572 |
|
# define itkLegacy(method) method __attribute__((deprecated)) |
| 573 |
|
# elif defined(_MSC_VER) && _MSC_VER >= 1300 |
| 574 |
|
# define itkLegacy(method) __declspec(deprecated) method |
| 575 |
|
# else |
| 576 |
|
# define itkLegacy(method) method |
| 577 |
|
# endif |
| 578 |
|
#endif |
| 579 |
|
|
| 580 |
|
// Macros to create runtime deprecation warning messages in function |
| 581 |
|
// bodies. Example usage: |
| 582 |
|
// |
| 583 |
|
// void itkMyClass::MyOldMethod() |
| 584 |
|
// { |
| 585 |
IND |
// itkLegacyBody(itkMyClass::MyOldMethod, 2.0); |
| 586 |
IND |
// } |
| 587 |
|
// |
| 588 |
|
// void itkMyClass::MyMethod() |
| 589 |
|
// { |
| 590 |
IND |
// itkLegacyReplaceBody(itkMyClass::MyMethod, 2.0, |
| 591 |
|
// itkMyClass::MyOtherMethod); |
| 592 |
IND |
// } |
| 593 |
|
#if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT) |
| 594 |
|
# define itkLegacyBody(method, version) |
| 595 |
|
# define itkLegacyReplaceBody(method, version, replace) |
| 596 |
|
#else |
| 597 |
|
# define itkLegacyBody(method, version) \ |
| 598 |
LEN,IND |
**itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.") |
| 599 |
|
# define itkLegacyReplaceBody(method, version, replace) \ |
| 600 |
LEN,IND |
**itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace " instead.") |
| 601 |
|
#endif |
| 602 |
|
|
| 603 |
|
|
| 604 |
|
#endif //end of itkMacro.h |
| 605 |
|
|
| 606 |
EOF |
|
| 607 |
EOF,EML |
|