]> Creatis software - gdcm.git/blob - src/gdcmElementSet.cxx
gdcmDocEntry::PrintCommonPart() and ::WriteCommonPart() removed.
[gdcm.git] / src / gdcmElementSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmElementSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/23 13:02:36 $
7   Version:   $Revision: 1.13 $
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          PrintEndLine = false;
73       if (PrintEndLine)
74          os << std::endl;
75    } 
76 }
77
78 /**
79   * \brief   Writes the Header Entries (Dicom Elements)
80   *          from the H Table
81   * @return
82   */ 
83 void gdcmElementSet::Write(FILE *fp, FileType filetype)
84 {
85
86    for (TagDocEntryHT::iterator i = tagHT.begin(); i != tagHT.end(); ++i)  
87    {
88       i->second->Write(fp, filetype);
89    } 
90 }
91 //-----------------------------------------------------------------------------
92 // Protected
93
94 //-----------------------------------------------------------------------------
95
96 //-----------------------------------------------------------------------------
97 // Private
98
99 /**
100  * \brief   add a new Dicom Element pointer to the H Table
101  * @param   NewEntry entry to add
102  */
103 bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) {
104    TagKey key;
105    key = NewEntry->GetKey();
106
107    if(tagHT.count(key) == 1)
108    {
109       dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ",
110                   key.c_str());
111       return(false);
112    } 
113    else 
114    {
115       tagHT[NewEntry->GetKey()] = NewEntry;
116       return(true);
117    }   
118 }
119
120 /**
121  * \brief   Clear the hash table from given entry.
122  * @param   EntryToRemove Entry to remove.
123  */
124 bool gdcmElementSet::RemoveEntry( gdcmDocEntry *EntryToRemove)
125 {
126    TagKey key = EntryToRemove->GetKey();
127    if(tagHT.count(key) == 1)
128    {
129       tagHT.erase(key);
130       dbg.Verbose(0, "gdcmElementSet::RemoveEntry: one element erased.");
131       return true;
132    }
133
134    dbg.Verbose(0, "gdcmElementSet::RemoveEntry: key not present: ");
135    return(false);
136 }