]> Creatis software - gdcm.git/commitdiff
* gdcmPython/CMakeLists.txt: SWIG_FLAGS doesn't declare includeall
authorfrog <frog>
Mon, 2 Aug 2004 14:06:57 +0000 (14:06 +0000)
committerfrog <frog>
Mon, 2 Aug 2004 14:06:57 +0000 (14:06 +0000)
    to avoid inclusion recursion until STL is reached.
  * src/gdcmDocument.[h|cxx]: exceptions substituted to errno C-style
    mecanism. errno.h is not included in gdcm anymore.
  * src/gdcmException.h: introduced new gdcmFormatUnexpected class
    (gdcmFormatError now inherits from gdcmFormatUnexpected).
  * TODO updated

ChangeLog
TODO
gdcmPython/CMakeLists.txt
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmException.h

index 3a66c1681c2a0b5f8ace74ec8d55946a86080c59..84ed0664eb362ff04076c3eac9f1a3ba87ff591b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-08-02 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+  * gdcmPython/CMakeLists.txt: SWIG_FLAGS doesn't declare includeall
+    to avoid inclusion recursion until STL is reached.
+  * src/gdcmDocument.[h|cxx]: exceptions substituted to errno C-style
+    mecanism. errno.h is not included in gdcm anymore.
+  * src/gdcmException.h: introduced new gdcmFormatUnexpected class
+    (gdcmFormatError now inherits from gdcmFormatUnexpected).
+  * TODO updated
+
 2004-07-06 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
   * src/gdcmDicomDir.cxx, gdcmDocEntrySet.cxx: removed inclusion of errno.h
   * src/gdcmDocument.[h|cxx], gdcmFile.[h|cxx], gdcmHeader.[h|cxx]:
diff --git a/TODO b/TODO
index 31b1fe9881afc3a2e7302f258bc653da894a0d40..86c7f7cbbc69e7a7defb9f3b42ac74dc7a48fc08 100644 (file)
--- a/TODO
+++ b/TODO
@@ -16,21 +16,6 @@ Convert the C-like IO to C++ IO:
         binary IO are available at
         http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html
 -----------------------------------------------------------------------------
-Switch from errno C-style to exceptions:
-  Goal: remove all the C-oriented errno (#include <errno.h>) and switch
-        to C++ exceptions.
-  Note: - only src/gdcmDocument.cxx includes errno.h
-        - when exceptions were first introduced within gdcm, it caused 
-        gdcmPython to be uncompatible within the corresponding version
-        of wxPython (refer to the first lines of
-        Test/ExceptionAndPython/README). Hence we reverted to the old
-        errno mecanisme. Since wxPython seems not to be problem anymore
-        (check it with Test/ExceptionAndPython) we can now move back to C++
-        exceptions.
------------------------------------------------------------------------------
-CLEANUP:
- - Remove ignore_shadow from gdcmDocument().
------------------------------------------------------------------------------
 * vtk/vtkGdcmHeader.cxx: if speed becomes a concern some changes can
   be made at the cost of memory consumption (refer to header of 
   vtk/vtkGdcmHeader.cxx)
index 2b094c63d663b250120ba7b9335f667075e676fd..4c9ebd0e7bf3d955948c3fd988ab8ef37ec44257 100644 (file)
@@ -22,7 +22,16 @@ IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
 
   #SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES PYTHON ON)
   SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON)
-  SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall")
+  # Setting SWIG_FLAGS to "-includeall" at the following line looks like
+  # a bad idea since swig tries to reculsively include all the referenced
+  # files, "including" the C++ <sstream>, <list>, <map>... Of course swig
+  # has no way of finding the path to those files (unless it is told by
+  # cmake) since they are related to the compiler installation layout.
+  # Anyhow, since this inclusion recursion is not necessary, just don't
+  # do it.
+  # Note: apparently the line is required in order to avoid a NOTFOUND
+  #       as argument of swig on invocation of make.
+  SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "")
   SWIG_ADD_MODULE(gdcm python gdcm.i)  #gdcm_wrap.cxx
   SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES})
   
