]> Creatis software - gdcm.git/blob - src/gdcmDictEntry.cxx
Typo + Doxygen
[gdcm.git] / src / gdcmDictEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/14 14:00:03 $
7   Version:   $Revision: 1.49 $
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                      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 // Public
55 /**
56  * \brief       If-and only if-the V(alue) R(epresentation)
57  * \            is unset then overwrite it.
58  * @param vr    New V(alue) R(epresentation) to be set.
59  */
60 void DictEntry::SetVR(TagName const &vr) 
61 {
62    if ( IsVRUnknown() )
63    {
64       VR = vr;
65    }
66    else 
67    {
68       gdcmErrorMacro( "Overwriting VR might compromise a dictionary");
69    }
70 }
71
72 /**
73  * \brief       If-and only if-the V(alue) M(ultiplicity)
74  * \            is unset then overwrite it.
75  * @param vm    New V(alue) M(ultiplicity) to be set.
76  */
77 void DictEntry::SetVM(TagName const &vm) 
78 {
79    if ( IsVMUnknown() )
80    {
81       VM = vm;
82    }
83    else 
84    {
85       gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
86    }
87 }
88
89 /**
90  * \brief   concatenates 2 uint16_t (supposed to be a Dicom group number 
91  *                                              and a Dicom element number)
92  * @param  group the Dicom group number used to build the tag
93  * @param  elem the Dicom element number used to build the tag
94  * @return the built tag
95  */
96 TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem)
97 {
98    // according to 'Purify', TranslateToKey is one of the most
99    // time consuming methods.
100    // Let's try to shorten it !
101  
102    //return Util::Format("%04x|%04x", group, elem); // too much time !
103    char res[10];
104    sprintf(res,"%04x|%04x", group, elem);
105    return res;
106 }
107
108 //-----------------------------------------------------------------------------
109 // Protected
110
111 //-----------------------------------------------------------------------------
112 // Private
113
114 //-----------------------------------------------------------------------------
115 // Print
116 /**
117  * \brief   Prints an entry of the Dicom DictionaryEntry
118  * @param   os ostream we want to print in
119  * @param indent Indentation string to be prepended during printing
120  */
121 void DictEntry::Print(std::ostream &os, std::string const & )
122 {
123    std::string vr;
124    std::ostringstream s;
125
126    vr = GetVR();
127    if(vr==GDCM_UNKNOWN)
128       vr="  ";
129
130    s << DictEntry::TranslateToKey(GetGroup(),GetElement()); 
131    s << " [" << vr  << "] ";
132
133    if (PrintLevel >= 1)
134    {
135       s.setf(std::ios::left);
136       s << std::setw(66-GetName().length()) << " ";
137    }
138
139    s << "[" << GetName()<< "]";
140    os << s.str() << std::endl;
141 }
142
143 //-----------------------------------------------------------------------------
144 } // end namespace gdcm
145