[Insight-users] What is the connection between 'SetFileName' and 'itkSetStringMacro'?

Luis Ibanez luis.ibanez at kitware.com
Mon Oct 23 14:26:49 EDT 2006


Hi Daniel,

This code is taking advantage of the C-Language preprocessor.

for details please read the following page from the Wikipedia.

       http://en.wikipedia.org/wiki/C_preprocessor

You may find useful to read also an introductory book to
C-Language programming.

--

In the context of ITK, we use Macros in order to generate
almost all the "Set", "Get" methods.


The "##" symbols in the macro describe the type of text string
replacement that should be applied.


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

for example, in the itk::ImageFileReader, the macro invocation


      itkSetStringMacro( FileName )

will be expanded to the following code

      void SetFileName( const char * _arg )
       {
       if ( _arg && (_arg == this->m_FileName) )
         { return;}
       if (_arg)
         {
         this->m_FileName = _arg; }
         else { this->m_FileName = ""; }
         this->Modified(); }
       }


If you invoke the gcc compiler with the option -E
it will simply run the C-preprocessor, which will
expand the Macros,and expand all the #includes in
your .cxx files, the output will be sent to the
standard output. Beware that this will generate very
large files in the case of ITK, but it is a good way
to learn about macro expansion.



Regards,


    Luis


=====================
daniel mark wrote:
> Hello all:
> 
> I have the following code:
> 
> typedef   itk::ImageFileReader< InputImageType >  ReaderType;
> ReaderType::Pointer   reader = ReaderType::New();
> reader->SetFileName( argv[1] );
> 
> #ifndef __itkImageFileReader_h
> #define __itkImageFileReader_h
> 
>  /** Specify the file to read. This is forwarded to the IO instance. */
>  itkSetStringMacro(FileName);
>  itkGetStringMacro(FileName);
> 
> #endif // __itkImageFileReader_h
> 
> I try to find where the definition of SetFileName is.
> 
> Finally, I got this:
> 
> #define itkSetStringMacro(name) virtual void Set##name (const char*
> _arg) { if ( _arg && (_arg == this->m_##name) ) { return;} if (_arg) {
> this->m_##name = _arg; } else { this->m_##name = ""; }
> this->Modified(); }
> 
> 
> The above snippet is totally out of my mind.
> 
> Can anyone give me what is going on here?
> or
> Point me to some places where I can find related C++ syntax.
> 
> Thank you
> -Daniel
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list