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