1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/07/02 13:55:27 $
7 Version: $Revision: 1.13 $
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(uint16_t Group,
67 // Find out if the tag we encountered is in the dictionaries:
68 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
70 DictEntry = NewVirtualDictEntry(Group, Elem);
72 gdcmValEntry *NewEntry = new gdcmValEntry(DictEntry);
75 dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
76 "failed to allocate gdcmValEntry");
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
90 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t Group,
93 // Find out if the tag we encountered is in the dictionaries:
94 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
96 DictEntry = NewVirtualDictEntry(Group, Elem);
98 gdcmBinEntry *NewEntry = new gdcmBinEntry(DictEntry);
101 dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
102 "failed to allocate gdcmBinEntry");
107 //-----------------------------------------------------------------------------
111 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
114 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string name) {
115 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
116 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
117 if( dictEntry == NULL)
119 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
124 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
125 * @param name : name of the searched element.
129 std::string gdcmDocEntrySet::GetEntryByName(TagName name) {
130 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
131 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
133 if( dictEntry == NULL)
135 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
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
147 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
153 return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
157 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
158 * an remove gdcmDocument::NewDocEntryByNumber
160 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
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);
167 DictEntry = NewVirtualDictEntry(group, elem);
169 gdcmDocEntry *NewEntry = new gdcmDocEntry(DictEntry);
172 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
173 "failed to allocate gdcmDocEntry");
174 return (gdcmDocEntry*)0;
180 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string Name) {
182 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
183 gdcmDictEntry *NewTag = (*PubDict).GetDictEntryByName(Name);
185 NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", Name);
187 gdcmDocEntry* NewEntry = new gdcmDocEntry(NewTag);
190 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
191 "failed to allocate gdcmDocEntry");
192 return (gdcmDocEntry *)0;
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.
205 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string Name)
207 gdcmDictEntry *found = (gdcmDictEntry *)0;
208 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
211 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
212 "we SHOULD have a default dictionary");
215 found = PubDict->GetDictEntryByName(Name);
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
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.
228 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
231 gdcmDictEntry *found = (gdcmDictEntry *)0;
232 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
235 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
236 "we SHOULD have a default dictionary");
239 found = PubDict->GetDictEntryByNumber(group, element);
244 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------