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