]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
* gdcmElementSet.cxx : Bad patch to pass the test suite. Patch because
[gdcm.git] / src / gdcmElementSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmElementSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 13:20:34 $
7   Version:   $Revision: 1.29 $
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.html 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 namespace gdcm 
26 {
27
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \ingroup ElementSet
32  * \brief   Constructor from a given ElementSet
33  */
34 //BOZ depthLevel is not usefull anymore
35 ElementSet::ElementSet(int depthLevel) 
36               : DocEntrySet()
37 {
38   (void)depthLevel;
39 }
40
41 /**
42  * \ingroup ElementSet
43  * \brief   Canonical destructor.
44  */
45 ElementSet::~ElementSet() 
46 {
47   for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
48    {
49       DocEntry* entryToDelete = cc->second;
50       if ( entryToDelete )
51       {
52          // FIXME
53          // Because the gdcmFile links the datas of gdcmPixelConvert with the
54          // data in a binArea, these datas are deleted 2 times... very bad...
55          //delete entryToDelete;
56       }
57    }
58    TagHT.clear();
59 }
60
61
62 //-----------------------------------------------------------------------------
63 // Public
64
65
66 //-----------------------------------------------------------------------------
67 // Print
68 /**
69   * \brief   Prints the Header Entries (Dicom Elements)
70   *          from the H Table
71   * @return
72   */ 
73 void ElementSet::Print(std::ostream& os)
74 {
75    for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
76    {
77       DocEntry* entry = i->second;
78       entry->Print(os);   
79       if ( SeqEntry* seqEntry = dynamic_cast<SeqEntry*>(entry) )
80       {
81          (void)seqEntry;
82          // Avoid the newline for a sequence:
83          continue;
84       }
85       os << std::endl;
86    }
87 }
88
89 /**
90   * \brief   Writes the Header Entries (Dicom Elements)
91   *          from the H Table
92   * @return
93   */ 
94 void ElementSet::Write(std::ofstream* fp, FileType filetype)
95 {
96    for (TagDocEntryHT::const_iterator i = TagHT.begin(); 
97                                      i != TagHT.end(); 
98                                     ++i)
99    {
100       i->second->Write(fp, filetype);
101    } 
102 }
103 //-----------------------------------------------------------------------------
104 // Protected
105
106 //-----------------------------------------------------------------------------
107
108 //-----------------------------------------------------------------------------
109 // Private
110
111 /**
112  * \brief   add a new Dicom Element pointer to the H Table
113  * @param   newEntry entry to add
114  */
115 bool ElementSet::AddEntry(DocEntry* newEntry)
116 {
117    const TagKey& key = newEntry->GetKey();
118
119    if( TagHT.count(key) == 1 )
120    {
121       dbg.Verbose(1, "ElementSet::AddEntry key already present: ",
122                   key.c_str());
123       return false;
124    }
125    else
126    {
127       TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
128       return true;
129    }
130 }
131
132 /**
133  * \brief   Clear the hash table from given entry BUT keep the entry.
134  * @param   entryToRemove Entry to remove.
135  */
136 bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove)
137 {
138    const TagKey& key = entryToRemove->GetKey();
139    if( TagHT.count(key) == 1 )
140    {
141       TagHT.erase(key);
142       dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
143       return true;
144    }
145
146    dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
147    return false ;
148 }
149
150 /**
151  * \brief   Clear the hash table from given entry AND delete the entry.
152  * @param   entryToRemove Entry to remove AND delete.
153  */
154 bool ElementSet::RemoveEntry( DocEntry* entryToRemove)
155 {
156    const TagKey& key = entryToRemove->GetKey();
157    if( TagHT.count(key) == 1 )
158    {
159       TagHT.erase(key);
160       dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased.");
161       delete entryToRemove;
162       return true;
163    }
164
165    dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: ");
166    return false ;
167 }
168 } // end namespace gdcm