]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
please compile before commit
[gdcm.git] / src / gdcmDocEntrySet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/22 14:11:34 $
7   Version:   $Revision: 1.12 $
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 <errno.h>
20 #include "gdcmDebug.h"
21 #include "gdcmCommon.h"
22 #include "gdcmGlobal.h"
23 #include "gdcmDocEntrySet.h"
24 #include "gdcmException.h"
25 #include "gdcmDocEntry.h"
26 #include "gdcmSeqEntry.h"
27 #include "gdcmValEntry.h"
28 #include "gdcmBinEntry.h"
29
30 //-----------------------------------------------------------------------------
31 // Constructor / Destructor
32 /**
33  * \ingroup gdcmDocEntrySet
34  * \brief   Constructor from a given gdcmDocEntrySet
35  */
36 gdcmDocEntrySet::gdcmDocEntrySet(int depthLevel) {
37    SQDepthLevel = depthLevel + 1;
38 }
39 /**
40  * \brief   Canonical destructor.
41  */
42 gdcmDocEntrySet::~gdcmDocEntrySet(){
43 }
44 //-----------------------------------------------------------------------------
45 // Print
46 /*
47  * \ingroup gdcmDocEntrySet
48  * \brief   canonical Printer
49  */
50
51
52 //-----------------------------------------------------------------------------
53 // Public
54
55
56
57 /**
58  * \brief   Build a new Element Value from all the low level arguments. 
59  *          Check for existence of dictionary entry, and build
60  *          a default one when absent.
61  * @param   Group group   number of the underlying DictEntry
62  * @param   Elem  element number of the underlying DictEntry
63  */
64 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(guint16 Group, guint16 Elem) 
65 {
66    // Find out if the tag we encountered is in the dictionaries:
67    gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
68    if (!DictEntry)
69       DictEntry = NewVirtualDictEntry(Group, Elem);
70
71    gdcmValEntry *NewEntry = new gdcmValEntry(DictEntry);
72    if (!NewEntry) 
73    {
74       dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
75                   "failed to allocate gdcmValEntry");
76       return NULL;
77    }
78    return NewEntry;
79 }
80
81
82 /**
83  * \brief   Build a new Element Value from all the low level arguments. 
84  *          Check for existence of dictionary entry, and build
85  *          a default one when absent.
86  * @param   Group group   number of the underlying DictEntry
87  * @param   Elem  element number of the underlying DictEntry
88  */
89 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(guint16 Group, guint16 Elem) 
90 {
91    // Find out if the tag we encountered is in the dictionaries:
92    gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
93    if (!DictEntry)
94       DictEntry = NewVirtualDictEntry(Group, Elem);
95
96    gdcmBinEntry *NewEntry = new gdcmBinEntry(DictEntry);
97    if (!NewEntry) 
98    {
99       dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
100                   "failed to allocate gdcmBinEntry");
101       return NULL;
102    }
103    return NewEntry;
104 }
105 //-----------------------------------------------------------------------------
106 // Protected
107
108 /**
109  * \brief   Gets a Dicom Element inside a SQ Item Entry, by name
110  * @return
111  */
112  gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string name) {
113    gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
114    gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
115    if( dictEntry == NULL)
116       return NULL;
117    return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());      
118 }
119
120
121 /**
122  * \brief   Get the value of a Dicom Element inside a SQ Item Entry, by name
123  * @param   name : name of the searched element.
124  * @return
125  */ 
126
127 std::string gdcmDocEntrySet::GetEntryByName(TagName name)  {
128    gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
129    gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name); 
130
131    if( dictEntry == NULL)
132       return GDCM_UNFOUND;
133    return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()); 
134 }
135
136
137 /**
138  * \brief   Request a new virtual dict entry to the dict set
139  * @param   group     group  number of the underlying DictEntry
140  * @param   element  element number of the underlying DictEntry
141  * @param   vr     VR of the underlying DictEntry
142  * @param   fourth owner group
143  * @param   name   english name
144  */
145 gdcmDictEntry *gdcmDocEntrySet::NewVirtualDictEntry(guint16 group, guint16 element,
146                                                std::string vr,
147                                                std::string fourth,
148                                                std::string name)
149 {
150    return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
151 }
152
153 /// \brief 
154
155 // 
156 // Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
157 // an remove gdcmDocument::NewDocEntryByNumber
158 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByNumber(guint16 group,
159                                                    guint16 elem) {
160       
161    // Find out if the tag we encountered is in the dictionaries:
162    gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
163    gdcmDictEntry *DictEntry = (*PubDict).GetDictEntryByNumber(group, elem);
164    if (!DictEntry)
165       DictEntry = NewVirtualDictEntry(group, elem);
166
167    gdcmDocEntry *NewEntry = new gdcmDocEntry(DictEntry);
168    if (!NewEntry) 
169    {
170       dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
171                   "failed to allocate gdcmDocEntry");
172       return (gdcmDocEntry*)0;
173    }
174    return NewEntry;
175 }
176
177 /// \brief 
178 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName  (std::string Name) {
179
180   gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
181   gdcmDictEntry *NewTag = (*PubDict).GetDictEntryByName(Name);
182    if (!NewTag)
183       NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", Name);
184
185    gdcmDocEntry* NewEntry = new gdcmDocEntry(NewTag);
186    if (!NewEntry) 
187    {
188       dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
189                   "failed to allocate gdcmDocEntry");
190       return (gdcmDocEntry *)0;
191    }
192    return NewEntry;
193 }
194
195
196 /**
197  * \brief   Searches both the public and the shadow dictionary (when they
198  *          exist) for the presence of the DictEntry with given name.
199  *          The public dictionary has precedence on the shadow one.
200  * @param   Name name of the searched DictEntry
201  * @return  Corresponding DictEntry when it exists, NULL otherwise.
202  */
203 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string Name) 
204 {
205    gdcmDictEntry *found = (gdcmDictEntry *)0;
206    gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
207    if (!PubDict) 
208    {
209       dbg.Verbose(0, "gdcmDocument::GetDictEntry",
210                      "we SHOULD have a default dictionary");
211    }
212    else 
213      found = PubDict->GetDictEntryByName(Name);  
214    return found;
215 }
216
217 /**
218  * \brief   Searches both the public and the shadow dictionary (when they
219  *          exist) for the presence of the DictEntry with given
220  *          group and element. The public dictionary has precedence on the
221  *          shadow one.
222  * @param   group   group number of the searched DictEntry
223  * @param   element element number of the searched DictEntry
224  * @return  Corresponding DictEntry when it exists, NULL otherwise.
225  */
226 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(guint16 group,guint16 element) 
227 {
228    gdcmDictEntry *found = (gdcmDictEntry *)0;
229    gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
230    if (!PubDict) 
231    {
232       dbg.Verbose(0, "gdcmDocument::GetDictEntry",
233                      "we SHOULD have a default dictionary");
234    }
235    else 
236      found = PubDict->GetDictEntryByNumber(group, element);  
237    return found;
238 }
239
240
241 //-----------------------------------------------------------------------------
242 // Private
243
244
245 //-----------------------------------------------------------------------------