]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
* In order to fix memory leaks:
[gdcm.git] / src / gdcmElementSet.cxx
1 // gdcmElementSet.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmElementSet.h"
5 #include "gdcmDebug.h"
6
7 //-----------------------------------------------------------------------------
8 // Constructor / Destructor
9 /**
10  * \ingroup gdcmElementSet
11  * \brief   Constructor from a given gdcmElementSet
12  */
13 gdcmElementSet::gdcmElementSet(int depthLevel) 
14               : gdcmDocEntrySet(depthLevel) {
15 }
16
17 /**
18  * \ingroup gdcmElementSet
19  * \brief   Canonical destructor.
20  */
21 gdcmElementSet::~gdcmElementSet() 
22 {
23   gdcmDocEntry* EntryToDelete;  
24   for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
25    {
26       EntryToDelete = cc->second;
27       if ( EntryToDelete )
28          delete EntryToDelete;  // TODO : a verifier
29    }
30    tagHT.clear();
31 }
32
33
34 //-----------------------------------------------------------------------------
35 // Public
36
37
38 //-----------------------------------------------------------------------------
39 // Print
40 /**
41   * \brief   Prints the Header Entries (Dicom Elements)
42   *          from the H Table
43   * @return
44   */ 
45 void gdcmElementSet::Print(std::ostream & os) {
46    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
47    {
48       //(*i)->second->SetPrintLevel(printLevel);
49       (i->second)->Print(os);   
50    } 
51 }
52
53
54 //-----------------------------------------------------------------------------
55 // Protected
56
57 //-----------------------------------------------------------------------------
58
59 //-----------------------------------------------------------------------------
60 // Private
61
62
63 /**
64  * \brief   add a new Dicom Element pointer to the H Table
65  * @param   NewEntry entry to add
66  */
67 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
68    TagKey key;
69    key = NewEntry->GetKey();
70
71    if(tagHT.count(key) == 1)
72    {
73       dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
74                   key.c_str());
75       return(false);
76    } 
77    else 
78    {
79       tagHT[NewEntry->GetKey()] = NewEntry;
80       return(true);
81    }   
82 }
83
84 /**
85  * \brief   Clear the hash table from given entry.
86  * @param   EntryToRemove Entry to remove.
87  */
88 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
89 {
90    TagKey key = EntryToRemove->GetKey();
91    if(tagHT.count(key) == 1)
92    {
93       tagHT.erase(key);
94       dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
95       return true;
96    }
97
98    dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
99    return(false);
100 }