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