]> Creatis software - gdcm.git/blob - src/gdcmDictEntry.cxx
* Add a RefCounter object that is deleted only when it's reference count is
[gdcm.git] / src / gdcmDictEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/20 15:24:08 $
7   Version:   $Revision: 1.54 $
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 DictEntry::DictEntry(uint16_t group, uint16_t elem,
40                      VRKey const &vr, 
41                      TagName const &vm,
42                      TagName const &name):
43    DicomEntry(group,elem,vr)
44 {
45    VM      = vm;
46    Name    = name;
47 }
48
49 //-----------------------------------------------------------------------------
50 // Public
51 /**
52  * \brief Class allocator
53  * @param   group      DICOM-Group Number
54  * @param   elem       DICOM-Element Number
55  * @param   vr         Value Representation
56  * @param   vm         Value Multiplicity 
57  * @param   name       description of the element
58 */
59 DictEntry *DictEntry::New(uint16_t group, uint16_t elem,
60                           VRKey const &vr,
61                           TagName const &vm,
62                           TagName const &name)
63 {
64    return new DictEntry(group,elem,vr,vm,name);
65 }
66
67 /**
68  * \brief       If-and only if-the V(alue) R(epresentation)
69  * \            is unset then overwrite it.
70  * @param vr    New V(alue) R(epresentation) to be set.
71  */
72 void DictEntry::SetVR(VRKey const &vr) 
73 {
74    if ( IsVRUnknown() )
75    {
76       DicomEntry::SetVR(vr);
77    }
78    else 
79    {
80       gdcmErrorMacro( "Overwriting VR might compromise a dictionary");
81    }
82 }
83
84 /**
85  * \brief       If-and only if-the V(alue) M(ultiplicity)
86  * \            is unset then overwrite it.
87  * @param vm    New V(alue) M(ultiplicity) to be set.
88  */
89 void DictEntry::SetVM(TagName const &vm) 
90 {
91    if ( IsVMUnknown() )
92    {
93       VM = vm;
94    }
95    else 
96    {
97       gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
98    }
99 }
100
101 //-----------------------------------------------------------------------------
102 // Protected
103
104 //-----------------------------------------------------------------------------
105 // Private
106
107 //-----------------------------------------------------------------------------
108 // Print
109 /**
110  * \brief   Prints an entry of the Dicom DictionaryEntry
111  * @param   os ostream we want to print in
112  * @param indent Indentation string to be prepended during printing
113  */
114 void DictEntry::Print(std::ostream &os, std::string const &indent )
115 {
116    DicomEntry::Print(os,indent);
117
118    VRKey vr;
119    std::ostringstream s;
120
121    if ( PrintLevel >= 1 )
122    {
123       s.setf(std::ios::left);
124       s << std::setw(66-GetName().length()) << " ";
125    }
126
127    s << "[" << GetName()<< "]";
128    os << s.str() << std::endl;
129 }
130
131 //-----------------------------------------------------------------------------
132 } // end namespace gdcm
133