]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
Doxygenation
[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 16:29:22 $
7   Version:   $Revision: 1.31 $
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 /** \brief 
164  * Creates a new DocEntry (without any 'value' ...)
165  * @param   group     group  number of the underlying DictEntry
166  * @param   elem  elem number of the underlying DictEntry 
167  * @param   vr    V(alue) R(epresentation) of the Entry -if private Entry- 
168  */
169 DocEntry* DocEntrySet::NewDocEntryByNumber(uint16_t group, uint16_t elem,
170                                            TagName const & vr)
171 {
172    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, vr);
173    assert(dictEntry);
174
175    // Create the DocEntry
176    DocEntry *newEntry = new DocEntry(dictEntry);
177    if (!newEntry) 
178    {
179       dbg.Verbose(1, "SQItem::NewDocEntryByNumber",
180                   "failed to allocate DocEntry");
181       return 0;
182    }
183    return newEntry;
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 name.
189  *          The public dictionary has precedence on the shadow one.
190  * @param   name Name of the searched DictEntry
191  * @return  Corresponding DictEntry when it exists, NULL otherwise.
192  */
193 DictEntry *DocEntrySet::GetDictEntryByName(TagName const & name) 
194 {
195    DictEntry *found = 0;
196    Dict *pubDict = Global::GetDicts()->GetDefaultPubDict();
197    if (!pubDict) 
198    {
199       dbg.Verbose(0, "Document::GetDictEntry",
200                      "we SHOULD have a default dictionary");
201    }
202    else
203    {
204       found = pubDict->GetDictEntryByName(name);  
205    }
206    return found;
207 }
208
209 /**
210  * \brief   Searches both the public and the shadow dictionary (when they
211  *          exist) for the presence of the DictEntry with given
212  *          group and element. The public dictionary has precedence on the
213  *          shadow one.
214  * @param   group   group number of the searched DictEntry
215  * @param   elem element number of the searched DictEntry
216  * @return  Corresponding DictEntry when it exists, NULL otherwise.
217  */
218 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group,uint16_t elem) 
219 {
220    DictEntry *found = 0;
221    Dict *pubDict = Global::GetDicts()->GetDefaultPubDict();
222    if (!pubDict) 
223    {
224       dbg.Verbose(0, "Document::GetDictEntry",
225                      "we SHOULD have a default dictionary");
226    }
227    else
228    {
229       found = pubDict->GetDictEntryByNumber(group, elem);  
230    }
231    return found;
232 }
233
234 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group, uint16_t elem,
235                                              TagName const & vr)
236 {
237    DictEntry *dictEntry = GetDictEntryByNumber(group,elem);
238    DictEntry *goodEntry = dictEntry;
239    std::string goodVR=vr;
240
241    if (elem==0x0000)
242       goodVR="UL";
243
244    if (goodEntry)
245       if (goodEntry->GetVR() != goodVR && goodVR!=GDCM_UNKNOWN)
246          goodEntry=NULL;
247
248    // Create a new virtual DictEntry if necessary
249    if (!goodEntry)
250    {
251       if (dictEntry)
252          goodEntry = NewVirtualDictEntry(group, elem, goodVR,"FIXME",dictEntry->GetName());
253       else
254          goodEntry = NewVirtualDictEntry(group, elem, goodVR);
255    }
256
257    return goodEntry;
258 }
259
260 //-----------------------------------------------------------------------------
261 // Private
262
263 } // end namespace gdcm
264
265 //-----------------------------------------------------------------------------