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