1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2004/06/22 14:37:04 $
7 Version: $Revision: 1.11 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmElementSet.h"
20 #include "gdcmDebug.h"
21 #include "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmSeqEntry.h"
25 //-----------------------------------------------------------------------------
26 // Constructor / Destructor
28 * \ingroup gdcmElementSet
29 * \brief Constructor from a given gdcmElementSet
31 gdcmElementSet::gdcmElementSet(int depthLevel)
32 : gdcmDocEntrySet(depthLevel) {
36 * \ingroup gdcmElementSet
37 * \brief Canonical destructor.
39 gdcmElementSet::~gdcmElementSet()
41 gdcmDocEntry* EntryToDelete;
42 for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
44 EntryToDelete = cc->second;
52 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
59 * \brief Prints the Header Entries (Dicom Elements)
63 void gdcmElementSet::Print(std::ostream & os) {
64 for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)
66 //(i)->second->SetPrintLevel(printLevel);
67 (i->second)->Print(os);
72 * \brief Writes the Header Entries (Dicom Elements)
76 void gdcmElementSet::Write(FILE *fp, FileType filetype) {
78 // Troubles expected : BinEntries ARE ValEntries :-(
79 // BinEntry is checked first, then ValEntry;
82 for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)
85 e->WriteCommonPart(fp, filetype);
86 std::cout<<e->GetKey() << " " << std::hex << e->GetVR() << " "
90 // e->Write(fp,filetype); // This will be the right way to proceed !
92 if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(e) ) {
93 BinEntry->Write(fp,filetype);
96 if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(e) ) {
101 if (gdcmSeqEntry* SeqEntry = dynamic_cast< gdcmSeqEntry* >(e) ) {
102 SeqEntry->Write(fp,filetype);
107 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
117 * \brief add a new Dicom Element pointer to the H Table
118 * @param NewEntry entry to add
120 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
122 key = NewEntry->GetKey();
124 if(tagHT.count(key) == 1)
126 dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
132 tagHT[NewEntry->GetKey()] = NewEntry;
138 * \brief Clear the hash table from given entry.
139 * @param EntryToRemove Entry to remove.
141 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
143 TagKey key = EntryToRemove->GetKey();
144 if(tagHT.count(key) == 1)
147 dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
151 dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");