1 /*=========================================================================
4 Module: $RCSfile: gdcmDocEntrySet.cxx,v $
6 Date: $Date: 2004/08/01 03:20:23 $
7 Version: $Revision: 1.15 $
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 Element Value 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 Element Value 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");
112 //-----------------------------------------------------------------------------
116 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
119 gdcmDocEntry *gdcmDocEntrySet::GetDocEntryByName(std::string const & name)
121 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
122 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
128 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
133 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
134 * @param name : name of the searched element.
138 std::string gdcmDocEntrySet::GetEntryByName(TagName const & name)
140 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
141 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByName(name);
148 return GetEntryByNumber(dictEntry->GetGroup(), dictEntry->GetElement());
153 * \brief Request a new virtual dict entry to the dict set
154 * @param group group number of the underlying DictEntry
155 * @param element element number of the underlying DictEntry
156 * @param vr VR of the underlying DictEntry
157 * @param fourth owner group
158 * @param name english name
160 gdcmDictEntry* gdcmDocEntrySet::NewVirtualDictEntry(uint16_t group,
162 std::string const & vr,
163 std::string const & fourth,
164 std::string const & name)
166 return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
170 * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method
171 * an remove gdcmDocument::NewDocEntryByNumber
173 gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group,
176 // Find out if the tag we encountered is in the dictionaries:
177 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
178 gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem);
181 dictEntry = NewVirtualDictEntry(group, elem);
184 gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry);
187 dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber",
188 "failed to allocate gdcmDocEntry");
195 gdcmDocEntry *gdcmDocEntrySet::NewDocEntryByName (std::string const & name)
197 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
198 gdcmDictEntry *newTag = pubDict->GetDictEntryByName(name);
201 newTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", name);
204 gdcmDocEntry* newEntry = new gdcmDocEntry(newTag);
207 dbg.Verbose(1, "gdcmSQItem::ObtainDocEntryByName",
208 "failed to allocate gdcmDocEntry");
217 * \brief Searches both the public and the shadow dictionary (when they
218 * exist) for the presence of the DictEntry with given name.
219 * The public dictionary has precedence on the shadow one.
220 * @param Name name of the searched DictEntry
221 * @return Corresponding DictEntry when it exists, NULL otherwise.
223 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByName(std::string const & name)
225 gdcmDictEntry *found = 0;
226 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
229 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
230 "we SHOULD have a default dictionary");
234 found = pubDict->GetDictEntryByName(name);
240 * \brief Searches both the public and the shadow dictionary (when they
241 * exist) for the presence of the DictEntry with given
242 * group and element. The public dictionary has precedence on the
244 * @param group group number of the searched DictEntry
245 * @param element element number of the searched DictEntry
246 * @return Corresponding DictEntry when it exists, NULL otherwise.
248 gdcmDictEntry *gdcmDocEntrySet::GetDictEntryByNumber(uint16_t group,
251 gdcmDictEntry *found = 0;
252 gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
255 dbg.Verbose(0, "gdcmDocument::GetDictEntry",
256 "we SHOULD have a default dictionary");
260 found = pubDict->GetDictEntryByNumber(group, element);
266 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------