1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/08/31 15:39:48 $
7 Version: $Revision: 1.18 $
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)
37 SQDepthLevel = depthLevel + 1; //magic +1 !
40 * \brief Canonical destructor.
42 gdcmDocEntrySet::~gdcmDocEntrySet()
45 //-----------------------------------------------------------------------------
48 * \ingroup gdcmDocEntrySet
49 * \brief canonical Printer
53 //-----------------------------------------------------------------------------
59 * \brief Build a new Val Entry from all the low level arguments.
60 * Check for existence of dictionary entry, and build
61 * a default one when absent.
62 * @param group group number of the underlying DictEntry
63 * @param elem element number of the underlying DictEntry
65 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t group,
68 // Find out if the tag we encountered is in the dictionaries:
69 gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
72 dictEntry = NewVirtualDictEntry(group, elem);
75 gdcmValEntry *newEntry = new gdcmValEntry(dictEntry);
78 dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
79 "failed to allocate gdcmValEntry");
87 * \brief Build a new Bin Entry from all the low level arguments.
88 * Check for existence of dictionary entry, and build
89 * a default one when absent.
90 * @param group group number of the underlying DictEntry
91 * @param elem element number of the underlying DictEntry
93 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group,
96 // Find out if the tag we encountered is in the dictionaries:
97 gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
100 dictEntry = NewVirtualDictEntry(group, elem);
103 gdcmBinEntry *newEntry = new gdcmBinEntry(dictEntry);
106 dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
107 "failed to allocate gdcmBinEntry");
114 * \brief Build a new Seq Entry from all the low level arguments.
115 * Check for existence of dictionary entry, and build
116 * a default one when absent.
117 * @param Group group number of the underlying DictEntry
118 * @param Elem element number of the underlying DictEntry
120 gdcmSeqEntry *gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
123 // Find out if the tag we encountered is in the dictionaries:
124 gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
126 DictEntry = NewVirtualDictEntry(Group, Elem);
128 gdcmSeqEntry *NewEntry = new gdcmSeqEntry(DictEntry, 1); // FIXME : 1
131 dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber",
132 "failed to allocate gdcmSeqEntry");
137 //-----------------------------------------------------------------------------
141 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
144 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string const & name)
146 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
147 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
153 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
158 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
159 * @param name : name of the searched element.
163 std::string gdcmDocEntrySet::GetEntryByName(TagName const & name)
165 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
166 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
173 return GetEntryByNumber(dictEntry->GetGroup(), dictEntry->GetElement());
178 * \brief Request a new virtual dict entry to the dict set
179 * @param group group number of the underlying DictEntry
180 * @param element element number of the underlying DictEntry
181 * @param vr VR of the underlying DictEntry
182 * @param fourth owner group
183 * @param name english name
185 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
187 std::string const & vr,
188 std::string const & fourth,
189 std::string const & name)
191 return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
195 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
196 * an remove gdcmDocument::NewDocEntryByNumber
198 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
201 // Find out if the tag we encountered is in the dictionaries:
202 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
203 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
206 dictEntry = NewVirtualDictEntry(group, elem);
209 gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
212 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
213 "failed to allocate gdcmDocEntry");
220 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
221 * an remove gdcmDocument::NewDocEntryByName
223 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string const & name)
225 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
226 gdcmDictEntry *newTag = pubDict->GetDictEntryByName(name);
229 newTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", name);
232 gdcmDocEntry* newEntry = new gdcmDocEntry(newTag);
235 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
236 "failed to allocate gdcmDocEntry");
245 * \brief Searches both the public and the shadow dictionary (when they
246 * exist) for the presence of the DictEntry with given name.
247 * The public dictionary has precedence on the shadow one.
248 * @param name Name of the searched DictEntry
249 * @return Corresponding DictEntry when it exists, NULL otherwise.
251 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string const & name)
253 gdcmDictEntry *found = 0;
254 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
257 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
258 "we SHOULD have a default dictionary");
262 found = pubDict->GetDictEntryByName(name);
268 * \brief Searches both the public and the shadow dictionary (when they
269 * exist) for the presence of the DictEntry with given
270 * group and element. The public dictionary has precedence on the
272 * @param group group number of the searched DictEntry
273 * @param element element number of the searched DictEntry
274 * @return Corresponding DictEntry when it exists, NULL otherwise.
276 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
279 gdcmDictEntry *found = 0;
280 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
283 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
284 "we SHOULD have a default dictionary");
288 found = pubDict->GetDictEntryByNumber(group, element);
294 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------