1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/09/27 08:39:06 $
7 Version: $Revision: 1.23 $
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.html 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 //-----------------------------------------------------------------------------
33 * \brief Build a new Val Entry from all the low level arguments.
34 * Check for existence of dictionary entry, and build
35 * a default one when absent.
36 * @param group group number of the underlying DictEntry
37 * @param elem element number of the underlying DictEntry
39 gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t group,
42 // Find out if the tag we encountered is in the dictionaries:
43 gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
46 dictEntry = NewVirtualDictEntry(group, elem);
49 gdcmValEntry *newEntry = new gdcmValEntry(dictEntry);
52 dbg.Verbose(1, "gdcmDocument::NewValEntryByNumber",
53 "failed to allocate gdcmValEntry");
61 * \brief Build a new Bin Entry from all the low level arguments.
62 * Check for existence of dictionary entry, and build
63 * a default one when absent.
64 * @param group group number of the underlying DictEntry
65 * @param elem element number of the underlying DictEntry
67 gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group,
70 // Find out if the tag we encountered is in the dictionaries:
71 gdcmDictEntry *dictEntry = GetDictEntryByNumber(group, elem);
74 dictEntry = NewVirtualDictEntry(group, elem);
77 gdcmBinEntry *newEntry = new gdcmBinEntry(dictEntry);
80 dbg.Verbose(1, "gdcmDocument::NewBinEntryByNumber",
81 "failed to allocate gdcmBinEntry");
88 * \brief Build a new Seq Entry from all the low level arguments.
89 * Check for existence of dictionary entry, and build
90 * a default one when absent.
91 * @param Group group number of the underlying DictEntry
92 * @param Elem element number of the underlying DictEntry
94 gdcmSeqEntry* gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
97 // Find out if the tag we encountered is in the dictionaries:
98 gdcmDictEntry* DictEntry = GetDictEntryByNumber( Group, Elem );
101 DictEntry = NewVirtualDictEntry(Group, Elem);
104 gdcmSeqEntry *NewEntry = new gdcmSeqEntry( DictEntry );
107 dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber",
108 "failed to allocate gdcmSeqEntry");
114 //-----------------------------------------------------------------------------
118 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
121 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string const & name)
123 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
124 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
130 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
135 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
136 * @param name : name of the searched element.
140 std::string gdcmDocEntrySet::GetEntryByName(TagName const & name)
142 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
143 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
150 return GetEntryByNumber(dictEntry->GetGroup(), dictEntry->GetElement());
155 * \brief Request a new virtual dict entry to the dict set
156 * @param group group number of the underlying DictEntry
157 * @param element element number of the underlying DictEntry
158 * @param vr VR of the underlying DictEntry
159 * @param fourth owner group
160 * @param name english name
162 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
164 std::string const & vr,
165 std::string const & fourth,
166 std::string const & name)
168 return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
172 * Creates a new DocEntry (without any 'value' ...)
173 * @param group group number of the underlying DictEntry
174 * @param elem elem number of the underlying DictEntry
176 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
179 // Find out if the tag we encountered is in the dictionaries:
180 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
181 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
184 dictEntry = NewVirtualDictEntry(group, elem);
187 gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
190 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
191 "failed to allocate gdcmDocEntry");
199 * Creates a new DocEntry (without any 'value' ...)
200 * @param group group number of the underlying DictEntry
201 * @param elem elem number of the underlying DictEntry
202 * @param VR V(alue) R(epresentation) of the Entry -if private Entry-
205 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
207 std::string const &VR)
209 // Find out if the tag we encountered is in the dictionaries:
210 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
211 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
214 dictEntry = NewVirtualDictEntry(group, elem, VR);
217 gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
220 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
221 "failed to allocate gdcmDocEntry");
227 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
228 * an remove gdcmDocument::NewDocEntryByName
230 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string const & name)
232 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
233 gdcmDictEntry *newTag = pubDict->GetDictEntryByName(name);
236 newTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", name);
239 gdcmDocEntry* newEntry = new gdcmDocEntry(newTag);
242 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
243 "failed to allocate gdcmDocEntry");
252 * \brief Searches both the public and the shadow dictionary (when they
253 * exist) for the presence of the DictEntry with given name.
254 * The public dictionary has precedence on the shadow one.
255 * @param name Name of the searched DictEntry
256 * @return Corresponding DictEntry when it exists, NULL otherwise.
258 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string const & name)
260 gdcmDictEntry *found = 0;
261 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
264 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
265 "we SHOULD have a default dictionary");
269 found = pubDict->GetDictEntryByName(name);
275 * \brief Searches both the public and the shadow dictionary (when they
276 * exist) for the presence of the DictEntry with given
277 * group and element. The public dictionary has precedence on the
279 * @param group group number of the searched DictEntry
280 * @param element element number of the searched DictEntry
281 * @return Corresponding DictEntry when it exists, NULL otherwise.
283 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
286 gdcmDictEntry *found = 0;
287 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
290 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
291 "we SHOULD have a default dictionary");
295 found = pubDict->GetDictEntryByNumber(group, element);
301 //-----------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------