]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
ENH: First pass at removing name of function from hardcoded string from gdcmVerboseMa...
[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:03:30 $
7   Version:   $Revision: 1.37 $
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       gdcmVerboseMacro( "Failed to allocate ValEntry");
75       return 0;
76    }
77    return newEntry;
78 }
79
80
81 /**
82  * \brief   Build a new Bin Entry from all the low level arguments. 
83  *          Check for existence of dictionary entry, and build
84  *          a default one when absent.
85  * @param   group group   number of the new Entry
86  * @param   elem  element number of the new Entry
87  * @param   vr     VR of the new Entry 
88  */
89 BinEntry *DocEntrySet::NewBinEntryByNumber(uint16_t group,uint16_t elem,
90                                            TagName const & vr) 
91 {
92    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, vr);
93    assert(dictEntry);
94
95    BinEntry *newEntry = new BinEntry(dictEntry);
96    if (!newEntry) 
97    {
98       gdcmVerboseMacro( "Failed to allocate BinEntry");
99       return 0;
100    }
101    return newEntry;
102 }
103
104 /**
105  * \brief   Build a new Seq Entry from all the low level arguments. 
106  *          Check for existence of dictionary entry, and build
107  *          a default one when absent.
108  * @param   group group   number of the new Entry
109  * @param   elem  element number of the new Entry
110  */
111 SeqEntry* DocEntrySet::NewSeqEntryByNumber(uint16_t group,uint16_t elem) 
112 {
113    DictEntry *dictEntry = GetDictEntryByNumber(group, elem, "SQ");
114    assert(dictEntry);
115
116    SeqEntry *newEntry = new SeqEntry( dictEntry );
117    if (!newEntry)
118    {
119       gdcmVerboseMacro( "Failed to allocate SeqEntry");
120       return 0;
121    }
122    return newEntry;
123 }
124
125 /**
126  * \brief   Searches both the public and the shadow dictionary (when they
127  *          exist) for the presence of the DictEntry with given
128  *          group and element. The public dictionary has precedence on the
129  *          shadow one.
130  * @param   group   group number of the searched DictEntry
131  * @param   elem element number of the searched DictEntry
132  * @return  Corresponding DictEntry when it exists, NULL otherwise.
133  */
134 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group,uint16_t elem) 
135 {
136    DictEntry *found = 0;
137    Dict *pubDict = Global::GetDicts()->GetDefaultPubDict();
138    if (!pubDict) 
139    {
140       gdcmVerboseMacro( "We SHOULD have a default dictionary");
141    }
142    else
143    {
144       found = pubDict->GetDictEntryByNumber(group, elem);  
145    }
146    return found;
147 }
148
149 DictEntry *DocEntrySet::GetDictEntryByNumber(uint16_t group, uint16_t elem,
150                                              TagName const & vr)
151 {
152    DictEntry *dictEntry = GetDictEntryByNumber(group,elem);
153    DictEntry *goodEntry = dictEntry;
154    std::string goodVR=vr;
155
156    if (elem==0x0000)
157       goodVR="UL";
158
159    if (goodEntry)
160       if (goodEntry->GetVR() != goodVR && goodVR!=GDCM_UNKNOWN)
161          goodEntry=NULL;
162
163    // Create a new virtual DictEntry if necessary
164    if (!goodEntry)
165    {
166       if (dictEntry)
167          goodEntry = NewVirtualDictEntry(group, elem, goodVR,"FIXME",dictEntry->GetName());
168       else
169          goodEntry = NewVirtualDictEntry(group, elem, goodVR);
170    }
171
172    return goodEntry;
173 }
174
175 //-----------------------------------------------------------------------------
176 // Private
177
178 } // end namespace gdcm
179
180 //-----------------------------------------------------------------------------