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