]> Creatis software - gdcm.git/commitdiff
* Remove memory leaks on the DicomDir
authorregrain <regrain>
Fri, 3 Dec 2004 17:13:17 +0000 (17:13 +0000)
committerregrain <regrain>
Fri, 3 Dec 2004 17:13:17 +0000 (17:13 +0000)
   * Remove some useless datas in DicomDirObject
   * Add usefull methods in SQItem, to be complient withe the ElementSet
   -- BeNours

19 files changed:
ChangeLog
Testing/TestAllEntryVerify.cxx
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmDicomDirImage.cxx
src/gdcmDicomDirImage.h
src/gdcmDicomDirMeta.cxx
src/gdcmDicomDirMeta.h
src/gdcmDicomDirObject.cxx
src/gdcmDicomDirObject.h
src/gdcmDicomDirPatient.cxx
src/gdcmDicomDirPatient.h
src/gdcmDicomDirSerie.cxx
src/gdcmDicomDirSerie.h
src/gdcmDicomDirStudy.cxx
src/gdcmDicomDirStudy.h
src/gdcmElementSet.cxx
src/gdcmSQItem.cxx
src/gdcmSQItem.h

index 30933f92bcbfcfd093d86a023ece6a13d56452b9..39408951478b8e3766a6b143e3485ce982671c29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-03 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * Remove memory leaks on the DicomDir
+   * Remove some useless datas in DicomDirObject
+   * Add usefull methods in SQItem, to be complient withe the ElementSet
+
 2004-12-03 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * src/gdcmFile.[h|cxx] : now use FileType instead of TWriteType.
 
index 0490f35291a66e7a0d57a4e60733ad00efa30d35..089a8ad7cced084ffbd5185de01dcbf5b8247a14 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllEntryVerify.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/16 04:28:20 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/12/03 17:13:17 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,6 +49,15 @@ std::string ParserException::Indent = "      ";
 
 class ReferenceFileParser
 {
+public:
+   ReferenceFileParser();
+   bool Open( std::string& referenceFileName );
+   void Print();
+   void SetDataPath(std::string&);
+   bool Check();
+   bool Check( std::string fileName );
+
+private:
    bool AddKeyValuePairToMap( std::string& key, std::string& value );
 
    std::istream& eatwhite(std::istream& is);
@@ -56,6 +65,7 @@ class ReferenceFileParser
    std::string ExtractFirstString(std::string& toSplit);
    void CleanUpLine( std::string& line );
 
+   bool Check( MapFileValuesType::iterator &fileIt );
    std::string ExtractValue(std::string& toSplit)  throw ( ParserException );
    void ParseRegularLine( std::string& line ) throw ( ParserException );
    void FirstPassReferenceFile()         throw ( ParserException );
@@ -64,12 +74,6 @@ class ReferenceFileParser
    void HandleKey( std::string& line )        throw ( ParserException );
    bool HandleValue( std::string& line )      throw ( ParserException );
    static uint16_t axtoi( char* );
-public:
-   ReferenceFileParser();
-   bool Open( std::string& referenceFileName );
-   void Print();
-   void SetDataPath(std::string&);
-   bool Check();
 private:
    /// The directory containing the images to check:
    std::string DataPath;
@@ -138,7 +142,8 @@ void ReferenceFileParser::SetDataPath( std::string& inDataPath )
    DataPath = inDataPath;
 }
 
