| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkLightObject.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 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 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkLightObject_h |
| 18 |
|
#define __itkLightObject_h |
| 19 |
|
|
| 20 |
|
#if defined(_MSC_VER) |
| 21 |
|
#pragma warning ( disable : 4786 ) |
| 22 |
|
#endif |
| 23 |
|
|
| 24 |
|
#include <iostream> |
| 25 |
|
#include <typeinfo> |
| 26 |
|
|
| 27 |
|
#include "itkSmartPointer.h" |
| 28 |
|
#include "itkTimeStamp.h" |
| 29 |
|
#include "itkIndent.h" |
| 30 |
|
#include "itkSimpleFastMutexLock.h" |
| 31 |
|
|
| 32 |
|
#include "itkMacro.h" |
| 33 |
|
|
| 34 |
|
namespace itk |
| 35 |
|
{ |
| 36 |
|
|
| 37 |
|
/** \class LightObject |
| 38 |
|
* \brief Light weight base class for most itk classes. |
| 39 |
|
* |
| 40 |
|
* LightObject is the highest level base class for most itk objects. It |
| 41 |
|
* implements reference counting and the API for object printing. |
| 42 |
|
* It can be used as a lightweight base class in preference to Object. |
| 43 |
|
* (LightObject does not support callbacks or modified time as Object |
| 44 |
|
* does.) All ITK objects should be a subclass of LightObject or Object |
| 45 |
|
* with few exceptions (due to performance concerns). |
| 46 |
|
* |
| 47 |
|
* \sa Object |
| 48 |
|
* \ingroup ITKSystemObjects |
| 49 |
|
* \ingroup DataRepresentation |
| 50 |
|
*/ |
| 51 |
|
class ITKCommon_EXPORT LightObject |
| 52 |
|
{ |
| 53 |
|
public: |
| 54 |
|
/** Standard clas typedefs. */ |
| 55 |
|
typedef LightObject Self; |
| 56 |
|
typedef SmartPointer<Self> Pointer; |
| 57 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 58 |
|
|
| 59 |
|
/** Method for creation through the object factory. */ |
| 60 |
|
static Pointer New(); |
| 61 |
|
|
| 62 |
|
/** Create an object from an instance, potentially deferring to a |
| 63 |
|
* factory. This method allows you to create an instance of an |
| 64 |
|
* object that is exactly the same type as the referring object. |
| 65 |
|
* This is useful in cases where an object has been cast back to a |
| 66 |
|
* base class. */ |
| 67 |
|
virtual Pointer CreateAnother() const; |
| 68 |
|
|
| 69 |
|
/** Delete an itk object. This method should always be used to delete an |
| 70 |
|
* object when the new operator was used to create it. Using the C |
| 71 |
|
* delete method will not work with reference counting. */ |
| 72 |
|
virtual void Delete(); |
| 73 |
|
|
| 74 |
|
/** Return the name of this class as a string. Used by the object factory |
| 75 |
|
* (implemented in New()) to instantiate objects of a named type. Also |
| 76 |
|
* used for debugging and other output information. */ |
| 77 |
|
virtual const char *GetNameOfClass() const |
| 78 |
|
{return "LightObject";} |
| 79 |
|
|
| 80 |
|
#ifdef _WIN32 |
| 81 |
|
/** Used to avoid dll boundary problems. */ |
| 82 |
|
void* operator new(size_t); |
| 83 |
|
void* operator new[](size_t); |
| 84 |
|
void operator delete(void*); |
| 85 |
|
void operator delete[](void*, size_t); |
| 86 |
|
#endif |
| 87 |
|
|
| 88 |
|
/** Cause the object to print itself out. */ |
| 89 |
|
void Print(std::ostream& os, Indent indent=0) const; |
| 90 |
|
|
| 91 |
|
/** This method is called when itkExceptionMacro executes. It allows |
| 92 |
|
* the debugger to break on error. */ |
| 93 |
|
static void BreakOnError(); |
| 94 |
|
|
| 95 |
|
/** Increase the reference count (mark as used by another object). */ |
| 96 |
|
virtual void Register() const; |
| 97 |
|
|
| 98 |
|
/** Decrease the reference count (release by another object). */ |
| 99 |
|
virtual void UnRegister() const; |
| 100 |
|
|
| 101 |
|
/** Gets the reference count on this object. */ |
| 102 |
|
virtual int GetReferenceCount() const |
| 103 |
|
{return m_ReferenceCount;} |
| 104 |
|
|
| 105 |
|
/** Sets the reference count on this object. This is a dangerous |
| 106 |
|
* method, use it with care. */ |
| 107 |
|
virtual void SetReferenceCount(int); |
| 108 |
|
|
| 109 |
|
protected: |
| 110 |
|
LightObject():m_ReferenceCount(1) {} |
| 111 |
|
virtual ~LightObject(); |
| 112 |
|
|
| 113 |
|
/** Methods invoked by Print() to print information about the object |
| 114 |
|
* including superclasses. Typically not called by the user (use Print() |
| 115 |
|
* instead) but used in the hierarchical print process to combine the |
| 116 |
|
* output of several classes. */ |
| 117 |
|
virtual void PrintSelf(std::ostream& os, Indent indent) const; |
| 118 |
|
virtual void PrintHeader(std::ostream& os, Indent indent) const; |
| 119 |
|
virtual void PrintTrailer(std::ostream& os, Indent indent) const; |
| 120 |
|
|
| 121 |
|
/** Number of uses of this object by other objects. */ |
| 122 |
|
mutable int m_ReferenceCount; |
| 123 |
|
|
| 124 |
|
/** Mutex lock to protect modification to the reference count */ |
| 125 |
|
mutable SimpleFastMutexLock m_ReferenceCountLock; |
| 126 |
|
|
| 127 |
|
private: |
| 128 |
|
LightObject(const Self&); //purposely not implemented |
| 129 |
|
void operator=(const Self&); //purposely not implemented |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
}; |
| 133 |
|
|
| 134 |
|
} // end namespace itk |
| 135 |
|
|
| 136 |
|
#endif |
| 137 |
|
|