GDCM: gdcmCSAElement.h Source File

GDCM 3.2.10

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
23namespace gdcm
24{
29 class GDCM_EXPORT CSAElement
30{
31public:
32 CSAElement(unsigned int kf = 0):KeyField(kf),SyngoDTField(0),NoOfItemsField(0) {}
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 //gdcm_assert( DataField == 0 );
65 DataField = vl;
66 }
67
68 bool IsEmpty() const { return DataField == nullptr; }
69
71 void SetByteValue(const char *array, VL length)
72 {
73 ByteValue *bv = new ByteValue(array,length);
74 SetValue( *bv );
75 }
76
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 = default;
98
99 bool operator==(const CSAElement &de) const
100 {
101 return KeyField == de.KeyField
102 && NameField == de.NameField
103 && ValueMultiplicityField == de.ValueMultiplicityField
104 && VRField == de.VRField
105 && SyngoDTField == de.SyngoDTField
106 //&& ValueField == de.ValueField;
107 ;
108 }
109
110protected:
111 unsigned int KeyField;
112 std::string NameField;
113 VM ValueMultiplicityField;
114 VR VRField;
115 unsigned int SyngoDTField;
116 unsigned int NoOfItemsField;
117 typedef SmartPointer<Value> DataPtr;
118 DataPtr DataField;
119};
120//-----------------------------------------------------------------------------
121 inline std::ostream& operator<<(std::ostream &os, const CSAElement &val)
122{
123 os << val.KeyField;
124 os << " - '" << val.NameField;
125 os << "' VM " << val.ValueMultiplicityField;
126 os << ", VR " << val.VRField;
127 os << ", SyngoDT " << val.SyngoDTField;
128 os << ", NoOfItems " << val.NoOfItemsField;
129 os << ", Data ";
130 if( val.DataField )
131 {
132 //val.DataField->Print( os << "'" );
133 const ByteValue * bv = dynamic_cast<ByteValue*>(&*val.DataField);
134 gdcm_assert( bv );
135 const char * p = bv->GetPointer();
136 std::string str(p, p + bv->GetLength() );
137 if( val.ValueMultiplicityField == VM::VM1 )
138 {
139 os << "'" << str.c_str() << "'";
140 }
141 else
142 {
143 std::istringstream is( str );
144 std::string s;
145 bool sep = false;
146 while( std::getline(is, s, '\\' ) )
147 {
148 if( sep )
149 {
150 os << '\\';
151 }
152 sep = true;
153 os << "'" << s.c_str() << "'";
154 }
155 //bv->Print( os << "'" );
156 //os << "'";
157 }
158 }
159 return os;
160}
161
162} // end namespace gdcm
163
164#endif //GDCMCSAELEMENT_H
gdcm::ByteValue
Class to represent binary value (array of bytes).
Definition gdcmByteValue.h:36
gdcm::ByteValue::GetPointer
const char * GetPointer() const
Definition gdcmByteValue.h:114
gdcm::ByteValue::GetLength
VL GetLength() const override
Definition gdcmByteValue.h:81
gdcm::CSAElement
Class to represent a CSA Element.
Definition gdcmCSAElement.h:30
gdcm::CSAElement::SetValue
void SetValue(Value const &vl)
Definition gdcmCSAElement.h:63
gdcm::CSAElement::GetSyngoDT
unsigned int GetSyngoDT() const
Set/Get SyngoDT.
Definition gdcmCSAElement.h:53
gdcm::CSAElement::NameField
std::string NameField
Definition gdcmCSAElement.h:112
gdcm::CSAElement::operator==
bool operator==(const CSAElement &de) const
Definition gdcmCSAElement.h:99
gdcm::CSAElement::GetByteValue
const ByteValue * GetByteValue() const
Definition gdcmCSAElement.h:78
gdcm::CSAElement::SyngoDTField
unsigned int SyngoDTField
Definition gdcmCSAElement.h:115
gdcm::CSAElement::operator<
bool operator<(const CSAElement &de) const
Definition gdcmCSAElement.h:92
gdcm::CSAElement::SetNoOfItems
void SetNoOfItems(unsigned int items)
Definition gdcmCSAElement.h:58
gdcm::CSAElement::operator=
CSAElement & operator=(const CSAElement &de)=default
gdcm::CSAElement::SetSyngoDT
void SetSyngoDT(unsigned int syngodt)
Definition gdcmCSAElement.h:54
gdcm::CSAElement::ValueMultiplicityField
VM ValueMultiplicityField
Definition gdcmCSAElement.h:113
gdcm::CSAElement::GetName
const char * GetName() const
Set/Get Name.
Definition gdcmCSAElement.h:41
gdcm::CSAElement::KeyField
unsigned int KeyField
Definition gdcmCSAElement.h:111
gdcm::CSAElement::SetByteValue
void SetByteValue(const char *array, VL length)
Set.
Definition gdcmCSAElement.h:71
gdcm::CSAElement::DataPtr
SmartPointer< Value > DataPtr
Definition gdcmCSAElement.h:117
gdcm::CSAElement::CSAElement
CSAElement(unsigned int kf=0)
Definition gdcmCSAElement.h:32
gdcm::CSAElement::IsEmpty
bool IsEmpty() const
Check if CSA Element is empty.
Definition gdcmCSAElement.h:68
gdcm::CSAElement::GetVR
VR const & GetVR() const
Set/Get VR.
Definition gdcmCSAElement.h:49
gdcm::CSAElement::SetVR
void SetVR(VR const &vr)
Definition gdcmCSAElement.h:50
gdcm::CSAElement::VRField
VR VRField
Definition gdcmCSAElement.h:114
gdcm::CSAElement::NoOfItemsField
unsigned int NoOfItemsField
Definition gdcmCSAElement.h:116
gdcm::CSAElement::GetValue
Value & GetValue()
Definition gdcmCSAElement.h:62
gdcm::CSAElement::CSAElement
CSAElement(const CSAElement &_val)
Definition gdcmCSAElement.h:84
gdcm::CSAElement::GetNoOfItems
unsigned int GetNoOfItems() const
Set/Get NoOfItems.
Definition gdcmCSAElement.h:57
gdcm::CSAElement::GetVM
const VM & GetVM() const
Set/Get VM.
Definition gdcmCSAElement.h:45
gdcm::CSAElement::GetKey
unsigned int GetKey() const
Set/Get Key.
Definition gdcmCSAElement.h:37
gdcm::CSAElement::DataField
DataPtr DataField
Definition gdcmCSAElement.h:118
gdcm::CSAElement::SetName
void SetName(const char *name)
Definition gdcmCSAElement.h:42
gdcm::CSAElement::GetValue
Value const & GetValue() const
Set/Get Value (bytes array, SQ of items, SQ of fragments):
Definition gdcmCSAElement.h:61
gdcm::CSAElement::SetKey
void SetKey(unsigned int key)
Definition gdcmCSAElement.h:38
gdcm::CSAElement::SetVM
void SetVM(const VM &vm)
Definition gdcmCSAElement.h:46
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::VL
Value Length.
Definition gdcmVL.h:30
gdcm::VM
Value Multiplicity Looking at the DICOMV3 dict only there is very few cases: 1 2 3 4 5 6 8 16 24 1-2 ...
Definition gdcmVM.h:68
gdcm::VM::VM1
@ VM1
Definition gdcmVM.h:72
gdcm::VR
VR class.
Definition gdcmVR.h:55
gdcm::Value
Class to represent the value of a Data Element.
Definition gdcmValue.h:32
gdcmByteValue.h
gdcm_assert
#define gdcm_assert(cond)
Definition gdcmException.h:104
gdcmSmartPointer.h
gdcmTag.h
gdcmVM.h
gdcmVR.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21
gdcm::operator<<
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88