-bool ReferenceFileParser::AddKeyValuePairToMap( std::string& key, std::string& value )
+bool ReferenceFileParser::AddKeyValuePairToMap( std::string& key, 
+                                                std::string& value )
 {
    if ( !CurrentMapEntryValuesPtr )
       return false;
@@ -173,63 +178,79 @@ void ReferenceFileParser::Print()
 
 bool ReferenceFileParser::Check()
 {
+   int ret = true;
    for (MapFileValuesType::iterator i  = ProducedMap.begin();
                                     i != ProducedMap.end();
                                     ++i)
    {
-      std::string fileName = DataPath + i->first;
-      std::cout << Indent << "FileName: " << fileName << std::endl;
-      gdcm::Header* tested = new gdcm::Header( fileName.c_str() );
-      if( !tested->IsReadable() )
-      {
-        std::cerr << Indent << "Image not gdcm compatible:"
+      ret &= Check(i);
+   }
+   std::cout << Indent << std::endl;
+   return ret;
+}
+
+bool ReferenceFileParser::Check( std::string fileName )
+{
+   MapFileValuesType::iterator it = ProducedMap.find(fileName);
+   if( it != ProducedMap.end() )
+   {
+      return Check(it);
+   }
+   std::cerr << Indent << "Failed\n"
+             << Indent << "Image not found :"
              << fileName << std::endl;
-        delete tested;
-        return false;
-      }
+   return false;
+}
 
-      MapEntryValuesPtr KeyValues = i->second;
-      for (MapEntryValues::iterator j  = KeyValues->begin();
-                                    j != KeyValues->end();
-                                    ++j)
-      {
-         std::string key = j->first;
+bool ReferenceFileParser::Check( MapFileValuesType::iterator &fileIt )
+{
+   std::string fileName = DataPath + fileIt->first;
+   std::cout << Indent << "FileName: " << fileName << std::endl;
+   gdcm::Header* tested = new gdcm::Header( fileName.c_str() );
+   if( !tested->IsReadable() )
+   {
+     std::cerr << Indent << "Failed\n"
+               << Indent << "Image not gdcm compatible:"
+               << fileName << std::endl;
+     delete tested;
+     return false;
+   }
 
-         std::string groupString  = key.substr( 0, 4 );
-         char* groupCharPtr;
-         groupCharPtr = new char(groupString.length() + 1);
-         strcpy( groupCharPtr, groupString.c_str() ); 
+   MapEntryValuesPtr KeyValues = fileIt->second;
+   for (MapEntryValues::iterator j  = KeyValues->begin();
+                                 j != KeyValues->end();
+                                 ++j)
+   {
+      std::string key = j->first;
 
-         std::string groupElement = key.substr( key.find_first_of( "|" ) + 1, 4 );
-         char* groupElementPtr;
-         groupElementPtr = new char(groupElement.length() + 1);
-         strcpy( groupElementPtr, groupElement.c_str() ); 
+      std::string groupString  = key.substr( 0, 4 );
+      std::string groupElement = key.substr( key.find_first_of( "|" ) + 1, 4 );
 
-         uint16_t group   = axtoi( groupCharPtr );
-         uint16_t element = axtoi( groupElementPtr );
+      uint16_t group   = axtoi( &(groupString[0]) );
+      uint16_t element = axtoi( &(groupElement[0]) );
 
-         std::string testedValue = tested->GetEntryByNumber(group, element);
-         if ( testedValue != j->second )
+      std::string testedValue = tested->GetEntryByNumber(group, element);
+      if ( testedValue != j->second )
+      {
+         // Oops make sure this is only the \0 that differ
+         if( testedValue[j->second.size()] != '\0' ||
+             strncmp(testedValue.c_str(), 
+                     j->second.c_str(), j->second.size()) != 0)
          {
-            // Oops make sure this is only the \0 that differ
-            if( testedValue[j->second.size()] != '\0' ||
-                strncmp(testedValue.c_str(), 
-                        j->second.c_str(), j->second.size()) != 0)
-            {
-               std::cout << Indent << "Uncorrect value for key " 
-                         << key << std::endl
-                         << Indent << "   read value      [" 
-                         << testedValue << "]" << std::endl
-                         << Indent << "   reference value [" 
-                         << j->second << "]" << std::endl;
+            std::cout << Indent << "Failed\n"
+                      << Indent << "Uncorrect value for key " 
+                      << key << std::endl
+                      << Indent << "   read value      [" 
+                      << testedValue << "]" << std::endl
+                      << Indent << "   reference value [" 
+                      << j->second << "]" << std::endl;
             return false;
-            }
          }
       }
-      delete tested;
-      std::cout << Indent << "  OK" << std::endl;
    }
-   std::cout << Indent << std::endl;
+   delete tested;
+   std::cout << Indent << "  OK" << std::endl;
+
    return true;
 }
 
@@ -274,8 +295,10 @@ std::string ReferenceFileParser::ExtractValue( std::string& toSplit )
    std::string::size_type   endPos = toSplit.find_last_of( '"' );
 
    // Make sure we have at most two " in toSplit:
-   std::string noQuotes = toSplit.substr( beginPos + 1, endPos - beginPos - 1);
-   if ( noQuotes.find_first_of( '"' ) != std::string::npos )
+   //std::string noQuotes = toSplit.substr( beginPos + 1, endPos - beginPos - 1);
+   //if ( noQuotes.find_first_of( '"' ) != std::string::npos )
+   //   throw ParserException( "more than two quote character" );
+   if ( toSplit.find_first_of( '"',beginPos+1 ) != endPos )
       throw ParserException( "more than two quote character" );
 
    // No leading quote means this is not a value:
@@ -610,10 +633,10 @@ bool ReferenceFileParser::SecondPassReferenceFile()
 
 int TestAllEntryVerify(int argc, char* argv[]) 
 {
-   if ( argc > 1 )
+   if ( argc > 2 )
    {
       std::cerr << "   Usage: " << argv[0]
-                << " (no arguments needed)." << std::endl;
+                << " fileName" << std::endl;
       return 1;
    }
 
@@ -629,7 +652,8 @@ int TestAllEntryVerify(int argc, char* argv[])
    std::cout << "   apply the following tests : "<< std::endl;
    std::cout << "   step 1: parse the image and call IsReadable(). "  << std::endl;
    std::cout << "   step 2: look for the entry corresponding to the image" << std::endl;
-   std::cout << "           in the reference file: " << referenceFilename << std::endl;
+   std::cout << "           in the reference file: \n" 
+             << "           " << referenceFilename << std::endl;
    std::cout << "   step 3: check that each reference tag value listed for this"
         << std::endl;
    std::cout << "           entry matches the tag encountered at parsing step 1."
@@ -638,13 +662,24 @@ int TestAllEntryVerify(int argc, char* argv[])
    ReferenceFileParser Parser;
    if ( !Parser.Open(referenceFilename) )
    {
-      std::cout << "   Corrupted reference file name: "
-           << referenceFilename << std::endl;
+      std::cout << "   failed"
+                << "   Corrupted reference file name: "
+                << referenceFilename << std::endl;
       return 1;
    }
    Parser.SetDataPath(referenceDir);
    // Parser.Print();
-   if ( Parser.Check() )
-      return 0;
-   return 1;
+   std::cout << "Reference fil loaded -->\n"
+             << "Check files : \n";
+
+   int ret;
+   if ( argc >= 2 )
+   {
+      ret = Parser.Check( argv[1] );
+   }
+   else
+   {
+      ret = Parser.Check(); 
+   }
+   return !ret;
 }
index ee3b95c18920c33bb0bf28ac6234044a2d54ea3c..8394a498c1ec4d84b623e87d9c6483938efafc65 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/30 17:04:01 $
-  Version:   $Revision: 1.83 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.84 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -61,7 +61,6 @@ DicomDir::DicomDir()
    :Document( )
 { 
    Initialize();  // sets all private fields to NULL
-   std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ...   
    MetaElems = NewMeta();
 }
 
@@ -86,7 +85,6 @@ DicomDir::DicomDir(std::string const & fileName, bool parseDir ):
    Initialize();  // sets all private fields to NULL
 
    // if user passed a root directory, sure we didn't get anything
-
    if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse
    {
       dbg.Verbose(0, "DicomDir::DicomDir : entry HT empty");
@@ -140,7 +138,6 @@ DicomDir::~DicomDir()
    SetProgressMethod(NULL);
    SetEndMethod(NULL);
 
-   TagHT.clear();
    for(ListDicomDirPatient::iterator cc = Patients.begin();
                                      cc!= Patients.end();
                                    ++cc)
@@ -221,7 +218,7 @@ void DicomDir::Initialize()
    Progress = 0.0;
    Abort = false;
 
-   MetaElems = 0;   
+   MetaElems = NULL;   
 }
 
 
@@ -390,6 +387,8 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
    }
 
    fp->close();
+   delete fp;
+
    return true;
 }
 
