GDCM  2.4.5
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 {
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  }
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;
124  unsigned int SyngoDTField;
125  unsigned int NoOfItemsField;
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
Value & GetValue()
Definition: gdcmCSAElement.h:62
const char * GetName() const
Set/Get Name.
Definition: gdcmCSAElement.h:41
void SetVM(const VM &vm)
Definition: gdcmCSAElement.h:46
bool IsEmpty() const
Check if CSA Element is empty.
Definition: gdcmCSAElement.h:68
SmartPointer< Value > DataPtr
Definition: gdcmCSAElement.h:126
Class to represent the value of a Data Element.
Definition: gdcmValue.h:31
unsigned int GetNoOfItems() const
Set/Get NoOfItems.
Definition: gdcmCSAElement.h:57
VL GetLength() const
Definition: gdcmByteValue.h:78
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
void SetKey(unsigned int key)
Definition: gdcmCSAElement.h:38
void SetName(const char *name)
Definition: gdcmCSAElement.h:42
void SetByteValue(const char *array, VL length)
Set.
Definition: gdcmCSAElement.h:71
CSAElement & operator=(const CSAElement &de)
Definition: gdcmCSAElement.h:96
CSAElement(unsigned int kf=0)
Definition: gdcmCSAElement.h:32
Value Length.
Definition: gdcmVL.h:29
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition: gdcmDirectory.h:88
VR VRField
Definition: gdcmCSAElement.h:123
DataPtr DataField
Definition: gdcmCSAElement.h:127
bool operator==(const CSAElement &de) const
Definition: gdcmCSAElement.h:108
Class to represent binary value (array of bytes)
Definition: gdcmByteValue.h:35
Value const & GetValue() const
Set/Get Value (bytes array, SQ of items, SQ of fragments):
Definition: gdcmCSAElement.h:61
void SetNoOfItems(unsigned int items)
Definition: gdcmCSAElement.h:58
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:67
unsigned int KeyField
Definition: gdcmCSAElement.h:120
bool operator<(const CSAElement &de) const
Definition: gdcmCSAElement.h:92
std::string NameField
Definition: gdcmCSAElement.h:121
unsigned int SyngoDTField
Definition: gdcmCSAElement.h:124
Class to represent a CSA Element.
Definition: gdcmCSAElement.h:29
const ByteValue * GetByteValue() const
Definition: gdcmCSAElement.h:78
unsigned int GetKey() const
Set/Get Key.
Definition: gdcmCSAElement.h:37
const char * GetPointer() const
Definition: gdcmByteValue.h:111
unsigned int NoOfItemsField
Definition: gdcmCSAElement.h:125
CSAElement(const CSAElement &_val)
Definition: gdcmCSAElement.h:84
VM ValueMultiplicityField
Definition: gdcmCSAElement.h:122
VR class This is adapted from DICOM standard The biggest difference is the INVALID VR and the composi...
Definition: gdcmVR.h:54
Definition: gdcmASN1.h:20
void SetSyngoDT(unsigned int syngodt)
Definition: gdcmCSAElement.h:54
void SetValue(Value const &vl)
Definition: gdcmCSAElement.h:63
Definition: gdcmVM.h:72
VR const & GetVR() const
Set/Get VR.
Definition: gdcmCSAElement.h:49
const VM & GetVM() const
Set/Get VM.
Definition: gdcmCSAElement.h:45
unsigned int GetSyngoDT() const
Set/Get SyngoDT.
Definition: gdcmCSAElement.h:53
void SetVR(VR const &vr)
Definition: gdcmCSAElement.h:50

Generated on Fri Sep 25 2015 17:58:22 for GDCM by doxygen 1.8.9.1
SourceForge.net Logo