gdcmDocEntryArchive.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDocEntryArchive.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/05/23 14:18:09 $
00007   Version:   $Revision: 1.19 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #include "gdcmDocEntryArchive.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmDocEntry.h"
00022 
00023 #include <string>
00024 
00025 namespace GDCM_NAME_SPACE 
00026 {
00027 //-----------------------------------------------------------------------------
00028 // Constructor / Destructor
00032 DocEntryArchive::DocEntryArchive(File *file)
00033 {
00034    ArchFile = file;
00035 }
00036 
00040 DocEntryArchive::~DocEntryArchive()
00041 {
00042    ClearArchive();
00043 }
00044 
00045 //-----------------------------------------------------------------------------
00046 // Public
00054 bool DocEntryArchive::Push(DocEntry *newEntry)
00055 {
00056    if ( !newEntry )
00057       return false;
00058 
00059    //uint16_t group = newEntry->GetDictEntry()->GetGroup();
00060    //uint16_t elem  = newEntry->GetDictEntry()->GetElement();
00061    //TagKey key = DictEntry::TranslateToKey(group,elem);
00062 
00063    TagKey key = newEntry->GetKey();
00064    
00065    if ( Archive.find(key) == Archive.end() )
00066    {
00067       uint16_t group = newEntry->GetGroup();
00068       uint16_t elem  = newEntry->GetElement();
00069       
00070       // Save the old DocEntry if any
00071       DocEntry *old = ArchFile->GetDocEntry(group, elem);
00072       Archive[key]  = old;
00073       if ( old )
00074       {
00075          old->Register();
00076          ArchFile->RemoveEntry(old);
00077       }
00078 
00079       // Set the new DocEntry
00080       ArchFile->AddEntry(newEntry);
00081 
00082       return true;
00083    }
00084    return false;
00085 }
00086 
00095 bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
00096 {
00097    //TagKey key = DictEntry::TranslateToKey(group, elem);
00098    TagKey key(group, elem);
00099    if ( Archive.find(key)==Archive.end() )
00100    {
00101       // Save the old DocEntry if any
00102       DocEntry *old = ArchFile->GetDocEntry(group, elem);
00103       Archive[key] = old;
00104       if ( old )
00105       {
00106          old->Register();
00107          ArchFile->RemoveEntry(old);
00108       }
00109 
00110       return true;
00111    }
00112    return false;
00113 }
00114 
00123 bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
00124 {
00125    //TagKey key=DictEntry::TranslateToKey(group, elem);
00126    TagKey key(group, elem);
00127    TagDocEntryHT::iterator restoreIt=Archive.find(key);
00128    if ( restoreIt!=Archive.end() )
00129    {
00130       // Delete the new value
00131       DocEntry *rem = ArchFile->GetDocEntry(group, elem);
00132       if ( rem )
00133       {
00134          ArchFile->RemoveEntry(rem);
00135       }
00136 
00137       // Restore the old value
00138       if ( restoreIt->second )
00139       {
00140          ArchFile->AddEntry(restoreIt->second);
00141          restoreIt->second->Unregister();
00142       }
00143 
00144       Archive.erase(restoreIt);
00145 
00146       return true;
00147    }
00148    return false;
00149 }
00150 
00155 void DocEntryArchive::ClearArchive( )
00156 {
00157    for(TagDocEntryHT::iterator it = Archive.begin();
00158        it!=Archive.end();
00159        ++it)
00160    {
00161       if(it->second)
00162          it->second->Unregister();
00163    }
00164    Archive.clear();
00165 }
00166 
00167 //-----------------------------------------------------------------------------
00168 // Protected
00169 
00170 //-----------------------------------------------------------------------------
00171 // Private
00172 
00173 //-----------------------------------------------------------------------------
00174 // Print
00179 void DocEntryArchive::Print(std::ostream &os) 
00180 {
00181    os << "Elements in archives :" << std::endl;
00182    for(TagDocEntryHT::iterator it = Archive.begin();
00183        it!=Archive.end();
00184        ++it)
00185    {
00186       if ( it->second )
00187          it->second->Print(os);
00188    }
00189 }
00190 
00191 //-----------------------------------------------------------------------------
00192 } // end namespace gdcm

Generated on Fri Aug 24 12:53:14 2007 for gdcm by  doxygen 1.4.6