1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/06/22 14:11:34 $
7 Version: $Revision: 1.12 $
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 =========================================================================*/
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"
30 //-----------------------------------------------------------------------------
31 // Constructor / Destructor
33 * \ingroup gdcmDocEntrySet
34 * \brief Constructor from a given gdcmDocEntrySet
36 gdcmDocEntrySet::gdcmDocEntrySet(int depthLevel) {
37 SQDepthLevel = depthLevel + 1;
40 * \brief Canonical destructor.
42 gdcmDocEntrySet::~gdcmDocEntrySet(){
44 //-----------------------------------------------------------------------------
47 * \ingroup gdcmDocEntrySet
48 * \brief canonical Printer
52 //-----------------------------------------------------------------------------
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
64 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(guint16 Group, guint16 Elem)
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(guint16 Group, guint16 Elem)
91 // Find out if the tag we encountered is in the dictionaries:
92 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
94 DictEntry = NewVirtualDictEntry(Group, Elem);
96 gdcmBinEntry *NewEntry = new gdcmBinEntry(DictEntry);
99 dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
100 "failed to allocate gdcmBinEntry");
105 //-----------------------------------------------------------------------------
109 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
112 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string name) {
113 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
114 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
115 if( dictEntry == NULL)
117 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
122 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
123 * @param name : name of the searched element.
127 std::string gdcmDocEntrySet::GetEntryByName(TagName name) {
128 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
129 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
131 if( dictEntry == NULL)
133 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
138 * \brief Request a new virtual dict entry to the dict set
139 * @param group group number of the underlying DictEntry
140 * @param element element number of the underlying DictEntry
141 * @param vr VR of the underlying DictEntry
142 * @param fourth owner group
143 * @param name english name
145 gdcmDictEntry *gdcmDocEntrySet::NewVirtualDictEntry(guint16 group, guint16 element,
150 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
158 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByNumber(guint16 group,
161 // Find out if the tag we encountered is in the dictionaries:
162 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
163 gdcmDictEntry *DictEntry = (*PubDict).GetDictEntryByNumber(group, elem);
165 DictEntry = NewVirtualDictEntry(group, elem);
167 gdcmDocEntry *NewEntry = new gdcmDocEntry(DictEntry);
170 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
171 "failed to allocate gdcmDocEntry");
172 return (gdcmDocEntry*)0;
178 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string Name) {
180 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
181 gdcmDictEntry *NewTag = (*PubDict).GetDictEntryByName(Name);
183 NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", Name);
185 gdcmDocEntry* NewEntry = new gdcmDocEntry(NewTag);
188 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
189 "failed to allocate gdcmDocEntry");
190 return (gdcmDocEntry *)0;
197 * \brief Searches both the public and the shadow dictionary (when they
198 * exist) for the presence of the DictEntry with given name.
199 * The public dictionary has precedence on the shadow one.
200 * @param Name name of the searched DictEntry
201 * @return Corresponding DictEntry when it exists, NULL otherwise.
203 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string Name)
205 gdcmDictEntry *found = (gdcmDictEntry *)0;
206 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
209 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
210 "we SHOULD have a default dictionary");
213 found = PubDict->GetDictEntryByName(Name);
218 * \brief Searches both the public and the shadow dictionary (when they
219 * exist) for the presence of the DictEntry with given
220 * group and element. The public dictionary has precedence on the
222 * @param group group number of the searched DictEntry
223 * @param element element number of the searched DictEntry
224 * @return Corresponding DictEntry when it exists, NULL otherwise.
226 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(guint16 group,guint16 element)
228 gdcmDictEntry *found = (gdcmDictEntry *)0;
229 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
232 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
233 "we SHOULD have a default dictionary");
236 found = PubDict->GetDictEntryByNumber(group, element);
241 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------