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

gdcmElementSet.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmElementSet.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/07 08:48:18 $
00007   Version:   $Revision: 1.58 $
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 "gdcmElementSet.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmValEntry.h"
00022 #include "gdcmBinEntry.h"
00023 #include "gdcmSeqEntry.h"
00024 
00025 namespace gdcm 
00026 {
00027 //-----------------------------------------------------------------------------
00028 // Constructor / Destructor
00032 //BOZ depthLevel is not usefull anymore
00033 ElementSet::ElementSet(int depthLevel) 
00034           : DocEntrySet()
00035 {
00036   (void)depthLevel;
00037 }
00038 
00042 ElementSet::~ElementSet() 
00043 {
00044    ClearEntry();
00045 }
00046 
00047 //-----------------------------------------------------------------------------
00048 // Public
00055 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
00056 {
00057    for (TagDocEntryHT::const_iterator i = TagHT.begin(); 
00058                                      i != TagHT.end(); 
00059                                     ++i)
00060    {
00061       i->second->WriteContent(fp, filetype);
00062    } 
00063 }
00064 
00069 bool ElementSet::AddEntry(DocEntry *newEntry)
00070 {
00071    const TagKey &key = newEntry->GetKey();
00072 
00073    if( TagHT.count(key) == 1 )
00074    {
00075       gdcmWarningMacro( "Key already present: " << key.c_str());
00076       return false;
00077    }
00078    else
00079    {
00080       TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
00081       return true;
00082    }
00083 }
00084 
00089 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
00090 {
00091    const TagKey &key = entryToRemove->GetKey();
00092    if( TagHT.count(key) == 1 )
00093    {
00094       TagHT.erase(key);
00095       //gdcmWarningMacro( "One element erased.");
00096       delete entryToRemove;
00097       return true;
00098    }
00099 
00100    gdcmWarningMacro( "Key not present");
00101    return false ;
00102 }
00103 
00108 bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
00109 {
00110    const TagKey &key = entryToRemove->GetKey();
00111    if( TagHT.count(key) == 1 )
00112    {
00113       TagHT.erase(key);
00114       //gdcmWarningMacro( "One element erased.");
00115       return true;
00116    }
00117 
00118    gdcmWarningMacro( "Key not present");
00119    return false ;
00120 }
00121 
00125 void ElementSet::ClearEntry()
00126 {
00127    for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
00128    {
00129       if ( cc->second )
00130       {
00131          delete cc->second;
00132       }
00133    }
00134    TagHT.clear();
00135 }
00136 
00142 DocEntry *ElementSet::GetFirstEntry()
00143 {
00144    ItTagHT = TagHT.begin();
00145    if (ItTagHT != TagHT.end())
00146       return  ItTagHT->second;
00147    return NULL;
00148 }
00149 
00156 DocEntry *ElementSet::GetNextEntry()
00157 {
00158    gdcmAssertMacro (ItTagHT != TagHT.end());
00159 
00160    ++ItTagHT;
00161    if (ItTagHT != TagHT.end())
00162       return  ItTagHT->second;
00163    return NULL;
00164 }
00165 
00172 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem) 
00173 {
00174    TagKey key = DictEntry::TranslateToKey(group, elem);
00175    TagDocEntryHT::iterator it = TagHT.find(key);
00176 
00177    if ( it!=TagHT.end() )
00178       return it->second;
00179    return NULL;
00180 }
00181 
00182 //-----------------------------------------------------------------------------
00183 // Protected
00184 
00185 //-----------------------------------------------------------------------------
00186 // Private
00187 
00188 //-----------------------------------------------------------------------------
00189 // Print
00195 void ElementSet::Print(std::ostream &os, std::string const & )
00196 {
00197    for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
00198    {
00199       DocEntry *entry = i->second;
00200 
00201       entry->SetPrintLevel(PrintLevel);
00202       entry->Print(os);   
00203 
00204       if ( dynamic_cast<SeqEntry*>(entry) )
00205       {
00206          // Avoid the newline for a sequence:
00207          continue;
00208       }
00209       os << std::endl;
00210    }
00211 }
00212 
00213 //-----------------------------------------------------------------------------
00214 } // end namespace gdcm

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