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