1 /*=========================================================================
4 Module: $RCSfile: gdcmDictEntry.cxx,v $
6 Date: $Date: 2005/07/11 15:20:46 $
7 Version: $Revision: 1.51 $
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.
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.
17 =========================================================================*/
19 #include "gdcmDictEntry.h"
20 #include "gdcmDebug.h"
23 #include <iomanip> // for std::ios::left, ...
25 #include <stdio.h> // for sprintf
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
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
40 DictEntry::DictEntry(uint16_t group, uint16_t elem,
50 Key = TranslateToKey(group, elem);
53 //-----------------------------------------------------------------------------
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.
60 void DictEntry::SetVR(TagName const &vr)
68 gdcmErrorMacro( "Overwriting VR might compromise a dictionary");
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.
77 void DictEntry::SetVM(TagName const &vm)
85 gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
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
96 TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem)
98 // according to 'Purify', TranslateToKey is one of the most
99 // time consuming methods.
100 // Let's try to shorten it !
102 //return Util::Format("%04x|%04x", group, elem); // too much time !
110 sprintf(res,"%04x|%04x", group, elem);
115 //-----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
124 * \brief Prints an entry of the Dicom DictionaryEntry
125 * @param os ostream we want to print in
126 * @param indent Indentation string to be prepended during printing
128 void DictEntry::Print(std::ostream &os, std::string const & )
131 std::ostringstream s;
134 if ( vr==GDCM_UNKNOWN )
137 s << DictEntry::TranslateToKey(GetGroup(),GetElement());
138 s << " [" << vr << "] ";
140 if ( PrintLevel >= 1 )
142 s.setf(std::ios::left);
143 s << std::setw(66-GetName().length()) << " ";
146 s << "[" << GetName()<< "]";
147 os << s.str() << std::endl;
150 //-----------------------------------------------------------------------------
151 } // end namespace gdcm