GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

gdcmCSAElement.h
Go to the documentation of this file.
1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14 #ifndef GDCMCSAELEMENT_H
15 #define GDCMCSAELEMENT_H
16
17 #include "gdcmTag.h"
18 #include "gdcmVM.h"
19 #include "gdcmVR.h"
20 #include "gdcmByteValue.h"
21 #include "gdcmSmartPointer.h"
22
23 namespace gdcm
24 {
29 class GDCM_EXPORT CSAElement
30 {
31 public:
32 CSAElement(unsigned int kf = 0):KeyField(kf) {}
33
34 friend std::ostream& operator<<(std::ostream &os, const CSAElement &val);
35
37 unsigned int GetKey() const { return KeyField; }
38 void SetKey(unsigned int key) { KeyField = key; }
39
41 const char *GetName() const { return NameField.c_str(); }
42 void SetName(const char *name) { NameField = name; }
43
45 const VM& GetVM() const { return ValueMultiplicityField; }
46 void SetVM(const VM &vm) { ValueMultiplicityField = vm; }
47
49 VR const &GetVR() const { return VRField; }
50 void SetVR(VR const &vr) { VRField = vr; }
51
53 unsigned int GetSyngoDT() const { return SyngoDTField; }
54 void SetSyngoDT(unsigned int syngodt) { SyngoDTField = syngodt; }
55
57 unsigned int GetNoOfItems() const { return NoOfItemsField; }
58 void SetNoOfItems(unsigned int items) { NoOfItemsField = items; }
59
61 Value const &GetValue() const { return *DataField; }
62 Value &GetValue() { return *DataField; }
63 void SetValue(Value const & vl) {
64 //assert( DataField == 0 );
65 DataField = vl;
66 }
68 bool IsEmpty() const { return DataField == 0; }
69
71 void SetByteValue(const char *array, VL length)
72 {
73 ByteValue *bv = new ByteValue(array,length);
74 SetValue( *bv );
75 }
78 const ByteValue* GetByteValue() const {
79 // Get the raw pointer from the gdcm::SmartPointer
80 const ByteValue *bv = dynamic_cast<const ByteValue*>(DataField.GetPointer());
81 return bv; // Will return NULL if not ByteValue
82 }
83
84 CSAElement(const CSAElement &_val)
85 {
86 if( this != &_val)
87 {
88 *this = _val;
89 }
90 }
91
92 bool operator<(const CSAElement &de) const
93 {
94 return GetKey() < de.GetKey();
95 }
96 CSAElement &operator=(const CSAElement &de)
97 {
98 KeyField = de.KeyField;
99 NameField = de.NameField;
100 ValueMultiplicityField = de.ValueMultiplicityField;
101 VRField = de.VRField;
102 SyngoDTField = de.SyngoDTField;
103 NoOfItemsField = de.NoOfItemsField;
104 DataField = de.DataField; // Pointer copy
105 return *this;
106 }
107
108 bool operator==(const CSAElement &de) const
109 {
110 return KeyField == de.KeyField
111 && NameField == de.NameField
112 && ValueMultiplicityField == de.ValueMultiplicityField
113 && VRField == de.VRField
114 && SyngoDTField == de.SyngoDTField
115 //&& ValueField == de.ValueField;
116 ;
117 }
118
119 protected:
120 unsigned int KeyField;
121 std::string NameField;
122 VM ValueMultiplicityField;
123 VR VRField;
124 unsigned int SyngoDTField;
125 unsigned int NoOfItemsField;
126 typedef SmartPointer<Value> DataPtr;
127 DataPtr DataField;
128 };
129 //-----------------------------------------------------------------------------
130 inline std::ostream& operator<<(std::ostream &os, const CSAElement &val)
131 {
132 os << val.KeyField;
133 os << " - '" << val.NameField;
134 os << "' VM " << val.ValueMultiplicityField;
135 os << ", VR " << val.VRField;
136 os << ", SyngoDT " << val.SyngoDTField;
137 os << ", NoOfItems " << val.NoOfItemsField;
138 os << ", Data ";
139 if( val.DataField )
140 {
141 //val.DataField->Print( os << "'" );
142 const ByteValue * bv = dynamic_cast< ByteValue*>(&*val.DataField);
143 assert( bv );
144 const char * p = bv->GetPointer();
145 std::string str(p, p + bv->GetLength() );
146 if( val.ValueMultiplicityField == VM::VM1 )
147 {
148 os << "'" << str.c_str() << "'";
149 }
150 else
151 {
152 std::istringstream is( str );
153 std::string s;
154 bool sep = false;
155 while( std::getline(is, s, '\\' ) )
156 {
157 if( sep )
158 {
159 os << '\\';
160 }
161 sep = true;
162 os << "'" << s.c_str() << "'";
163 }
164 //bv->Print( os << "'" );
165 //os << "'";
166 }
167 }
168 return os;
169 }
170
171 } // end namespace gdcm
172
173 #endif //GDCMCSAELEMENT_H