]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
EMH: *Add PrintAllDocument, dog slow right now
[gdcm.git] / src / gdcmElementSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmElementSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/25 03:06:38 $
7   Version:   $Revision: 1.14 $
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 gdcmElementSet::gdcmElementSet(int depthLevel) 
32               : gdcmDocEntrySet(depthLevel) {
33 }
34
35 /**
36  * \ingroup gdcmElementSet
37  * \brief   Canonical destructor.
38  */
39 gdcmElementSet::~gdcmElementSet() 
40 {
41   gdcmDocEntry* EntryToDelete;  
42   for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc)
43    {
44       EntryToDelete = cc->second;
45       if ( EntryToDelete )
46          delete EntryToDelete;
47    }
48    tagHT.clear();
49 }
50
51
52 //-----------------------------------------------------------------------------
53 // Public
54
55
56 //-----------------------------------------------------------------------------
57 // Print
58 /**
59   * \brief   Prints the Header Entries (Dicom Elements)
60   *          from the H Table
61   * @return
62   */ 
63 void gdcmElementSet::Print(std::ostream & os)
64 {
65    gdcmDocEntry* Entry;
66    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
67    {
68       Entry = i->second;
69       Entry->Print(os);   
70       bool PrintEndLine = true;
71       if ( gdcmSeqEntry* SeqEntry = dynamic_cast<gdcmSeqEntry*>(Entry) )
72       {
73          (void)SeqEntry;  //not used
74          PrintEndLine = false;
75       }
76       if (PrintEndLine)
77          os << std::endl;
78    } 
79 }
80
81 /**
82   * \brief   Writes the Header Entries (Dicom Elements)
83   *          from the H Table
84   * @return
85   */ 
86 void gdcmElementSet::Write(FILE *fp, FileType filetype)
87 {
88
89    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
90    {
91       i->second->Write(fp, filetype);
92    } 
93 }
94 //-----------------------------------------------------------------------------
95 // Protected
96
97 //-----------------------------------------------------------------------------
98
99 //-----------------------------------------------------------------------------
100 // Private
101
102 /**
103  * \brief   add a new Dicom Element pointer to the H Table
104  * @param   NewEntry entry to add
105  */
106 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
107    TagKey key;
108    key = NewEntry->GetKey();
109
110    if(tagHT.count(key) == 1)
111    {
112       dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
113                   key.c_str());
114       return(false);
115    } 
116    else 
117    {
118       tagHT[NewEntry->GetKey()] = NewEntry;
119       return(true);
120    }   
121 }
122
123 /**
124  * \brief   Clear the hash table from given entry.
125  * @param   EntryToRemove Entry to remove.
126  */
127 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
128 {
129    TagKey key = EntryToRemove->GetKey();
130    if(tagHT.count(key) == 1)
131    {
132       tagHT.erase(key);
133       dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
134       return true;
135    }
136
137    dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
138    return(false);
139 }