]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
* Erroneous leading white fix:
[gdcm.git] / src / gdcmElementSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmElementSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/20 18:08:47 $
7   Version:   $Revision: 1.8 $
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
22 //-----------------------------------------------------------------------------
23 // Constructor / Destructor
24 /**
25  * \ingroup gdcmElementSet
26  * \brief   Constructor from a given gdcmElementSet
27  */
28 gdcmElementSet::gdcmElementSet(int depthLevel) 
29               : gdcmDocEntrySet(depthLevel) {
30 }
31
32 /**
33  * \ingroup gdcmElementSet
34  * \brief   Canonical destructor.
35  */
36 gdcmElementSet::~gdcmElementSet() 
37 {
38   gdcmDocEntry* EntryToDelete;  
39   for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
40    {
41       EntryToDelete = cc->second;
42       if ( EntryToDelete )
43          delete EntryToDelete;  // TODO : a verifier
44    }
45    tagHT.clear();
46 }
47
48
49 //-----------------------------------------------------------------------------
50 // Public
51
52
53 //-----------------------------------------------------------------------------
54 // Print
55 /**
56   * \brief   Prints the Header Entries (Dicom Elements)
57   *          from the H Table
58   * @return
59   */ 
60 void gdcmElementSet::Print(std::ostream & os) {
61    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
62    {
63       //(*i)->second->SetPrintLevel(printLevel);
64       (i->second)->Print(os);   
65    } 
66 }
67
68
69 //-----------------------------------------------------------------------------
70 // Protected
71
72 //-----------------------------------------------------------------------------
73
74 //-----------------------------------------------------------------------------
75 // Private
76
77
78 /**
79  * \brief   add a new Dicom Element pointer to the H Table
80  * @param   NewEntry entry to add
81  */
82 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
83    TagKey key;
84    key = NewEntry->GetKey();
85
86    if(tagHT.count(key) == 1)
87    {
88       dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
89                   key.c_str());
90       return(false);
91    } 
92    else 
93    {
94       tagHT[NewEntry->GetKey()] = NewEntry;
95       return(true);
96    }   
97 }
98
99 /**
100  * \brief   Clear the hash table from given entry.
101  * @param   EntryToRemove Entry to remove.
102  */
103 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
104 {
105    TagKey key = EntryToRemove->GetKey();
106    if(tagHT.count(key) == 1)
107    {
108       tagHT.erase(key);
109       dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
110       return true;
111    }
112
113    dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
114    return(false);
115 }