index 36d1703c4d4548d6973ea45e747ad937fa2323db..22b095702fa39597e72f807781f800e2cb6bafd2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 03:20:23 $
-  Version:   $Revision: 1.63 $
+  Date:      $Date: 2004/08/02 14:06:57 $
+  Version:   $Revision: 1.64 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -25,7 +25,6 @@
 #include "gdcmUtil.h"
 #include "gdcmDebug.h"
 
-#include <errno.h>
 #include <vector>
 
 // For nthos:
@@ -1499,8 +1498,12 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry)
       }
       // to be sure we are at the end of the value ...
       fseek(Fp, (long)entry->GetOffset()+(long)entry->GetLength(), SEEK_SET);      
-
-      return;  //FIXME FIXME FIXME FIXME ????
+      // Following return introduced by JPR on version 1.25. Since the 
+      // treatement of a ValEntry is never executed (doh!) this means
+      // we were lucky up to now because we NEVER encountered a ValEntry
+      // whose length was bigger thant MaxSizeLoadEntry !? I can't believe
+      // this could ever work...
+      return;  //FIXME FIXME FIXME FIXME JPR ????
 
        // Be carefull : a BinEntry IS_A ValEntry ... 
       if (gdcmValEntry* valEntryPtr = dynamic_cast< gdcmValEntry* >(entry) )
@@ -1618,7 +1621,8 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry)
  * \brief  Find the value Length of the passed Header Entry
  * @param  Entry Header Entry whose length of the value shall be loaded. 
  */
-void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
+void gdcmDocument::FindDocEntryLength( gdcmDocEntry *entry )
+   throw ( gdcmFormatError )
 {
    uint16_t element = entry->GetElement();
    std::string  vr  = entry->GetVR();
@@ -1637,8 +1641,12 @@ void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
 
          if ( vr == "OB" && length32 == 0xffffffff ) 
          {
-            uint32_t lengthOB = FindDocEntryLengthOB();
-            if ( errno == 1 )
+            uint32_t lengthOB;
+            try 
+            {
+               lengthOB = FindDocEntryLengthOB();
+            }
+            catch ( gdcmFormatUnexpected )
             {
                // Computing the length failed (this happens with broken
                // files like gdcm-JPEG-LossLess3a.dcm). We still have a
@@ -1650,7 +1658,6 @@ void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
                long lengthUntilEOF = ftell(Fp) - currentPosition;
                fseek(Fp, currentPosition, SEEK_SET);
                entry->SetLength(lengthUntilEOF);
-               errno = 0;
                return;
             }
             entry->SetLength(lengthOB);
@@ -1694,8 +1701,8 @@ void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
       {
          if ( !IsExplicitVRBigEndianTransferSyntax() ) 
          {
-            dbg.Verbose(0, "gdcmDocument::FindLength", "not explicit VR");
-            errno = 1;
+            throw gdcmFormatError( "gdcmDocument::FindDocEntryLength()",
+                                   " not explicit VR." );
             return;
          }
          length16 = 4;
@@ -1719,11 +1726,10 @@ void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
       // Heuristic: well, some files are really ill-formed.
       if ( length16 == 0xffff) 
       {
+         // 0xffff means that we deal with 'Unknown Length' Sequence  
          length16 = 0;
-         // Length16= 0xffff means that we deal with
-         // 'Unknown Length' Sequence  
       }
-      FixDocEntryFoundLength(entry, (uint32_t)length16);
+      FixDocEntryFoundLength( entry, (uint32_t)length16 );
       return;
    }
    else
@@ -1735,7 +1741,7 @@ void gdcmDocument::FindDocEntryLength (gdcmDocEntry *entry)
       // not coexist in a Data Set and Data Sets nested within it".]
       // Length is on 4 bytes.
       
-      FixDocEntryFoundLength(entry, ReadInt32());
+      FixDocEntryFoundLength( entry, ReadInt32() );
       return;
    }
 }
@@ -2150,6 +2156,7 @@ bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *entry)
  */
 
 uint32_t gdcmDocument::FindDocEntryLengthOB()