@@ -420,6 +419,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
          break;
       }
 
+std::cerr<<"File : "<<it->c_str()<<std::endl;
       header = new Header( it->c_str() );
       if( !header )
       {
@@ -427,6 +427,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
                       "DicomDir::CreateDicomDirChainedList: "
                       "failure in new Header ",
                       it->c_str() );
+         continue;
       }
       
       if( header->IsReadable() )
@@ -436,7 +437,6 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
          dbg.Verbose( 1,
                       "DicomDir::CreateDicomDirChainedList: readable ",
                       it->c_str() );
-
        }
        else
        {
@@ -451,6 +451,13 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
    //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
    SetElements(tmp, list);
    CallEndMethod();
+
+   for(VectDocument::iterator it=list.begin();
+       it!=list.end();
+       ++it)
+   {
+      delete dynamic_cast<Header *>(*it);
+   }
 }
 
 /**
@@ -460,7 +467,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path)
   
 DicomDirMeta * DicomDir::NewMeta()
 {
-   DicomDirMeta *m = new DicomDirMeta( &TagHT );
+   DicomDirMeta *m = new DicomDirMeta();
   
    if ( TagHT.begin() != TagHT.end() ) // after Document Parsing
    { 
@@ -497,7 +504,7 @@ DicomDirPatient * DicomDir::NewPatient()
 
    ListDicomDirPatientElem const & elemList =
       Global::GetDicomDirElements()->GetDicomDirPatientElements(); 
-   SQItem *s = new SQItem(0);
+   DicomDirPatient *p = new DicomDirPatient();
 
    // for all the DicomDirPatient Elements      
    for( it = elemList.begin(); it != elemList.end(); ++it ) 
@@ -531,10 +538,9 @@ DicomDirPatient * DicomDir::NewPatient()
       {
          entry->SetLength( entry->GetValue().length() );
       }
-      s->AddDocEntry( entry );
+      p->AddDocEntry( entry );
    }
 
-   DicomDirPatient *p = new DicomDirPatient(s, &TagHT);
    Patients.push_front( p );
 
    return p;
@@ -557,30 +563,57 @@ void DicomDir::SetElement(std::string const & path, DicomDirType type,
    DictEntry *dictEntry;
    ValEntry *entry;
    std::string val;
-   SQItem *si = new SQItem(0); // all the items will be at level 1
+   SQItem *si;
 
    switch( type )
    {
       case GDCM_DICOMDIR_IMAGE:
          elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
+         si = new DicomDirImage();
+         if( !AddDicomDirImageToEnd(static_cast<DicomDirImage *>(si)) )
+         {
+            dbg.Verbose(0,"DicomDir::SetElement:",
+                        "Add DicomDirImageToEnd failed");
+         }
          break;
-
       case GDCM_DICOMDIR_SERIE:
          elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
+         si = new DicomDirSerie();
+         if( !AddDicomDirSerieToEnd(static_cast<DicomDirSerie *>(si)) )
+         {
+            dbg.Verbose(0,"DicomDir::SetElement:",
+                        "Add DicomDirSerieToEnd failed");
+         }
          break;
-
       case GDCM_DICOMDIR_STUDY:
          elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
+         si = new DicomDirStudy();
+         if( !AddDicomDirStudyToEnd(static_cast<DicomDirStudy *>(si)) )
+         {
+            dbg.Verbose(0,"DicomDir::SetElement:",
+                        "Add DicomDirStudyToEnd failed");
+         }
          break;
-
       case GDCM_DICOMDIR_PATIENT:
          elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
+         si = new DicomDirPatient();
+         if( !AddDicomDirPatientToEnd(static_cast<DicomDirPatient *>(si)) )
+         {
+            dbg.Verbose(0,"DicomDir::SetElement:",
+                        "Add DicomDirPatientToEnd failed");
+         }
          break;
-  
       case GDCM_DICOMDIR_META:
          elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
+         si = new DicomDirMeta();
+         if( MetaElems )
+         {
+            dbg.Verbose(0,"DicomDir::SetElement:",
+                        "MetaElements already exist, they will be destroyed");
+            delete MetaElems;
+         }
+         MetaElems = static_cast<DicomDirMeta *>(si);
          break;
-
       default:
          return;
    }
@@ -682,30 +715,6 @@ void DicomDir::SetElement(std::string const & path, DicomDirType type,
       }
       si->AddEntry(entry);
    }
-   switch( type )
-   {
-      case GDCM_DICOMDIR_IMAGE:
-         AddDicomDirImageToEnd(si);
-         break;
-
-      case GDCM_DICOMDIR_SERIE:
-         AddDicomDirSerieToEnd(si);
-         break;
-
-      case GDCM_DICOMDIR_STUDY:
-         AddDicomDirStudyToEnd(si);
-         break;
-
-      case GDCM_DICOMDIR_PATIENT:
-         AddDicomDirPatientToEnd(si);
-         break;
-
-      default:
-         return;
-   }
-   //int count=1;            // find a trick to increment
-   //s->AddEntry(si, count); // Seg Faults 
-
 }
 
 //-----------------------------------------------------------------------------
@@ -790,6 +799,7 @@ void DicomDir::CreateDicomDir()
    
    DocEntry * d;
    std::string v;
+   SQItem * si;
    for( ListSQItem::iterator i = listItems.begin(); 
                              i !=listItems.end(); ++i ) 
    {
@@ -806,22 +816,26 @@ void DicomDir::CreateDicomDir()
 
       if( v == "PATIENT " )
       {
-         AddDicomDirPatientToEnd( *i );
+         si = new DicomDirPatient();
+         AddDicomDirPatientToEnd( static_cast<DicomDirPatient *>(si) );
          type = DicomDir::GDCM_DICOMDIR_PATIENT;
       }
       else if( v == "STUDY " )
       {
-         AddDicomDirStudyToEnd( *i );
+         si = new DicomDirStudy();
+         AddDicomDirStudyToEnd( static_cast<DicomDirStudy *>(si) );
          type = DicomDir::GDCM_DICOMDIR_STUDY;
       }
       else if( v == "SERIES" )
       {
-         AddDicomDirSerieToEnd( *i );
+         si = new DicomDirSerie();
+         AddDicomDirSerieToEnd( static_cast<DicomDirSerie *>(si) );
          type = DicomDir::GDCM_DICOMDIR_SERIE;
       }
       else if( v == "IMAGE " ) 
       {
-         AddDicomDirImageToEnd( *i );
+         si = new DicomDirImage();
+         AddDicomDirImageToEnd( static_cast<DicomDirImage *>(si) );
          type = DicomDir::GDCM_DICOMDIR_IMAGE;
       }
       else
@@ -830,20 +844,23 @@ void DicomDir::CreateDicomDir()
          // neither an 'IMAGE' SQItem. Skip to next item.
          continue;
       }
+      MoveSQItem(si,*i);
    }
+   TagHT.clear();
 }
 
 /**
  * \ingroup DicomDir
  * \brief Well ... there is only one occurence  
  */
