]> Creatis software - gdcm.git/blobdiff - src/gdcmDocEntry.cxx
* src/gdcmDocEntry.[h|cxx] : now the ReadLength is the length of the datas
[gdcm.git] / src / gdcmDocEntry.cxx
index dce3028c11a37db9e755f09601d39df20b7f836b..c1317163a9503b1c98a1b42d15aa0077d9b8c3df 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:41 $
-  Version:   $Revision: 1.28 $
+  Date:      $Date: 2005/01/07 16:45:51 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -18,6 +18,7 @@
 
 #include "gdcmDocEntry.h"
 #include "gdcmTS.h"
+#include "gdcmVR.h"
 #include "gdcmGlobal.h"
 #include "gdcmUtil.h"
 
@@ -37,12 +38,16 @@ namespace gdcm
  * \brief   Constructor from a given DictEntry
  * @param   in Pointer to existing dictionary entry
  */
-DocEntry::DocEntry(DictEntryin)
+DocEntry::DocEntry(DictEntry *in)
 {
    ImplicitVR = false;
    DicomDict  = in;
    SetKey( in->GetKey( ) );
    Offset     = 0 ; // To avoid further missprinting
+
+   // init some variables
+   ReadLength = 0;
+   Length = 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -52,29 +57,26 @@ DocEntry::DocEntry(DictEntry* in)
  * \brief   Prints the common part of ValEntry, BinEntry, SeqEntry
  * @param   os ostream we want to print in
  */
-void DocEntry::Print(std::ostreamos)
+void DocEntry::Print(std::ostream &os)
 {
-   PrintLevel = 2; // FIXME
-   
    size_t o;
-   unsigned short int g, e;
    std::string st;
    TSKey v;
    std::string d2, vr;
    std::ostringstream s;
    uint32_t lgth;
 
-   g  = GetGroup();
-   e  = GetElement();
    o  = GetOffset();
    vr = GetVR();
+   if(vr==GDCM_UNKNOWN)
+      vr="  ";
 
    s << DictEntry::TranslateToKey(GetGroup(),GetElement()); 
 
    if (PrintLevel >= 2)
    {
       s << " lg : ";
-      lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
+      lgth = GetReadLength(); // ReadLength, as opposed to Length
       if (lgth == 0xffffffff)
       {
          st = Util::Format("x(ffff)");  // I said : "x(ffff)" !
@@ -118,13 +120,13 @@ void DocEntry::Print(std::ostream& os)
  * @param fp already open file pointer
  * @param filetype type of the file to be written
  */
-void DocEntry::Write(std::ofstream* fp, FileType filetype)
+void DocEntry::WriteContent(std::ofstream *fp, FileType filetype)
 {
    uint32_t ffff  = 0xffffffff;
    uint16_t group = GetGroup();
    VRKey vr   = GetVR();
    uint16_t el    = GetElement();
-   uint32_t lgr   = GetReadLength();
+   uint32_t lgr   = GetLength();
 
    if ( group == 0xfffe && el == 0x0000 )
    {
@@ -137,9 +139,9 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
    //
    // ----------- Writes the common part
    //
-   fp->write ((char*) &group,(size_t)2 );  //group
-   fp->write ( (char*)&el,   (size_t)2 );  //element
-      
+   binary_write( *fp, group);  //group
+   binary_write( *fp, el);  //element
+
    if ( filetype == ExplicitVR )
    {
       // Special case of delimiters:
@@ -155,44 +157,44 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
 
          // TODO : verify if the Sequence Delimitor Item was forced during Parsing 
 
-         int ff = 0xffffffff;
-         fp->write ((char*)&ff,(size_t)4 );
+         uint32_t ff = 0xffffffff;
+         binary_write(*fp, ff);
          return;
       }
 
       uint16_t z = 0;
       uint16_t shortLgr = lgr;
 
-      if (vr == "unkn")
+      if (vr == GDCM_UNKNOWN)
       {
          // Unknown was 'written'
          // deal with Little Endian            
-         fp->write ( (char*)&shortLgr,(size_t)2 );
-         fp->write ( (char*)&z,       (size_t)2 );
+         binary_write(*fp, shortLgr);
+         binary_write(*fp, z);
       }
       else
       {
-         fp->write (vr.c_str(),(size_t)2 ); 
-
+         binary_write(*fp, vr);
+         assert( vr.size() == 2 );
                   
          if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
          {
-            fp->write ( (char*)&z,  (size_t)2 );
+            binary_write(*fp, z);
             if (vr == "SQ")
             {
                // we set SQ length to ffffffff
                // and  we shall write a Sequence Delimitor Item 
                // at the end of the Sequence! 
-               fp->write ( (char*)&ffff,(size_t)4 );
+               binary_write(*fp, ffff);
             }
             else
             {
-               fp->write ( (char*)&lgr,(size_t)4 );
+               binary_write(*fp, lgr);
             }
          }
          else
          {
-            fp->write ( (char*)&shortLgr,(size_t)2 );
+            binary_write(*fp, shortLgr);
          }
       }
    } 
@@ -200,11 +202,11 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
    { 
       if (vr == "SQ")
       {
-         fp->write ( (char*)&ffff,(size_t)4 );
+         binary_write(*fp, ffff);
       }
       else
       {
-         fp->write ( (char*)&lgr,(size_t)4 );
+         binary_write(*fp, lgr);
       }
    }
 }
@@ -242,14 +244,12 @@ uint32_t DocEntry::GetFullLength()
  * \ingroup DocEntry
  * \brief   Copies all the attributes from an other DocEntry 
  */
-void DocEntry::Copy (DocEntrye)
+void DocEntry::Copy (DocEntry *e)
 {
-   DicomDict    = e->DicomDict;
-   UsableLength = e->UsableLength;
-   ReadLength   = e->ReadLength;
-   ImplicitVR   = e->ImplicitVR;
-   Offset       = e->Offset;
-   PrintLevel   = e->PrintLevel;
+   Length     = e->Length;
+   ReadLength = e->ReadLength;
+   ImplicitVR = e->ImplicitVR;
+   Offset     = e->Offset;
    // TODO : remove DocEntry SQDepth
 }