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