-void DicomDir::AddDicomDirMeta()
+bool DicomDir::AddDicomDirMeta()
 {
    if( MetaElems )
    {
       delete MetaElems;
    }
-   MetaElems = new DicomDirMeta( &TagHT );
+   MetaElems = new DicomDirMeta();
+   return true;
 }
 
 /**
@@ -851,9 +868,10 @@ void DicomDir::AddDicomDirMeta()
  * \brief  AddDicomDirPatientToEnd 
  * @param   s SQ Item to enqueue to the DicomPatient chained List
  */
-void DicomDir::AddDicomDirPatientToEnd(SQItem *s)
+bool DicomDir::AddDicomDirPatientToEnd(DicomDirPatient *dd)
 {
-   Patients.push_back(new DicomDirPatient(s, &TagHT));
+   Patients.push_back(dd);
+   return true;
 }
 
 /**
@@ -861,14 +879,16 @@ void DicomDir::AddDicomDirPatientToEnd(SQItem *s)
  * \brief  AddDicomDirStudyToEnd 
  * @param   s SQ Item to enqueue to the DicomDirStudy chained List
  */
- void DicomDir::AddDicomDirStudyToEnd(SQItem *s)
+bool DicomDir::AddDicomDirStudyToEnd(DicomDirStudy *dd)
 {
    if( Patients.size() > 0 )
    {
       ListDicomDirPatient::iterator itp = Patients.end();
       itp--;
-      (*itp)->AddDicomDirStudy(new DicomDirStudy(s, &TagHT));
+      (*itp)->AddDicomDirStudy(dd);
+      return true;
    }
+   return false;
 }
 
 /**
@@ -876,7 +896,7 @@ void DicomDir::AddDicomDirPatientToEnd(SQItem *s)
  * \brief  AddDicomDirSerieToEnd 
  * @param   s SQ Item to enqueue to the DicomDirSerie chained List
  */
