]> Creatis software - gdcm.git/blob - src/gdcmDictEntry.cxx
cfe420d81a88496853dc6fe7a6aedf1eaf537607
[gdcm.git] / src / gdcmDictEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/19 13:17:04 $
7   Version:   $Revision: 1.53 $
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 #include <stdio.h> // for sprintf
26
27 namespace gdcm 
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 Multiplicity 
37  * @param   name       description of the element
38 */
39
40 DictEntry::DictEntry(uint16_t group, uint16_t elem,
41                      VRKey const &vr, 
42                      TagName const &vm,
43                      TagName const &name):
44    DicomEntry(group,elem,vr)
45 {
46    VM      = vm;
47    Name    = name;
48 }
49
50 //-----------------------------------------------------------------------------
51 // Public
52 /**
53  * \brief       If-and only if-the V(alue) R(epresentation)
54  * \            is unset then overwrite it.
55  * @param vr    New V(alue) R(epresentation) to be set.
56  */
57 void DictEntry::SetVR(VRKey const &vr) 
58 {
59    if ( IsVRUnknown() )
60    {
61       DicomEntry::SetVR(vr);
62    }
63    else 
64    {
65       gdcmErrorMacro( "Overwriting VR might compromise a dictionary");
66    }
67 }
68
69 /**
70  * \brief       If-and only if-the V(alue) M(ultiplicity)
71  * \            is unset then overwrite it.
72  * @param vm    New V(alue) M(ultiplicity) to be set.
73  */
74 void DictEntry::SetVM(TagName const &vm) 
75 {
76    if ( IsVMUnknown() )
77    {
78       VM = vm;
79    }
80    else 
81    {
82       gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
83    }
84 }
85
86 //-----------------------------------------------------------------------------
87 // Protected
88
89 //-----------------------------------------------------------------------------
90 // Private
91
92 //-----------------------------------------------------------------------------
93 // Print
94 /**
95  * \brief   Prints an entry of the Dicom DictionaryEntry
96  * @param   os ostream we want to print in
97  * @param indent Indentation string to be prepended during printing
98  */
99 void DictEntry::Print(std::ostream &os, std::string const &indent )
100 {
101    DicomEntry::Print(os,indent);
102
103    VRKey vr;
104    std::ostringstream s;
105
106    if ( PrintLevel >= 1 )
107    {
108       s.setf(std::ios::left);
109       s << std::setw(66-GetName().length()) << " ";
110    }
111
112    s << "[" << GetName()<< "]";
113    os << s.str() << std::endl;
114 }
115
116 //-----------------------------------------------------------------------------
117 } // end namespace gdcm
118