]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
Removal out of the Dicom Dictionary of non dicom 'fourth' field
[gdcm.git] / src / gdcmDocEntrySet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/07 12:29:17 $
7   Version:   $Revision: 1.34 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDocEntrySet.h"
19
20 #include "gdcmDebug.h"
21 #include "gdcmCommon.h"
22 #include "gdcmDictSet.h"
23 #include "gdcmGlobal.h"
24 #include "gdcmException.h"
25 #include "gdcmDocEntry.h"
26 #include "gdcmSeqEntry.h"
27 #include "gdcmValEntry.h"
28 #include "gdcmBinEntry.h"
29
30 #include <assert.h>
31
32 namespace gdcm 
33 {
34
35 //-----------------------------------------------------------------------------
36 // Public
37
38
39 /**
40  * \brief   Request a new virtual dict entry to the dict set
41  * @param   group group  number of the underlying DictEntry
42  * @param   elem  element number of the underlying DictEntry
43  * @param   vr    VR (Value Representation) of the underlying DictEntry
44  * @param   vm    VM (Value Multiplicity) of the underlying DictEntry
45  * @param   name   english name
46  */
47 DictEntry* DocEntrySet::NewVirtualDictEntry( uint16_t group,uint16_t elem,
48                                              TagName const & vr,
49                                              TagName const & vm,
50                                              TagName const & name )
51 {
52    return Global::GetDicts()->NewVirtualDictEntry(group,elem,vr,vm,name);
53 }
54
55 //-----------------------------------------------------------------------------
56 // Protected
57 /**
58  * \brief   Build a new Val Entry 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 new Entry
62  * @param   elem  element number of the new Entry
63  * @param   vr     VR of the new Entry 
64  */
65 ValEntry *DocEntrySet::NewValEntryByNumber(uint16_t group,uint16_t elem,
66                                            TagName const & vr) 
67 {
68    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, vr);
69    assert(dictEntry);
70
71    ValEntry *newEntry = new ValEntry(dictEntry);
72    if (!newEntry) 
73    {
74       dbg.Verbose(1, "Document::NewValEntryByNumber",
75                   "failed to allocate ValEntry");
76       return 0;
77    }
78    return newEntry;
79 }
80
81
82 /**
83  * \brief   Build a new Bin Entry 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 new Entry
87  * @param   elem  element number of the new Entry
88  * @param   vr     VR of the new Entry 
89  */
90 BinEntry *DocEntrySet::NewBinEntryByNumber(uint16_t group,uint16_t elem,
91                                            TagName const & vr) 
92 {
93    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, vr);
94    assert(dictEntry);
95
96    BinEntry *newEntry = new BinEntry(dictEntry);
97    if (!newEntry) 
98    {
99       dbg.Verbose(1, "Document::NewBinEntryByNumber",
100                   "failed to allocate BinEntry");
101       return 0;
102    }
103    return newEntry;
104 }
105
106 /**
107  * \brief   Build a new Seq Entry from all the low level arguments. 
108  *          Check for existence of dictionary entry, and build
109  *          a default one when absent.
110  * @param   group group   number of the new Entry
111  * @param   elem  element number of the new Entry
112  */
113 SeqEntry* DocEntrySet::NewSeqEntryByNumber(uint16_t group,uint16_t elem) 
114 {
115    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, "SQ");
116    assert(dictEntry);
117
118    SeqEntry *newEntry = new SeqEntry( dictEntry );
119    if (!newEntry)
120    {
121       dbg.Verbose(1, "Document::NewSeqEntryByNumber",
122                   "failed to allocate SeqEntry");
123       return 0;
124    }
125    return newEntry;
126 }
127
128 /**
129  * \brief   Searches both the public and the shadow dictionary (when they
130  *          exist) for the presence of the DictEntry with given
131  *          group and element. The public dictionary has precedence on the
132  *          shadow one.
133  * @param   group   group number of the searched DictEntry
134  * @param   elem element number of the searched DictEntry
135  * @return  Corresponding DictEntry when it exists, NULL otherwise.
136  */
137 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group,uint16_t elem) 
138 {
139    DictEntry *found = 0;
140    Dict *pubDict = Global::GetDicts()->GetDefaultPubDict();
141    if (!pubDict) 
142    {
143       dbg.Verbose(0, "Document::GetDictEntry",
144                      "we SHOULD have a default dictionary");
145    }
146    else
147    {
148       found = pubDict->GetDictEntryByNumber(group, elem);  
149    }
150    return found;
151 }
152
153 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group, uint16_t elem,
154                                              TagName const & vr)
155 {
156    DictEntry *dictEntry = GetDictEntryByNumber(group,elem);
157    DictEntry *goodEntry = dictEntry;
158    std::string goodVR=vr;
159
160    if (elem==0x0000)
161       goodVR="UL";
162
163    if (goodEntry)
164       if (goodEntry->GetVR() != goodVR && goodVR!=GDCM_UNKNOWN)
165          goodEntry=NULL;
166
167    // Create a new virtual DictEntry if necessary
168    if (!goodEntry)
169    {
170       if (dictEntry)
171          goodEntry = NewVirtualDictEntry(group, elem, goodVR,"FIXME",dictEntry->GetName());
172       else
173          goodEntry = NewVirtualDictEntry(group, elem, goodVR);
174    }
175
176    return goodEntry;
177 }
178
179 //-----------------------------------------------------------------------------
180 // Private
181
182 } // end namespace gdcm
183
184 //-----------------------------------------------------------------------------