]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
fix compilation warnings for the gdcm::Document::TransferSyntaxStrings
[gdcm.git] / src / gdcmDocument.cxx
index c5d391396cc11c60b7b040b24e07c9d19869ce90..0d32d8fc66d0c655e67a4dfbf2a5a0a4e3b87b4e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/24 11:17:47 $
-  Version:   $Revision: 1.136 $
+  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
 
@@ -1103,6 +1089,9 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
  */
 void Document::LoadEntryBinArea(BinEntry* element) 
 {
+   if(element->GetBinArea())
+      return;
+
    bool openFile = !Fp;
    if(openFile)
       OpenFile();
@@ -1274,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);
+   }
 }
 
 /**
@@ -1422,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
@@ -2554,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 :