Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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/02/01 10:29:55 $
00007   Version:   $Revision: 1.11 $
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    std::string 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          ArchFile->RemoveEntryNoDestroy(old);
00070 
00071       // Set the new DocEntry
00072       ArchFile->AddEntry(newEntry);
00073 
00074       return true;
00075    }
00076    return false;
00077 }
00078 
00087 bool DocEntryArchive::Push(uint16_t group,uint16_t elem)
00088 {
00089    std::string key = DictEntry::TranslateToKey(group,elem);
00090 
00091    if( Archive.find(key)==Archive.end() )
00092    {
00093       // Save the old DocEntry if any
00094       DocEntry *old = ArchFile->GetDocEntry(group,elem);
00095       Archive[key] = old;
00096       if( old )
00097          ArchFile->RemoveEntryNoDestroy(old);
00098 
00099       return true;
00100    }
00101    return false;
00102 }
00103 
00112 bool DocEntryArchive::Restore(uint16_t group,uint16_t elem)
00113 {
00114    std::string key=DictEntry::TranslateToKey(group,elem);
00115 
00116    TagDocEntryHT::iterator restoreIt=Archive.find(key);
00117    if( restoreIt!=Archive.end() )
00118    {
00119       // Delete the new value
00120       DocEntry *rem = ArchFile->GetDocEntry(group,elem);
00121       if( rem )
00122          ArchFile->RemoveEntry(rem);
00123 
00124       // Restore the old value
00125       if( Archive[key] )
00126          ArchFile->AddEntry(Archive[key]);
00127 
00128       Archive.erase(restoreIt);
00129 
00130       return true;
00131    }
00132    return false;
00133 }
00134 
00139 void DocEntryArchive::ClearArchive( )
00140 {
00141    for(TagDocEntryHT::iterator it = Archive.begin();
00142        it!=Archive.end();
00143        ++it)
00144    {
00145       delete it->second;
00146    }
00147    Archive.clear();
00148 }
00149 
00150 //-----------------------------------------------------------------------------
00151 // Protected
00152 
00153 //-----------------------------------------------------------------------------
00154 // Private
00155 
00156 //-----------------------------------------------------------------------------
00157 // Print
00162 void DocEntryArchive::Print(std::ostream &os) 
00163 {
00164    os << "Elements in archives :" << std::endl;
00165    for(TagDocEntryHT::iterator it = Archive.begin();
00166        it!=Archive.end();
00167        ++it)
00168    {
00169       if(it->second)
00170          it->second->Print(os);
00171    }
00172 }
00173 
00174 //-----------------------------------------------------------------------------
00175 } // end namespace gdcm

Generated on Thu Feb 10 22:17:30 2005 for gdcm by doxygen 1.3.6