1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/07/30 11:40:13 $
7 Version: $Revision: 1.14 $
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.
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.
17 =========================================================================*/
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"
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
32 * \ingroup gdcmDocEntrySet
33 * \brief Constructor from a given gdcmDocEntrySet
35 gdcmDocEntrySet::gdcmDocEntrySet(int depthLevel) {
36 SQDepthLevel = depthLevel + 1;
39 * \brief Canonical destructor.
41 gdcmDocEntrySet::~gdcmDocEntrySet(){
43 //-----------------------------------------------------------------------------
46 * \ingroup gdcmDocEntrySet
47 * \brief canonical Printer
51 //-----------------------------------------------------------------------------
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
63 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t Group,
66 // Find out if the tag we encountered is in the dictionaries:
67 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
69 DictEntry = NewVirtualDictEntry(Group, Elem);
71 gdcmValEntry *NewEntry = new gdcmValEntry(DictEntry);
74 dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
75 "failed to allocate gdcmValEntry");
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
89 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t Group,
92 // Find out if the tag we encountered is in the dictionaries:
93 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
95 DictEntry = NewVirtualDictEntry(Group, Elem);
97 gdcmBinEntry *NewEntry = new gdcmBinEntry(DictEntry);
100 dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
101 "failed to allocate gdcmBinEntry");
106 //-----------------------------------------------------------------------------
110 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
113 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string name) {
114 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
115 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
116 if( dictEntry == NULL)
118 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
123 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
124 * @param name : name of the searched element.
128 std::string gdcmDocEntrySet::GetEntryByName(TagName name) {
129 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
130 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
132 if( dictEntry == NULL)
134 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
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
146 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
152 return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
156 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
157 * an remove gdcmDocument::NewDocEntryByNumber
159 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
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);
166 DictEntry = NewVirtualDictEntry(group, elem);
168 gdcmDocEntry *NewEntry = new gdcmDocEntry(DictEntry);
171 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
172 "failed to allocate gdcmDocEntry");
173 return (gdcmDocEntry*)0;
179 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string Name) {
181 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
182 gdcmDictEntry *NewTag = (*PubDict).GetDictEntryByName(Name);
184 NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", Name);
186 gdcmDocEntry* NewEntry = new gdcmDocEntry(NewTag);
189 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
190 "failed to allocate gdcmDocEntry");
191 return (gdcmDocEntry *)0;
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.
204 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string Name)
206 gdcmDictEntry *found = (gdcmDictEntry *)0;
207 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
210 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
211 "we SHOULD have a default dictionary");
214 found = PubDict->GetDictEntryByName(Name);
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
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.
227 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
230 gdcmDictEntry *found = (gdcmDictEntry *)0;
231 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
234 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
235 "we SHOULD have a default dictionary");
238 found = PubDict->GetDictEntryByNumber(group, element);
243 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------