]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
* src/*.cxx *.h Reference to License.htm fixed to License.html.
[gdcm.git] / src / gdcmDocEntrySet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/09/27 08:39:06 $
7   Version:   $Revision: 1.23 $
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
19 #include "gdcmDebug.h"
20 #include "gdcmCommon.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmDocEntrySet.h"
23 #include "gdcmException.h"
24 #include "gdcmDocEntry.h"
25 #include "gdcmSeqEntry.h"
26 #include "gdcmValEntry.h"
27 #include "gdcmBinEntry.h"
28
29 //-----------------------------------------------------------------------------
30 // Public
31
32 /**
33  * \brief   Build a new Val Entry from all the low level arguments. 
34  *          Check for existence of dictionary entry, and build
35  *          a default one when absent.
36  * @param   group group   number of the underlying DictEntry
37  * @param   elem  element number of the underlying DictEntry
38  */
39 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t group,
40                                                    uint16_t elem) 
41 {
42    // Find out if the tag we encountered is in the dictionaries:
43    gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
44    if (!dictEntry)
45    {
46       dictEntry = NewVirtualDictEntry(group, elem);
47    }
48
49    gdcmValEntry *newEntry = new gdcmValEntry(dictEntry);
50    if (!newEntry) 
51    {
52       dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
53                   "failed to allocate gdcmValEntry");
54       return 0;
55    }
56    return newEntry;
57 }
58
59
60 /**
61  * \brief   Build a new Bin Entry from all the low level arguments. 
62  *          Check for existence of dictionary entry, and build
63  *          a default one when absent.
64  * @param   group group   number of the underlying DictEntry
65  * @param   elem  element number of the underlying DictEntry
66  */
67 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group,
68                                                    uint16_t elem) 
69 {
70    // Find out if the tag we encountered is in the dictionaries:
71    gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
72    if (!dictEntry)
73    {
74       dictEntry = NewVirtualDictEntry(group, elem);
75    }
76
77    gdcmBinEntry *newEntry = new gdcmBinEntry(dictEntry);
78    if (!newEntry) 
79    {
80       dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
81                   "failed to allocate gdcmBinEntry");
82       return 0;
83    }
84    return newEntry;
85 }
86
87 /**
88  * \brief   Build a new Seq Entry from all the low level arguments. 
89  *          Check for existence of dictionary entry, and build
90  *          a default one when absent.
91  * @param   Group group   number of the underlying DictEntry
92  * @param   Elem  element number of the underlying DictEntry
93  */
94 gdcmSeqEntry* gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
95                                                    uint16_t Elem) 
96 {
97    // Find out if the tag we encountered is in the dictionaries:
98    gdcmDictEntry* DictEntry = GetDictEntryByNumber( Group, Elem );
99    if ( ! DictEntry )
100    {
101       DictEntry = NewVirtualDictEntry(Group, Elem);
102    }
103
104    gdcmSeqEntry *NewEntry = new gdcmSeqEntry( DictEntry );
105    if ( !NewEntry ) 
106    {
107       dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber",
108                   "failed to allocate gdcmSeqEntry");
109       return 0;
110    }
111    return NewEntry;
112 }
113
114 //-----------------------------------------------------------------------------
115 // Protected
116
117 /**
118  * \brief   Gets a Dicom Element inside a SQ Item Entry, by name
119  * @return
120  */
121  gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string const & name)
122  {
123    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
124    gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
125    if( !dictEntry )
126    {
127       return 0;
128    }
129
130    return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());      
131 }
132
133
134 /**
135  * \brief   Get the value of a Dicom Element inside a SQ Item Entry, by name
136  * @param   name : name of the searched element.
137  * @return
138  */ 
139
140 std::string gdcmDocEntrySet::GetEntryByName(TagName const & name)
141 {
142    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
143    gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name); 
144
145    if( !dictEntry )
146    {
147       return GDCM_UNFOUND;
148    }
149
150    return GetEntryByNumber(dictEntry->GetGroup(), dictEntry->GetElement()); 
151 }
152
153
154 /**
155  * \brief   Request a new virtual dict entry to the dict set
156  * @param   group     group  number of the underlying DictEntry
157  * @param   element  element number of the underlying DictEntry
158  * @param   vr     VR of the underlying DictEntry
159  * @param   fourth owner group
160  * @param   name   english name
161  */
162 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
163                                                     uint16_t element,
164                                                     std::string const & vr,
165                                                     std::string const & fourth,
166                                                     std::string const & name)
167 {
168    return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
169 }
170
171 /** \brief 
172  * Creates a new DocEntry (without any 'value' ...)
173  * @param   group     group  number of the underlying DictEntry
174  * @param   elem  elem number of the underlying DictEntry 
175  */
176 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
177                                                    uint16_t elem)
178 {
179    // Find out if the tag we encountered is in the dictionaries:
180    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
181    gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
182    if (!dictEntry)
183    {
184       dictEntry = NewVirtualDictEntry(group, elem);
185    }
186
187    gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
188    if (!newEntry) 
189    {
190       dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
191                   "failed to allocate gdcmDocEntry");
192       return 0;
193    }
194    return newEntry;
195 }
196
197
198 /** \brief 
199  * Creates a new DocEntry (without any 'value' ...)
200  * @param   group     group  number of the underlying DictEntry
201  * @param   elem  elem number of the underlying DictEntry 
202  * @param   VR   V(alue) R(epresentation) of the Entry -if private Entry- 
203
204  */
205 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
206                                                    uint16_t elem,
207                                                    std::string const &VR)
208 {
209    // Find out if the tag we encountered is in the dictionaries:
210    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
211    gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
212    if (!dictEntry)
213    {
214       dictEntry = NewVirtualDictEntry(group, elem, VR);
215    }
216
217    gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
218    if (!newEntry) 
219    {
220       dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
221                   "failed to allocate gdcmDocEntry");
222       return 0;
223    }
224    return newEntry;
225 }
226 /* \brief
227  * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
228  * an remove gdcmDocument::NewDocEntryByName
229  */
230 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName  (std::string const & name)
231 {
232   gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
233   gdcmDictEntry *newTag = pubDict->GetDictEntryByName(name);
234    if (!newTag)
235    {
236       newTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", name);
237    }
238
239    gdcmDocEntry* newEntry = new gdcmDocEntry(newTag);
240    if (!newEntry) 
241    {
242       dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
243                   "failed to allocate gdcmDocEntry");
244       return 0;
245    }
246
247    return newEntry;
248 }
249
250
251 /**
252  * \brief   Searches both the public and the shadow dictionary (when they
253  *          exist) for the presence of the DictEntry with given name.
254  *          The public dictionary has precedence on the shadow one.
255  * @param   name Name of the searched DictEntry
256  * @return  Corresponding DictEntry when it exists, NULL otherwise.
257  */
258 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string const & name) 
259 {
260    gdcmDictEntry *found = 0;
261    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
262    if (!pubDict) 
263    {
264       dbg.Verbose(0, "gdcmDocument::GetDictEntry",
265                      "we SHOULD have a default dictionary");
266    }
267    else
268    {
269       found = pubDict->GetDictEntryByName(name);  
270    }
271    return found;
272 }
273
274 /**
275  * \brief   Searches both the public and the shadow dictionary (when they
276  *          exist) for the presence of the DictEntry with given
277  *          group and element. The public dictionary has precedence on the
278  *          shadow one.
279  * @param   group   group number of the searched DictEntry
280  * @param   element element number of the searched DictEntry
281  * @return  Corresponding DictEntry when it exists, NULL otherwise.
282  */
283 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
284                                                      uint16_t element) 
285 {
286    gdcmDictEntry *found = 0;
287    gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
288    if (!pubDict) 
289    {
290       dbg.Verbose(0, "gdcmDocument::GetDictEntry",
291                      "we SHOULD have a default dictionary");
292    }
293    else
294    {
295       found = pubDict->GetDictEntryByNumber(group, element);  
296    }
297    return found;
298 }
299
300
301 //-----------------------------------------------------------------------------
302 // Private
303
304
305 //-----------------------------------------------------------------------------