]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
ENH: stdify
[gdcm.git] / src / gdcmElementSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmElementSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/22 14:03:30 $
7   Version:   $Revision: 1.10 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmElementSet.h"
20 #include "gdcmDebug.h"
21 #include "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmSeqEntry.h"
24
25 //-----------------------------------------------------------------------------
26 // Constructor / Destructor
27 /**
28  * \ingroup gdcmElementSet
29  * \brief   Constructor from a given gdcmElementSet
30  */
31 gdcmElementSet::gdcmElementSet(int depthLevel) 
32               : gdcmDocEntrySet(depthLevel) {
33 }
34
35 /**
36  * \ingroup gdcmElementSet
37  * \brief   Canonical destructor.
38  */
39 gdcmElementSet::~gdcmElementSet() 
40 {
41   gdcmDocEntry* EntryToDelete;  
42   for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
43    {
44       EntryToDelete = cc->second;
45       if ( EntryToDelete )
46          delete EntryToDelete;
47    }
48    tagHT.clear();
49 }
50
51
52 //-----------------------------------------------------------------------------
53 // Public
54
55
56 //-----------------------------------------------------------------------------
57 // Print
58 /**
59   * \brief   Prints the Header Entries (Dicom Elements)
60   *          from the H Table
61   * @return
62   */ 
63 void gdcmElementSet::Print(std::ostream & os) {
64    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
65    {
66       //(i)->second->SetPrintLevel(printLevel);
67       (i->second)->Print(os);   
68    } 
69 }
70
71 /**
72   * \brief   Writes the Header Entries (Dicom Elements)
73   *          from the H Table
74   * @return
75   */ 
76 void gdcmElementSet::Write(FILE *fp, FileType filetype) {
77
78 // Troubles expected : BinEntries ARE ValEntries :-(
79 // BinEntry is checked first, then ValEntry;
80
81    gdcmDocEntry *e;
82    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
83    {
84       e=i->second;      
85            e->WriteCommonPart(fp, filetype);
86                 std::cout<<e->GetKey() << " " << std::hex << e->GetVR() << " " 
87                          << e->GetName()
88                          << std::endl;
89                                         
90 //               e->Write(fp,filetype); // This will be the right way to proceed !
91                 
92       if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(e) ) {
93          BinEntry->Write(fp,filetype);
94                         continue;
95       }
96                 if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(e) ) {
97          ValEntry->Write(fp,filetype);
98                         continue;
99       }
100
101       if (gdcmSeqEntry* SeqEntry = dynamic_cast< gdcmSeqEntry* >(e) ) {
102          SeqEntry->Write(fp,filetype);
103                         continue;
104       } 
105    } 
106 }
107 //-----------------------------------------------------------------------------
108 // Protected
109
110 //-----------------------------------------------------------------------------
111
112 //-----------------------------------------------------------------------------
113 // Private
114
115
116 /**
117  * \brief   add a new Dicom Element pointer to the H Table
118  * @param   NewEntry entry to add
119  */
120 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
121    TagKey key;
122    key = NewEntry->GetKey();
123
124    if(tagHT.count(key) == 1)
125    {
126       dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
127                   key.c_str());
128       return(false);
129    } 
130    else 
131    {
132       tagHT[NewEntry->GetKey()] = NewEntry;
133       return(true);
134    }   
135 }
136
137 /**
138  * \brief   Clear the hash table from given entry.
139  * @param   EntryToRemove Entry to remove.
140  */
141 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
142 {
143    TagKey key = EntryToRemove->GetKey();
144    if(tagHT.count(key) == 1)
145    {
146       tagHT.erase(key);
147       dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
148       return true;
149    }
150
151    dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
152    return(false);
153 }