-void DicomDir::AddDicomDirSerieToEnd(SQItem *s)
+bool DicomDir::AddDicomDirSerieToEnd(DicomDirSerie *dd)
 {
    if( Patients.size() > 0 )
    {
@@ -888,9 +908,11 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s)
          ListDicomDirStudy::const_iterator itst = 
             (*itp)->GetDicomDirStudies().end();
          itst--;
-         (*itst)->AddDicomDirSerie(new DicomDirSerie(s, &TagHT));
+         (*itst)->AddDicomDirSerie(dd);
+         return true;
       }
    }
+   return false;
 }
 
 /**
@@ -898,7 +920,7 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s)
  * \brief   AddDicomDirImageToEnd
  * @param   s SQ Item to enqueue to the DicomDirImage chained List
  */
- void DicomDir::AddDicomDirImageToEnd(SQItem *s)
+bool DicomDir::AddDicomDirImageToEnd(DicomDirImage *dd)
 {
    if( Patients.size() > 0 )
    {
@@ -915,10 +937,12 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s)
          {
             ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end();
             its--;
-            (*its)->AddDicomDirImage(new DicomDirImage(s, &TagHT));
+            (*its)->AddDicomDirImage(dd);
+            return true;
          }
       }
    }
+   return false;
 }
 
 /**
@@ -940,32 +964,38 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
    std::string studCurInstanceUID, studCurID;
    std::string serCurInstanceUID,  serCurID;
 
+   bool first = true;
    for( VectDocument::const_iterator it = list.begin();
                                      it != list.end(); ++it )
    {
       // get the current file characteristics
-      patCurName         = (*it)->GetEntryByNumber(0x0010,0x0010); 
-      patCurID           = (*it)->GetEntryByNumber(0x0010,0x0011); 
-      studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);            
-      studCurID          = (*it)->GetEntryByNumber(0x0020,0x0010);            
-      serCurInstanceUID  = (*it)->GetEntryByNumber(0x0020,0x000e);            
+      patCurName         = (*it)->GetEntryByNumber(0x0010,0x0010);
+      patCurID           = (*it)->GetEntryByNumber(0x0010,0x0011);
+      studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d);
+      studCurID          = (*it)->GetEntryByNumber(0x0020,0x0010);
+      serCurInstanceUID  = (*it)->GetEntryByNumber(0x0020,0x000e);
       serCurID           = (*it)->GetEntryByNumber(0x0020,0x0011);
 
-      if( patCurName != patPrevName || patCurID != patPrevID)
+      if( patCurName != patPrevName || patCurID != patPrevID || first )
       {
          SetElement(path, GDCM_DICOMDIR_PATIENT, *it);
+         first = true;
       }
 
       // if new Study Deal with 'STUDY' Elements   
-      if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID )
+      if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID 
+         || first )
       {
          SetElement(path, GDCM_DICOMDIR_STUDY, *it);
+         first = true;
       }
 
       // if new Serie Deal with 'SERIE' Elements   
-      if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID )
+      if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID
+         || first )
       {
          SetElement(path, GDCM_DICOMDIR_SERIE, *it);
+         first = true;
       }
       
       // Always Deal with 'IMAGE' Elements  
@@ -977,6 +1007,29 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list)
       studPrevID          = studCurID;
       serPrevInstanceUID  = serCurInstanceUID;
       serPrevID           = serCurID;
+      first = false;
+   }
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief   Move the content of the src SQItem to the dst SQItem
+ *          Only DocEntry's are moved
+ * 
+ */
+void DicomDir::MoveSQItem(SQItem* dst,SQItem *src)
+{
+   DocEntry *entry;
+
+   src->Initialize();
+   entry = src->GetNextEntry();
+   while(entry)
+   {
+      src->RemoveEntryNoDestroy(entry);
+      dst->AddEntry(entry);
+
+      src->Initialize();
+      entry = src->GetNextEntry();
    }
 }
 
index c77f91a521781a529416f8b602a63ca5057142df..1666617019f5af659a1a17b982cf24bbc1a0ddc9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/16 10:25:53 $
-  Version:   $Revision: 1.39 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.40 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -119,15 +119,17 @@ protected:
 private:
    void Initialize();
    void CreateDicomDir();
-   void AddDicomDirMeta();
-   void AddDicomDirPatientToEnd(SQItem* s);
-   void AddDicomDirStudyToEnd  (SQItem* s);
-   void AddDicomDirSerieToEnd  (SQItem* s);
-   void AddDicomDirImageToEnd  (SQItem* s);
+
+   bool AddDicomDirMeta();
+   bool AddDicomDirPatientToEnd(DicomDirPatient* dd);
+   bool AddDicomDirStudyToEnd  (DicomDirStudy* dd);
+   bool AddDicomDirSerieToEnd  (DicomDirSerie* dd);
+   bool AddDicomDirImageToEnd  (DicomDirImage* dd);
 
    void SetElements(std::string const & path, VectDocument const &list);
    void SetElement (std::string const & path, DicomDirType type,
                     Document* header);
+   void MoveSQItem(SQItem* dst,SQItem *src);
 
    static bool HeaderLessThan(Document* header1, Document* header2);
    
