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