Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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: 2005/10/24 16:00:47 $
00007   Version:   $Revision: 1.17 $
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 
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    if ( Archive.find(key) == Archive.end() )
00064    {
00065       // Save the old DocEntry if any
00066       DocEntry *old = ArchFile->GetDocEntry(group, elem);
00067       Archive[key]  = old;
00068       if ( old )
00069       {
00070          old->Register();
00071          ArchFile->RemoveEntry(old);
00072       }
00073 
00074       // Set the new DocEntry
00075       ArchFile->AddEntry(newEntry);
00076 
00077       return true;
00078    }
00079    return false;
00080 }
00081 
00090 bool DocEntryArchive::Push(uint16_t group, uint16_t elem)
00091 {
00092    TagKey key = DictEntry::TranslateToKey(group, elem);
00093 
00094    if ( Archive.find(key)==Archive.end() )
00095    {
00096       // Save the old DocEntry if any
00097       DocEntry *old = ArchFile->GetDocEntry(group, elem);
00098       Archive[key] = old;
00099       if ( old )
00100       {
00101          old->Register();
00102          ArchFile->RemoveEntry(old);
00103       }
00104 
00105       return true;
00106    }
00107    return false;
00108 }
00109 
00118 bool DocEntryArchive::Restore(uint16_t group, uint16_t elem)
00119 {
00120    TagKey key=DictEntry::TranslateToKey(group, elem);
00121 
00122    TagDocEntryHT::iterator restoreIt=Archive.find(key);
00123    if ( restoreIt!=Archive.end() )
00124    {
00125       // Delete the new value
00126       DocEntry *rem = ArchFile->GetDocEntry(group, elem);
00127       if ( rem )
00128       {
00129          ArchFile->RemoveEntry(rem);
00130       }
00131 
00132       // Restore the old value
00133       if ( restoreIt->second )
00134       {
00135          ArchFile->AddEntry(restoreIt->second);
00136          restoreIt->second->Unregister();
00137       }
00138 
00139       Archive.erase(restoreIt);
00140 
00141       return true;
00142    }
00143    return false;
00144 }
00145 
00150 void DocEntryArchive::ClearArchive( )
00151 {
00152    for(TagDocEntryHT::iterator it = Archive.begin();
00153        it!=Archive.end();
00154        ++it)
00155    {
00156       if(it->second)
00157          it->second->Unregister();
00158    }
00159    Archive.clear();
00160 }
00161 
00162 //-----------------------------------------------------------------------------
00163 // Protected
00164 
00165 //-----------------------------------------------------------------------------
00166 // Private
00167 
00168 //-----------------------------------------------------------------------------
00169 // Print
00174 void DocEntryArchive::Print(std::ostream &os) 
00175 {
00176    os << "Elements in archives :" << std::endl;
00177    for(TagDocEntryHT::iterator it = Archive.begin();
00178        it!=Archive.end();
00179        ++it)
00180    {
00181       if ( it->second )
00182          it->second->Print(os);
00183    }
00184 }
00185 
00186 //-----------------------------------------------------------------------------
00187 } // end namespace gdcm

Generated on Fri Jan 20 10:14:24 2006 for gdcm by  doxygen 1.4.4