index ba2134ab151f95aad522a223dff78aec1f87d12b..5a12172ec205491405edcca6737a78b2b94e2da9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirImage.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 03:35:19 $
-  Version:   $Revision: 1.13 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  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
@@ -23,28 +23,14 @@ namespace gdcm
 {
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-
-/**
- * \ingroup DicomDirImage
- * \brief  Constructor 
- * @param  s  SQ Item holding the elements
- * @param ptagHT pointer to the HTable (DicomDirObject needs it 
- *               to build the DocEntries)
- */
-DicomDirImage::DicomDirImage(SQItem *s, TagDocEntryHT *ptagHT):
-   DicomDirObject(ptagHT)
-{
-   DocEntries = s->GetDocEntries();
-}
-
 /**
  * \ingroup DicomDirImage
  * \brief  Constructor 
  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
  *               to build the DocEntries)
  */
-DicomDirImage::DicomDirImage(TagDocEntryHT *ptagHT):
-   DicomDirObject(ptagHT)
+DicomDirImage::DicomDirImage():
+   DicomDirObject()
 {
 }
 /**
index a1e101f526650d142a1025e1ec34f7a1dcf6b362..5731cd0ef874e5bbc7b2bf10ffc4f38935c00d95 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirImage.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 03:35:19 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,9 +27,7 @@ namespace gdcm
 class GDCM_EXPORT DicomDirImage : public DicomDirObject
 {
 public:
-   DicomDirImage(SQItem *s, TagDocEntryHT *ptagHT); 
-   DicomDirImage(TagDocEntryHT *ptagHT); 
-
+   DicomDirImage(); 
    ~DicomDirImage();
 
    void Print(std::ostream &os = std::cout);
index 64ff145978a9e942e7f96765e196a9b24ab00494..be4ecbfd679e931f04f5203c531beb2028d48e33 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:10 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -29,8 +29,8 @@ namespace gdcm
  * \ingroup DicomDirMeta
  * \brief  Constructor
  */ 
-DicomDirMeta::DicomDirMeta(TagDocEntryHT* ptagHT):
-   DicomDirObject(ptagHT)
+DicomDirMeta::DicomDirMeta():
+   DicomDirObject()
 {
 
 }
index 5a3059cbed8773b66882932bb5f0ade69a693818..9c50ee1607ef0d73bfc1aabe2f5f6e2a3c34f426 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,8 +27,7 @@ namespace gdcm
 class GDCM_EXPORT DicomDirMeta : public DicomDirObject 
 {
 public:
-   DicomDirMeta(TagDocEntryHT *ptagHT); 
-
+   DicomDirMeta(); 
    ~DicomDirMeta();
 
    virtual void Print(std::ostream &os = std::cout);
index 3997b0f2697e59ceadabc308c953462dd253b09b..882b8a2f3c7efb176b9e869575f61d26903a4cc7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirObject.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 04:08:20 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.8 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -33,10 +33,9 @@ namespace gdcm
  * @param depth Sequence depth level
  */
   
-DicomDirObject::DicomDirObject(TagDocEntryHT *ptagHT, int depth) 
+DicomDirObject::DicomDirObject(int depth) 
           : SQItem (depth)
 {
-   PtagHT = ptagHT;
 }
 
 
index 713682bafbf7a70e01fdaf5afe680c4d2f87c406..8503569b765c2edb27b4ee800f9f3d0472cce1d2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirObject.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 03:35:19 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.7 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -40,7 +40,7 @@ class GDCM_EXPORT DicomDirObject : public SQItem
 {
 public:
 
-   DicomDirObject(TagDocEntryHT *ptagHT, int depth = 0);
+   DicomDirObject(int depth = 1);
    ~DicomDirObject();
 
    /**
index f6a149a9441bae6430f4df28ad29e610d447270f..93a459cad3dab6104ed0ef41a01ff2753b3759b8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.20 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -26,22 +26,11 @@ namespace gdcm
 // Constructor / Destructor
 /**
  * \brief   Constructor
- * @param  s SQ Item holding the elements related to this "PATIENT" part
  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
  *               to build the HeaderEntries)
  */
-DicomDirPatient::DicomDirPatient(SQItem *s, TagDocEntryHT *ptagHT) :
-   DicomDirObject(ptagHT)
-{
-   DocEntries = s->GetDocEntries();
-}
-/**
- * \brief   Constructor
- * @param ptagHT pointer to the HTable (DicomDirObject needs it 
- *               to build the HeaderEntries)
- */
-DicomDirPatient::DicomDirPatient(TagDocEntryHT* ptagHT):
-   DicomDirObject(ptagHT)
+DicomDirPatient::DicomDirPatient():
+   DicomDirObject()
 {
 }
 /**
@@ -104,7 +93,7 @@ DicomDirStudy* DicomDirPatient::NewStudy()
    ListDicomDirStudyElem const & elemList = 
       Global::GetDicomDirElements()->GetDicomDirStudyElements();
       
-   DicomDirStudy* st = new DicomDirStudy( PtagHT );
+   DicomDirStudy* st = new DicomDirStudy();
    st->FillObject(elemList);
 
    Studies.push_front(st);
index f5e7ebfc4a4fb835e9f6120f4af32c3a2ef1d26d..2052d02576b89500866def097e0b58c6f1b40dda 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.13 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  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
@@ -33,9 +33,7 @@ typedef std::list<DicomDirStudy*> ListDicomDirStudy;
 class GDCM_EXPORT DicomDirPatient : public DicomDirObject 
 {
 public:
-   DicomDirPatient(SQItem *s, TagDocEntryHT *ptagHT); 
-   DicomDirPatient(TagDocEntryHT *ptagHT); 
-
+   DicomDirPatient(); 
    ~DicomDirPatient();
 
    void Print(std::ostream &os = std::cout);
index 13c3108059a531afec0558a35deb89000f8ae032..dcdd74656a78e0f350188884afd29170573631da 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,23 +27,11 @@ namespace gdcm
 // Constructor / Destructor
 /**
  * \brief  Constructor 
- * @param  s  SQ Item holding the elements related to this "SERIE" part
  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
  *               to build the DocEntries)
  */
-DicomDirSerie::DicomDirSerie(SQItem* s, TagDocEntryHT* ptagHT) :
-   DicomDirObject(ptagHT)
-{
-   DocEntries = s->GetDocEntries();
-}
-
-/**
- * \brief  Constructor 
- * @param ptagHT pointer to the HTable (DicomDirObject needs it 
- *               to build the DocEntries)
- */
-DicomDirSerie::DicomDirSerie(TagDocEntryHT* ptagHT):
-   DicomDirObject(ptagHT)
+DicomDirSerie::DicomDirSerie():
+   DicomDirObject()
 {
 }
 /**
@@ -106,7 +94,7 @@ DicomDirImage* DicomDirSerie::NewImage()
    ListDicomDirImageElem const & elemList = 
       Global::GetDicomDirElements()->GetDicomDirImageElements();
 
-   DicomDirImage* st = new DicomDirImage(PtagHT);
+   DicomDirImage* st = new DicomDirImage();
    FillObject(elemList);
    Images.push_front(st);
 
index 8021d859a0f5c3e072247833993a951edd2a03c4..4f4371a30b6d7c203aa52549278bac0e21290f23 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -31,9 +31,7 @@ typedef std::list<DicomDirImage *> ListDicomDirImage;
 class GDCM_EXPORT DicomDirSerie : public DicomDirObject 
 {
 public:
-   DicomDirSerie( SQItem* s, TagDocEntryHT* ptagHT ); 
-   DicomDirSerie( TagDocEntryHT* ptagHT ); 
-
+   DicomDirSerie(); 
    ~DicomDirSerie();
 
    void Print( std::ostream& os = std::cout );
index d15c62efa8c92aab7728a43a197614042599417b..a602cdd2503708084c2c7a0273c06070fa74dd60 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.19 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -24,27 +24,14 @@ namespace gdcm
 {
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-
-/**
- * \ingroup DicomDirStudy
- * \brief constructor  
- * @param  s SQ Item holding the elements related to this "STUDY" part
- * @param ptagHT pointer to the HTable (DicomDirObject needs it 
- *               to build the HeaderEntries)
- */
-DicomDirStudy::DicomDirStudy(SQItem* s, TagDocEntryHT* ptagHT):
-   DicomDirObject(ptagHT)
-{
-   DocEntries = s->GetDocEntries();
-}
 /**
  * \ingroup DicomDirStudy
  * \brief constructor  
  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
  *               to build the HeaderEntries)
  */
-DicomDirStudy::DicomDirStudy(TagDocEntryHT* ptagHT):
-   DicomDirObject(ptagHT)
+DicomDirStudy::DicomDirStudy():
+   DicomDirObject()
 {
 }
 /**
@@ -111,7 +98,7 @@ DicomDirSerie* DicomDirStudy::NewSerie()
    ListDicomDirSerieElem const & elemList = 
       Global::GetDicomDirElements()->GetDicomDirSerieElements();   
 
-   DicomDirSerie* st = new DicomDirSerie(PtagHT);
+   DicomDirSerie* st = new DicomDirSerie();
    FillObject(elemList);
    Series.push_front(st);
 
index 5a083f28ff76d39f7dd20f9e189371da621cbd1d..7ddd366631a2ea0adc2ce185bf2e875bee8458e6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.13 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  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
@@ -31,9 +31,7 @@ typedef std::list<DicomDirSerie *> ListDicomDirSerie;
 class GDCM_EXPORT DicomDirStudy : public DicomDirObject
 {
 public:
-   DicomDirStudy(SQItem *s, TagDocEntryHT *ptagHT); 
-   DicomDirStudy(TagDocEntryHT *ptagHT); 
-
+   DicomDirStudy(); 
    ~DicomDirStudy();
 
    void Print(std::ostream &os = std::cout);
index 0b60c37da9f498b6d40d225a8b0945cec9d40a2c..dd2c6d1976c5d0383d5846379ad972c0c3d473a8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.32 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.33 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -126,41 +126,41 @@ bool ElementSet::AddEntry(DocEntry* newEntry)
 }
 
 /**
- * \brief   Clear the hash table from given entry BUT keep the entry.
- * @param   entryToRemove Entry to remove.
+ * \brief   Clear the hash table from given entry AND delete the entry.
+ * @param   entryToRemove Entry to remove AND delete.
+ * \warning Some problems when using under Windows... prefer the use of
+ *          Initialize / GetNext methods
  */
-bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove)
+bool ElementSet::RemoveEntryDocEntry* entryToRemove)
 {
    const TagKey& key = entryToRemove->GetKey();
    if( TagHT.count(key) == 1 )
    {
       TagHT.erase(key);
       dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
+      delete entryToRemove;
       return true;
    }
 
-   dbg.Verbose(0, "ElementSet::RemoveEntry: key not present");
+   dbg.Verbose(0, "ElementSet::RemoveEntry: key not present");
    return false ;
 }
 
 /**
- * \brief   Clear the hash table from given entry AND delete the entry.
- * @param   entryToRemove Entry to remove AND delete.
- * \warning Some problems when using under Windows... prefer the use of
- *          Initialize / GetNext methods
+ * \brief   Clear the hash table from given entry BUT keep the entry.
+ * @param   entryToRemove Entry to remove.
  */
-bool ElementSet::RemoveEntryDocEntry* entryToRemove)
+bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove)
 {
    const TagKey& key = entryToRemove->GetKey();
    if( TagHT.count(key) == 1 )
    {
       TagHT.erase(key);
       dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
-      delete entryToRemove;
       return true;
    }
 
-   dbg.Verbose(0, "ElementSet::RemoveEntry: key not present");
+   dbg.Verbose(0, "ElementSet::RemoveEntry: key not present");
    return false ;
 }
 
