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