[Insight-developers] Deriving non-itk classes from itk classes

Luis Ibanez ibanez@cs.unc.edu
Wed, 17 Jan 2001 12:50:40 -0500


Hi,

I'm creating a class that derives from itk::LightObject but that
is not intended to be put on itk namespace. The idea is to reuse 
itk's facilities without having to introduce this new class into 
itk. This class uses itk's SmartPointers and Observer/Command
functionalities.

In doing that there is a problem with the NewMacro, because it
is implicitly assumed that the macro will always be called inside
the itk namespace.

Specifically the problem arise with the use of  ObjectFactory outside
itk namespace.  One possible solution is to specify the namespace on 
the macro itself as "itk::ObjectFactory" instead of "ObjectFactory"
only.

Another option in principle is the "using itk::ObjectFactory" keyword,
but given that ObjectFactory is templated, it seems that the 'using'
line is useless if the template parameter is not given.

------------

The NewMacro would look like:

#define itkNewMacro(x) \
static Pointer New(void) \
{ \
  x *ret = itk::ObjectFactory<x>::Create(); \     // Here adding itk::
  if(ret != NULL) \
    { \
    return ret; \
    } \
  return new x; \
}

---------------

Could that be a problem for other classes ?

Is there a better way around this ?


Thanks


Luis