index 073093641b8136986ca139f6472152158983c87b..62e506771508224ce7ddb841603af16380b2a3f4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/25 15:46:11 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  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
@@ -237,10 +237,83 @@ bool SQItem::SetEntryByNumber(std::string const & val, uint16_t group,
    }
    return false;
 }
-//-----------------------------------------------------------------------------
-// Protected
 
+/**
+ * \brief   Clear the hash table from given entry AND delete the entry.
+ * @param   entryToRemove Entry to remove AND delete.
+ * \warning Some problems when using under Windows... prefer the use of
+ *          Initialize / GetNext methods
+ */
+bool SQItem::RemoveEntry( DocEntry* entryToRemove)
+{
+   for(ListDocEntry::iterator it = DocEntries.begin();
+       it != DocEntries.end();
+       ++it)
+   {
+      if( *it == entryToRemove)
+      {
+         DocEntries.erase(it);
+         dbg.Verbose(0, "SQItem::RemoveEntry: one element erased.");
+         delete entryToRemove;
+         return true;
+      }
+   }
+                                                                                
+   dbg.Verbose(0, "SQItem::RemoveEntry: value not present ");
+   return false ;
+}
+                                                                                
+/**
+ * \brief   Clear the hash table from given entry BUT keep the entry.
+ * @param   entryToRemove Entry to remove.
+ */
+bool SQItem::RemoveEntryNoDestroy(DocEntry* entryToRemove)
+{
+   for(ListDocEntry::iterator it = DocEntries.begin();
+       it != DocEntries.end();
+       ++it)
+   {
+      if( *it == entryToRemove)
+      {
+         DocEntries.erase(it);
+         dbg.Verbose(0, "SQItem::RemoveEntry: one element erased.");
+         return true;
+      }
+   }
+                                                                                
+   dbg.Verbose(0, "SQItem::RemoveEntry: value not present ");
+   return false ;
+}
+                                                                                
+/**
+ * \brief   Initialise the visit of the chained list
+ */
+void SQItem::Initialize()
+{
+   ItDocEntries = DocEntries.begin();
+}
+                                                                                
+/**
+ * \brief   Get the next entry whil visiting the chained list
+ * \return  The next DocEntry if found, otherwhise NULL
+ */
+DocEntry *SQItem::GetNextEntry()
+{
+   if (ItDocEntries != DocEntries.end())
+   {
+      DocEntry *tmp = *ItDocEntries;
+      ++ItDocEntries;
+                                                                                
+      return(tmp);
+   }
+   else
+   {
+      return(NULL);
+   }
+}
 
