]> Creatis software - gdcm.git/blob - src/gdcmDictEntry.cxx
// according to 'Purify', TranslateToKey is one of the most
[gdcm.git] / src / gdcmDictEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/07 08:59:39 $
7   Version:   $Revision: 1.46 $
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
19 #include "gdcmDictEntry.h"
20 #include "gdcmDebug.h"
21 #include "gdcmUtil.h"
22
23 #include <iomanip> // for std::ios::left, ...
24 #include <fstream>
25
26 namespace gdcm 
27 {
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief   Constructor
32  * @param   group      DICOM-Group Number
33  * @param   elem       DICOM-Element Number
34  * @param   vr         Value Representation
35  * @param   vm         Value Mutlplicity 
36  * @param   name      description of the element
37 */
38
39 DictEntry::DictEntry(uint16_t group, uint16_t elem,
40                      TagName const &vr, 
41                      TagName const &vm,
42                      TagName const &name)
43 {
44    Group   = group;
45    Element = elem;
46    VR      = vr;
47    VM      = vm;
48    Name    = name;
49    Key     = TranslateToKey(group, elem);
50 }
51
52 //-----------------------------------------------------------------------------
53 // Public
54 /**
55  * \brief       If-and only if-the V(alue) R(epresentation)
56  * \            is unset then overwrite it.
57  * @param vr    New V(alue) R(epresentation) to be set.
58  */
59 void DictEntry::SetVR(TagName const &vr) 
60 {
61    if ( IsVRUnknown() )
62    {
63       VR = vr;
64    }
65    else 
66    {
67       gdcmErrorMacro( "Overwriting VR might compromise a dictionary");
68    }
69 }
70
71 /**
72  * \brief       If-and only if-the V(alue) M(ultiplicity)
73  * \            is unset then overwrite it.
74  * @param vm    New V(alue) M(ultiplicity) to be set.
75  */
76 void DictEntry::SetVM(TagName const &vm) 
77 {
78    if ( IsVMUnknown() )
79    {
80       VM = vm;
81    }
82    else 
83    {
84       gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
85    }
86 }
87
88 /**
89  * \brief   concatenates 2 uint16_t (supposed to be a Dicom group number 
90  *                                              and a Dicom element number)
91  * @param  group the Dicom group number used to build the tag
92  * @param  elem the Dicom element number used to build the tag
93  * @return the built tag
94  */
95 TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem)
96 {
97    // according to 'Purify', TranslateToKey is one of the most
98    // time consuming methods.
99    // Let's try to shorten it !
100  
101    //return Util::Format("%04x|%04x", group, elem);
102    char res[10];
103    sprintf(res,"%04x|%04x", group, elem);
104    return res;
105 }
106
107 //-----------------------------------------------------------------------------
108 // Protected
109
110 //-----------------------------------------------------------------------------
111 // Private
112
113 //-----------------------------------------------------------------------------
114 // Print
115 /**
116  * \brief   Prints an entry of the Dicom DictionaryEntry
117  * @param   os ostream we want to print in
118  * @param indent Indentation string to be prepended during printing
119  */
120 void DictEntry::Print(std::ostream &os, std::string const & )
121 {
122    std::string vr;
123    std::ostringstream s;
124
125    vr = GetVR();
126    if(vr==GDCM_UNKNOWN)
127       vr="  ";
128
129    s << DictEntry::TranslateToKey(GetGroup(),GetElement()); 
130    s << " [" << vr  << "] ";
131
132    if (PrintLevel >= 1)
133    {
134       s.setf(std::ios::left);
135       s << std::setw(66-GetName().length()) << " ";
136    }
137
138    s << "[" << GetName()<< "]";
139    os << s.str() << std::endl;
140 }
141
142 //-----------------------------------------------------------------------------
143 } // end namespace gdcm
144