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