+//-----------------------------------------------------------------------------
+// Protected
 /**
  * \brief   Gets a Dicom Element inside a SQ Item Entry, by number
  * @return
index be8594980047fcd3a6bc0a3bfca7a584ce92508b..e1ba7a5244b57103688b8b5ebf3b12ff1f3f81af 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/30 16:24:31 $
-  Version:   $Revision: 1.24 $
+  Date:      $Date: 2004/12/03 17:13:18 $
+  Version:   $Revision: 1.25 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -47,7 +47,9 @@ public:
    /// this SQ Item.      
    void AddDocEntry(DocEntry *e) { DocEntries.push_back(e); };
 
-   virtual bool AddEntry(DocEntry *Entry); // add to the List
+   bool AddEntry(DocEntry *Entry); // add to the List
+   bool RemoveEntry(DocEntry *EntryToRemove);
+   bool RemoveEntryNoDestroy(DocEntry *EntryToRemove);
   
    DocEntry *GetDocEntryByNumber(uint16_t group, uint16_t element);
    // FIXME method to write
@@ -76,12 +78,16 @@ public:
    /// Accessor on \ref BaseTagKey.
    BaseTagKey const & GetBaseTagKey() const { return BaseTagKeyNested; }
 
+   void Initialize();
+   DocEntry *GetNextEntry();
 
 protected:
 // Variables that need to be access in subclasses
 
-   /// \brief chained list of (Elementary) Doc Entries
+   /// \brief Chained list of (Elementary) Doc Entries
    ListDocEntry DocEntries;
+   /// Chained list iterator, used to visit the TagHT variable
+   ListDocEntry::iterator ItDocEntries;
    
    ///\brief pointer to the HTable of the Document,
    ///       (because we don't know it within any DicomDirObject nor any SQItem)