]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
ENH: minor style
[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 22:24:00 $
7   Version:   $Revision: 1.40 $
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::NewValEntryByNumber(uint16_t group,uint16_t elem,
64                                            TagName const & vr) 
65 {
66    DictEntry *dictEntry = GetDictEntryByNumber(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::NewBinEntryByNumber(uint16_t group,uint16_t elem,
88                                            TagName const & vr) 
89 {
90    DictEntry *dictEntry = GetDictEntryByNumber(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::NewSeqEntryByNumber(uint16_t group,uint16_t elem) 
110 {
111    DictEntry *dictEntry = GetDictEntryByNumber(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::GetDictEntryByNumber(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->GetDictEntryByNumber(group, elem);  
143    }
144    return found;
145 }
146
147 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group, uint16_t elem,
148                                              TagName const & vr)
149 {
150    DictEntry *dictEntry = GetDictEntryByNumber(group,elem);
151    DictEntry *goodEntry = dictEntry;
152    std::string goodVR = vr;
153
154    if (elem == 0x0000) goodVR="UL";
155
156    if ( goodEntry )
157    {
158       if ( goodVR != goodEntry->GetVR()
159         && goodVR != GDCM_UNKNOWN )
160       {
161          goodEntry = NULL;
162       }
163    }
164
165    // Create a new virtual DictEntry if necessary
166    if (!goodEntry)
167    {
168       if (dictEntry)
169       {
170          goodEntry = NewVirtualDictEntry(group, elem, goodVR, "FIXME", 
171                                          dictEntry->GetName() );
172       }
173       else
174       {
175          goodEntry = NewVirtualDictEntry(group, elem, goodVR);
176       }
177    }
178
179    return goodEntry;
180 }
181
182 //-----------------------------------------------------------------------------
183 // Private
184
185 } // end namespace gdcm
186
187 //-----------------------------------------------------------------------------