[Insight-developers] Enumeration type causes warning in XCode project

Luis Ibanez luis.ibanez at kitware.com
Sun Mar 18 08:01:31 EST 2007


Hi Mathieu,

Thanks a lot for contributing this patch.

The code looks good.
You followed quite well the ITK coding style.


There is only a small modification we would like make to the patch.
It is related to the GetConstReferenceEnumMacro().

It seems that we should only use a GetEnumMacro, that returns by
value and is const.  You did the right thing by following the
existing style of other macros in ITK. For the enums, however,
given that they are so small types, and that the Get method should
never be use as a way of modifying their value, it seems to be safer
to retain only the GetEnumMacro() and make its signature const.

We are testing this path now in an experimental build and we
anticipate to commit it later today.


   Regards


      Luis


=========================
Mathieu Coursolle wrote:
> Hi,
> 
> Here is a patch for 2007/03/13 version which fixes those warnings for
> the IO classes. I would really appreciated if someone could take a look
> at it so it could be commited.
> 
> Please let me know if it could be part of CVS version.
> Thanks a lot!
> 
> Mathieu
> 
> 
>>Hi,
>>
>>I added new macros in itkMacro.h to support enum types. As explained
>>previously,
>>the itkDebugMacro causes warnings on some platform (XCode) when it
>>receives an 
>>enum type.
>>
>>So I added in itkMacro.h:
>>
>>- itkSetEnumMacro
>>- itkGetEnumMacro
>>- itkGetConstReferenceEnumMacro.
>>
>>Those macro basically cast the enum type into a long value for output.
>>
>>I currently use them in:
>>
>>- itkImageIOBase.h
>>- itkGDCMImageIO.h
>>- itkDICOMSeriesFileNames.h
>>
>>Those all the only one I changed yet cause they are causing the warnings
>>in my application.
>>
>>If you agree to that change, I could parse all code and change whenever
>>an enum is use with the
>>itkDebugMacro. That fix would avoid lots of warnings when including itk
>>headers.
>>
>>Please let me know if you want a patch for this. I would really
>>appreciate those warnings to
>>go away...
>>
>>Thanks.
>>
>>Mathieu
>>
>>-- 
>>____________________________________________________________
>>Mathieu Coursolle                   mcoursolle at rogue-research.com
>>Rogue Research                      www.rogue-research.com 
>>Montréal, Québec, Canada
>>
>>
>>
>>>This warning is caused because the itkSetMacro is in the header files
>>
>>included
>>
>>>in my project, so the warnings are in my project.
>>>
>>>Casting at the point where the warning occur would mean to cast in that
>>>accessor. I could implement the Set accessor for the enum type members,
>>>and cast
>>>the enum into an long type for example in that implementation. Is the
>>>itkSetMacro
>>>use for another reason than avoid rewriting the same code everytime. I
>>
>>mean is
>>
>>>it a problem if this macro is replace by a Set method where the enum
> 
> would be
> 
>>>casted?
>>>
>>>Thanks.
>>>
>>>Mathieu
>>>
>>>
>>>>Another solution would be simply to cast the use of the enum values in
>>>>streaming expressions to avoid the warning. (Perhaps conditionally
>>>>based on some preprocessor definition.)
>>>>
>>>>Casting at the point where the warning occurs would be a "less
>>>>intrusive" and more obviously backwards compatible change...
>>>>
>>>>Yes?
>>>>David
>>>>
>>>>
>>>>On 2/23/07, Mathieu Coursolle <mcoursolle at rogue-research.com> wrote:
>>>>
>>>>>Hi,
>>>>>
>>>>>We are currently using ITK in a Cocoa application build with XCode.
>>>>>However, we get lots of warning related to enumeration types when
>>>>>including some ITK headers.
>>>>>
>>>>>Ex: Warning: choosing 'int' over 'long unsigned int'
>>>>>
>>>>>This is mainly caused by the itkDebugMacro, which uses the << operator
>>>>>of the itk::OStringStream to display some enum values. It seems like
>>>>>the compiler does not see the same type as the << operator for those
>>>>>enum types.
>>>>>
>>>>>Enum types might cause some issues asa they might not be of the same type
>>>>>according to the compiler (32 or 64 bits for example).
>>>>>
>>>>>A solution to fix those issues and related warning would be to set the
>>>>>type to use for those enums:
>>>>>
>>>>>Ex:  typedef enum { ELEMENT1, ELEMENT2, ELEMENT3} MyEnum;
>>>>>
>>>>>can be written:
>>>>>
>>>>>enum { ELEMENT1, ELEMENT2, ELEMENT3};
>>>>>typedef int MyEnum;
>>>>>
>>>>>This causes MyEnum to be used as an int in all cases. I changed
>>>>>the ones in itkImageIOBase.h, itkGDCMImageIO.h and DICOMSeriesFileName.h
>>>>>to get rid of all the warnings I had.
>>>>>
>>>>>I would like to know if you would agree to commit such a change to
>>>>>enumeration types in ITK.
>>>>>
>>>>>Thank you.
>>>>>
>>>>>Mathieu
>>>>>
>>>>>--
>>>>>____________________________________________________________
>>>>>Mathieu Coursolle                   mcoursolle at rogue-research.com
>>>>>Rogue Research                      www.rogue-research.com
>>>>>Montréal, Québec, Canada
>>>>>
>>>>>_______________________________________________
>>>>>Insight-developers mailing list
>>>>>Insight-developers at itk.org
>>>>>http://www.itk.org/mailman/listinfo/insight-developers
>>>>>
>>>>
>>>
>>>_______________________________________________
>>>Insight-developers mailing list
>>>Insight-developers at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-developers
>>>
>>
>>
>>
>>
>>
>>------------------------------------------------------------------------
>>
>>? Code/.DS_Store
>>Index: Code/Common/itkMacro.h
>>===================================================================
>>RCS file: /cvsroot/Insight/Insight/Code/Common/itkMacro.h,v
>>retrieving revision 1.69
>>diff -r1.69 itkMacro.h
>>188a189,237
>>
>>>  
>>>  /** Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
>>>  * This should be use when the type is an enum. It is use to avoid warnings on
>>>  * some compilers with non specified enum types passed to itkDebugMacro.*/
>>>#define itkSetEnumMacro(name,type) \
>>>  virtual void Set##name (const type _arg) \
>>>  { \
>>>    itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
>>>    if (this->m_##name != _arg) \
>>>      { \
>>>      this->m_##name = _arg; \
>>>      this->Modified(); \
>>>      } \
>>>  } 
>>>
>>>/** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility()); 
>>>  * This should be use when the type is an enum. It is use to avoid warnings on
>>>  * some compilers with non specified enum types passed to itkDebugMacro.*/
>>>#define itkGetEnumMacro(name,type) \
>>>  virtual type Get##name () \
>>>  { \
>>>    itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
>>>    return this->m_##name; \
>>>  }
>>>
>>>/** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
>>> * This is the "const" form of the itkGetMacro.  It should be used unless
>>> * the member can be changed through the "Get" access routine. 
>>> * This should be use when the type is an enum. It is use to avoid warnings on
>>> * some compilers with non specified enum types passed to itkDebugMacro.*/
>>>#define itkGetConstEnumMacro(name,type) \
>>>  virtual type Get##name () const \
>>>  { \
>>>    itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
>>>    return this->m_##name; \
>>>  }
>>>
>>>/** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
>>> * This is the "const" form of the itkGetMacro.  It should be used unless
>>> * the member can be changed through the "Get" access routine.
>>> * This versions returns a const reference to the variable. 
>>> * This should be use when the type is an enum. It is use to avoid warnings on
>>> * some compilers with non specified enum types passed to itkDebugMacro.*/
>>>#define itkGetConstReferenceEnumMacro(name,type) \
>>>  virtual const type & Get##name () const \
>>>  { \
>>>    itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
>>>    return this->m_##name; \
>>>  }
>>
>>Index: Code/IO/itkDICOMSeriesFileNames.h
>>===================================================================
>>RCS file: /cvsroot/Insight/Insight/Code/IO/itkDICOMSeriesFileNames.h,v
>>retrieving revision 1.10
>>diff -r1.10 itkDICOMSeriesFileNames.h
>>131,132c131,132
>><   itkSetMacro(FileNameSortingOrder, FileNameSortingOrderType);
>><   itkGetMacro(FileNameSortingOrder, FileNameSortingOrderType);
>>---
>>
>>>  itkSetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
>>>  itkGetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
>>
>>Index: Code/IO/itkGDCMImageIO.h
>>===================================================================
>>RCS file: /cvsroot/Insight/Insight/Code/IO/itkGDCMImageIO.h,v
>>retrieving revision 1.30
>>diff -r1.30 itkGDCMImageIO.h
>>211,212c211,212
>><   itkSetMacro(CompressionType,TCompressionType);
>><   itkGetConstReferenceMacro(CompressionType,TCompressionType);
>>---
>>
>>>  itkSetEnumMacro(CompressionType,TCompressionType);
>>>  itkGetConstReferenceEnumMacro(CompressionType,TCompressionType);
>>
>>Index: Code/IO/itkImageIOBase.h
>>===================================================================
>>RCS file: /cvsroot/Insight/Insight/Code/IO/itkImageIOBase.h,v
>>retrieving revision 1.40
>>diff -r1.40 itkImageIOBase.h
>>136,137c136,137
>><   itkSetMacro(PixelType, IOPixelType);
>><   itkGetConstReferenceMacro(PixelType, IOPixelType);
>>---
>>
>>>  itkSetEnumMacro(PixelType, IOPixelType);
>>>  itkGetConstReferenceEnumMacro(PixelType, IOPixelType);
>>
>>149,150c149,150
>><   itkSetMacro(ComponentType,IOComponentType);
>><   itkGetConstReferenceMacro(ComponentType,IOComponentType);
>>---
>>
>>>  itkSetEnumMacro(ComponentType,IOComponentType);
>>>  itkGetConstReferenceEnumMacro(ComponentType,IOComponentType);
>>
>>182,183c182,183
>><   itkSetMacro(FileType,FileType);
>><   itkGetConstReferenceMacro(FileType,FileType);
>>---
>>
>>>  itkSetEnumMacro(FileType,FileType);
>>>  itkGetConstReferenceEnumMacro(FileType,FileType);
>>
>>200,201c200,201
>><   itkSetMacro(ByteOrder,ByteOrder);
>><   itkGetConstReferenceMacro(ByteOrder,ByteOrder);
>>---
>>
>>>  itkSetEnumMacro(ByteOrder,ByteOrder);
>>>  itkGetConstReferenceEnumMacro(ByteOrder,ByteOrder);
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>Insight-developers mailing list
>>>Insight-developers at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list