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