+   throw( gdcmFormatUnexpected )
 {
    // See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
    long positionOnEntry = ftell(Fp);
@@ -2158,26 +2165,33 @@ uint32_t gdcmDocument::FindDocEntryLengthOB()
 
    while ( !foundSequenceDelimiter )
    {
-      uint16_t g = ReadInt16();
-      uint16_t n = ReadInt16();   
-      if ( errno == 1 )
+      uint16_t group;
+      uint16_t elem;
+      try
       {
-         return 0;
+         group = ReadInt16();
+         elem  = ReadInt16();   
+      }
+      catch ( gdcmFormatError )
+      {
+         throw gdcmFormatError("gdcmDocument::FindDocEntryLengthOB()",
+                               " group or element not present.");
       }
 
       // We have to decount the group and element we just read
       totalLength += 4;
      
-      if ( g != 0xfffe || ( n != 0xe0dd && n != 0xe000 ) )
+      if ( group != 0xfffe || ( ( elem != 0xe0dd ) && ( elem != 0xe000 ) ) )
       {
-         dbg.Verbose(1, "gdcmDocument::FindLengthOB: neither an Item tag "
-                        "nor a Sequence delimiter tag."); 
+         dbg.Verbose(1, "gdcmDocument::FindDocEntryLengthOB: neither an Item "
+                        "tag nor a Sequence delimiter tag."); 
          fseek(Fp, positionOnEntry, SEEK_SET);
-         errno = 1;
-         return 0;
+         throw gdcmFormatUnexpected("gdcmDocument::FindDocEntryLengthOB()",
+                                    "Neither an Item tag nor a Sequence "
+                                    "delimiter tag.");
       }
 
-      if ( n == 0xe0dd )
+      if ( elem == 0xe0dd )
       {
          foundSequenceDelimiter = true;
       }
@@ -2202,6 +2216,7 @@ uint32_t gdcmDocument::FindDocEntryLengthOB()
  * @return read value
  */
 uint16_t gdcmDocument::ReadInt16()
+   throw( gdcmFormatError )
 {
    uint16_t g;
    size_t item_read = fread (&g, (size_t)2,(size_t)1, Fp);
@@ -2209,12 +2224,10 @@ uint16_t gdcmDocument::ReadInt16()
    {
       if( ferror(Fp) )
       {
-         dbg.Verbose(0, "gdcmDocument::ReadInt16", " File Error");
+         throw gdcmFormatError( "gdcmDocument::ReadInt16()", " file error." );
       }
-      errno = 1;
-      return 0;
+      throw gdcmFormatError( "gdcmDocument::ReadInt16()", "EOF." );
    }
-   errno = 0;
    g = SwapShort(g); 
    return g;
 }
@@ -2225,6 +2238,7 @@ uint16_t gdcmDocument::ReadInt16()
  * @return read value
  */
 uint32_t gdcmDocument::ReadInt32()
+   throw( gdcmFormatError )
 {
    uint32_t g;
    size_t item_read = fread (&g, (size_t)4,(size_t)1, Fp);
@@ -2232,12 +2246,10 @@ uint32_t gdcmDocument::ReadInt32()
    {
       if( ferror(Fp) )
       {
-         dbg.Verbose(0, "gdcmDocument::ReadInt32", " File Error");
+         throw gdcmFormatError( "gdcmDocument::ReadInt16()", " file error." );
       }
-      errno = 1;
-      return 0;
+      throw gdcmFormatError( "gdcmDocument::ReadInt32()", "EOF." );
    }
-   errno = 0;
    g = SwapLong(g);
    return g;
 }
@@ -2524,28 +2536,39 @@ void gdcmDocument::SetMaxSizePrintEntry(long newSize)
  *          gets the VR, gets the length, gets the offset value)
  * @return  On succes the newly created DocEntry, NULL on failure.      
  */
-gdcmDocEntry *gdcmDocument::ReadNextDocEntry()
+gdcmDocEntrygdcmDocument::ReadNextDocEntry()
 {
-   uint16_t g = ReadInt16();
-   uint16_t n = ReadInt16();
+   uint16_t group;
+   uint16_t elem;
 
-   if (errno == 1)
+   try
+   {
+      group = ReadInt16();
+      elem  = ReadInt16();
+   }
+   catch ( gdcmFormatError e )
    {
       // We reached the EOF (or an error occured) therefore 
       // header parsing has to be considered as finished.
+      std::cout << e;
       return 0;
    }
-   gdcmDocEntry *newEntry = NewDocEntryByNumber(g, n);
 
+   gdcmDocEntry *newEntry = NewDocEntryByNumber(group, elem);
    FindDocEntryVR(newEntry);
-   FindDocEntryLength(newEntry);
 
-   if (errno == 1)
+   try
+   {
+      FindDocEntryLength(newEntry);
+   }
+   catch ( gdcmFormatError e )
    {
       // Call it quits
+      std::cout << e;
       delete newEntry;
       return 0;
    }
+
    newEntry->SetOffset(ftell(Fp));  
 
    return newEntry;
index b5d1523731de8e184bc34113b1b1b191a92c5227..0923cfb6a430d281b52b0d35d558cca97f140a40 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/01 03:20:23 $
-  Version:   $Revision: 1.28 $
+  Date:      $Date: 2004/08/02 14:06:58 $
+  Version:   $Revision: 1.29 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -131,7 +131,7 @@ public:
 
    FileType GetFileType();
 
-   FILE* OpenFile(bool exception_on_error = false) throw(gdcmFileError);
+   FILE* OpenFile(bool exception_on_error = false) throw( gdcmFileError );
    bool CloseFile();
 
    void Write(FILE* fp, FileType type);
@@ -202,7 +202,7 @@ private:
    long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode); 
    
    void LoadDocEntry      (gdcmDocEntry *);
-   void FindDocEntryLength(gdcmDocEntry *);
+   void FindDocEntryLength(gdcmDocEntry *) throw ( gdcmFormatError );
    void FindDocEntryVR    (gdcmDocEntry *);
    bool CheckDocEntryVR   (gdcmDocEntry *, gdcmVRKey);
 
@@ -215,10 +215,10 @@ private:
    void FixDocEntryFoundLength(gdcmDocEntry *, uint32_t);
    bool IsDocEntryAnInteger   (gdcmDocEntry *);
 
-   uint32_t FindDocEntryLengthOB();
+   uint32_t FindDocEntryLengthOB() throw( gdcmFormatUnexpected );
 
-   uint16_t ReadInt16();
-   uint32_t ReadInt32();
+   uint16_t ReadInt16() throw ( gdcmFormatError );
+   uint32_t ReadInt32() throw ( gdcmFormatError );
    void     SkipBytes(uint32_t);
    bool     ReadTag(uint16_t, uint16_t);
    uint32_t ReadTagLength(uint16_t, uint16_t);
index 95d9a3c56115ee3b6fc85c2ccdc450b9d7d84fa4..7d486158db40fe5ae6f2f8334a1feae4e5c0374b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmException.h,v $
   Language:  C++
-  Date:      $Date: 2004/06/20 18:08:47 $
-  Version:   $Revision: 1.13 $
+  Date:      $Date: 2004/08/02 14:06:58 $
+  Version:   $Revision: 1.14 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -95,22 +95,33 @@ public:
 
 
 //-----------------------------------------------------------------------------
-/*
- * Invalid file format exception
+/**
+ * \brief Unexpected file format exception
  */
-class GDCM_EXPORT gdcmFormatError : public gdcmException {
+class GDCM_EXPORT gdcmFormatUnexpected : public gdcmException {
 public:
-   /*
-    * Builds an file-related exception with minimal information: name of
-    * the thrower method and error message
-    *
-    * @param from name of the thrower
-    * @param error error description string
-    */
+   /// \brief Builds a file-related exception with minimal information:
+   /// name of the thrower method and error message
+   /// @param from name of the thrower
+   /// @param error error description string
+   explicit gdcmFormatUnexpected(const std::string &from,
+                            const std::string &error = "Unexpected file format")
+      throw() : gdcmException( from, error ) { }
+};
+
+//-----------------------------------------------------------------------------
+/**
+ * \brief Invalid file format exception
+ */
+class GDCM_EXPORT gdcmFormatError : public gdcmFormatUnexpected {
+public:
+   /// \brief Builds a file-related exception with minimal information:
+   /// name of the thrower method and error message
+   /// @param from name of the thrower
+   /// @param error error description string
    explicit gdcmFormatError(const std::string &from,
-                            const std::string &error = "Invalid file format error")
-      throw() : gdcmException(from, error) {
-   }
+                            const std::string &error = "Invalid file format")
+      throw() : gdcmFormatUnexpected( from, error ) { }
 };
 
 //-----------------------------------------------------------------------------