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-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]:
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)
#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})
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
#include "gdcmUtil.h"
#include "gdcmDebug.h"
-#include <errno.h>
#include <vector>
// For nthos:
}
// 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) )
* \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();
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
long lengthUntilEOF = ftell(Fp) - currentPosition;
fseek(Fp, currentPosition, SEEK_SET);
entry->SetLength(lengthUntilEOF);
- errno = 0;
return;
}
entry->SetLength(lengthOB);
{
if ( !IsExplicitVRBigEndianTransferSyntax() )
{
- dbg.Verbose(0, "gdcmDocument::FindLength", "not explicit VR");
- errno = 1;
+ throw gdcmFormatError( "gdcmDocument::FindDocEntryLength()",
+ " not explicit VR." );
return;
}
length16 = 4;
// 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
// not coexist in a Data Set and Data Sets nested within it".]
// Length is on 4 bytes.
- FixDocEntryFoundLength(entry, ReadInt32());
+ FixDocEntryFoundLength( entry, ReadInt32() );
return;
}
}
*/
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);
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;
}
* @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);
{
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;
}
* @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);
{
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;
}
* gets the VR, gets the length, gets the offset value)
* @return On succes the newly created DocEntry, NULL on failure.
*/
-gdcmDocEntry *gdcmDocument::ReadNextDocEntry()
+gdcmDocEntry* gdcmDocument::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;
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
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);
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);
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);
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
//-----------------------------------------------------------------------------
-/*
- * 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 ) { }
};
//-----------------------------------------------------------------------------