]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
fix compilation warnings for the gdcm::Document::TransferSyntaxStrings
[gdcm.git] / src / gdcmDocument.cxx
index 62f5b9d211c61ca98c97cdf0fe3583977dee59f6..0d32d8fc66d0c655e67a4dfbf2a5a0a4e3b87b4e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/17 19:49:13 $
-  Version:   $Revision: 1.134 $
+  Date:      $Date: 2004/11/25 16:35:16 $
+  Version:   $Revision: 1.141 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,6 +36,7 @@
 
 namespace gdcm 
 {
+//-----------------------------------------------------------------------------
 static const char *TransferSyntaxStrings[] =  {
   // Implicit VR Little Endian
   "1.2.840.10008.1.2",
@@ -70,7 +71,7 @@ static const char *TransferSyntaxStrings[] =  {
   // Unknown
   "Unknown Transfer Syntax"
 };
-
+                                                                                
 //-----------------------------------------------------------------------------
 // Refer to Document::CheckSwap()
 const unsigned int Document::HEADER_LENGTH_TO_READ = 256;
@@ -481,41 +482,22 @@ bool Document::CloseFile()
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  * \return Always true.
  */
-void Document::Write(std::ofstream* fp, FileType filetype)
+void Document::WriteContent(std::ofstream* fp, FileType filetype)
 {
    /// \todo move the following lines (and a lot of others, to be written)
    /// to a future function CheckAndCorrectHeader  
    /// (necessary if user wants to write a DICOM V3 file
    /// starting from an  ACR-NEMA (V2)  Header
 
-   if (filetype == ImplicitVR) 
-   {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       in the following case we have to padd manually with a 0
-      
-      SetEntryLengthByNumber(18, 0x0002, 0x0010);
-   } 
-
-   if (filetype == ExplicitVR)
+   if ( filetype == ImplicitVR || filetype == ExplicitVR )
    {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); //LEAK
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       Dans le cas suivant on doit pader manuellement avec un 0
-      
-      SetEntryLengthByNumber(20, 0x0002, 0x0010);
+      // writing Dicom File Preamble
+      char filePreamble[128];
+      memset(filePreamble, 0, 128);
+      fp->write(filePreamble, 128);
+      fp->write("DICM", 4);
    }
-  
+
 /**
  * \todo rewrite later, if really usefull
  *       - 'Group Length' element is optional in DICOM
@@ -528,8 +510,7 @@ void Document::Write(std::ofstream* fp, FileType filetype)
  *    UpdateGroupLength(true,ACR);
  */
  
-   ElementSet::Write(fp, filetype); // This one is recursive
-
+   ElementSet::WriteContent(fp, filetype); // This one is recursive
 }
 
 /**
@@ -757,6 +738,11 @@ bool Document::ReplaceIfExistByNumber(std::string const & value,
    return true;
 } 
 
+std::string Document::GetTransferSyntaxValue(TransferSyntaxType type)
+{
+   return TransferSyntaxStrings[type];
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
@@ -1065,7 +1051,12 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
    if ( !docElement )
       return;
 
-   size_t o =(size_t)docElement->GetOffset();
+   BinEntry *binElement = dynamic_cast<BinEntry *>(docElement);
+   if( !binElement )
+      return;
+
+   LoadEntryBinArea(binElement);
+/*   size_t o =(size_t)docElement->GetOffset();
    Fp->seekg( o, std::ios_base::beg);
    size_t l = docElement->GetLength();
    uint8_t* a = new uint8_t[l];
@@ -1088,8 +1079,9 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
    {
       delete[] a;
       dbg.Verbose(0, "Document::LoadEntryBinArea setting failed.");
-   }
+   }*/
 }
+
 /**
  * \brief         Loads (from disk) the element content 
  *                when a string is not suitable
@@ -1097,8 +1089,16 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
  */
 void Document::LoadEntryBinArea(BinEntry* element) 
 {
+   if(element->GetBinArea())
+      return;
+
+   bool openFile = !Fp;
+   if(openFile)
+      OpenFile();
+
    size_t o =(size_t)element->GetOffset();
    Fp->seekg(o, std::ios_base::beg);
+
    size_t l = element->GetLength();
    uint8_t* a = new uint8_t[l];
    if( !a )
@@ -1116,6 +1116,9 @@ void Document::LoadEntryBinArea(BinEntry* element)
    }
 
    element->SetBinArea(a);
+
+   if(openFile)
+      CloseFile();
 }
 
 /**
@@ -1260,9 +1263,12 @@ ValEntry* Document::GetValEntryByNumber(uint16_t group, uint16_t element)
  */
 void Document::LoadDocEntrySafe(DocEntry * entry)
 {
-   long PositionOnEntry = Fp->tellg();
-   LoadDocEntry(entry);
-   Fp->seekg(PositionOnEntry, std::ios_base::beg);
+   if(Fp)
+   {
+      long PositionOnEntry = Fp->tellg();
+      LoadDocEntry(entry);
+      Fp->seekg(PositionOnEntry, std::ios_base::beg);
+   }
 }
 
 /**
@@ -1389,10 +1395,12 @@ void Document::ParseDES(DocEntrySet *set, long offset,
 
             if (delimitor)
             {
+               delete newDocEntry;
                break;
             }
             if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
             {
+               delete newDocEntry;
                break;
             }
          }
@@ -1406,9 +1414,6 @@ void Document::ParseDES(DocEntrySet *set, long offset,
             }
 
          //////////////////// BinEntry or UNKOWN VR:
-/*            BinEntry* newBinEntry =
-               new BinEntry( newDocEntry->GetDictEntry() );  //LEAK
-            newBinEntry->Copy( newDocEntry );*/
             BinEntry* newBinEntry = new BinEntry( newDocEntry );  //LEAK
 
             // When "this" is a Document the Key is simply of the
@@ -1457,6 +1462,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
     
          // Just to make sure we are at the beginning of next entry.
          SkipToNextDocEntry(newDocEntry);
+         //delete newDocEntry;
       }
       else
       {
@@ -1508,6 +1514,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          set->AddEntry( newSeqEntry );
          if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
          {
+            delete newDocEntry;
             break;
          }
       }
@@ -1537,13 +1544,14 @@ void Document::ParseSQ( SeqEntry* seqEntry,
       {
          if ( newDocEntry->IsSequenceDelimitor() )
          {
-            seqEntry->SetSequenceDelimitationItem( newDocEntry );
+            seqEntry->SetSequenceDelimitationItem( newDocEntry ); 
             break;
          }
       }
       if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
       {
-          break;
+         delete newDocEntry;
+         break;
       }
 
       SQItem *itemSQ = new SQItem( seqEntry->GetDepthLevel() );
@@ -1565,6 +1573,7 @@ void Document::ParseSQ( SeqEntry* seqEntry,
       }
    
       ParseDES(itemSQ, newDocEntry->GetOffset(), l, dlm_mod);
+      delete newDocEntry;
       
       seqEntry->AddEntry( itemSQ, SQItemNumber ); 
       SQItemNumber++;
@@ -2534,7 +2543,7 @@ bool Document::CheckSwap()
    // representation of a 32 bits integer. Hence the following dirty
    // trick :
    s32 = *((uint32_t *)(entCur));
-      
+
    switch( s32 )
    {
       case 0x00040000 :