GDCM
2.2.3
|
00001 /*========================================================================= 00002 00003 Program: GDCM (Grassroots DICOM). A DICOM library 00004 00005 Copyright (c) 2006-2011 Mathieu Malaterre 00006 All rights reserved. 00007 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 #ifndef GDCMCSAELEMENT_H 00015 #define GDCMCSAELEMENT_H 00016 00017 #include "gdcmTag.h" 00018 #include "gdcmVM.h" 00019 #include "gdcmVR.h" 00020 #include "gdcmByteValue.h" 00021 #include "gdcmSmartPointer.h" 00022 00023 namespace gdcm 00024 { 00029 class GDCM_EXPORT CSAElement 00030 { 00031 public: 00032 CSAElement(unsigned int kf = 0):KeyField(kf) {} 00033 00034 friend std::ostream& operator<<(std::ostream &os, const CSAElement &val); 00035 00037 unsigned int GetKey() const { return KeyField; } 00038 void SetKey(unsigned int key) { KeyField = key; } 00039 00041 const char *GetName() const { return NameField.c_str(); } 00042 void SetName(const char *name) { NameField = name; } 00043 00045 const VM& GetVM() const { return ValueMultiplicityField; } 00046 void SetVM(const VM &vm) { ValueMultiplicityField = vm; } 00047 00049 VR const &GetVR() const { return VRField; } 00050 void SetVR(VR const &vr) { VRField = vr; } 00051 00053 unsigned int GetSyngoDT() const { return SyngoDTField; } 00054 void SetSyngoDT(unsigned int syngodt) { SyngoDTField = syngodt; } 00055 00057 unsigned int GetNoOfItems() const { return NoOfItemsField; } 00058 void SetNoOfItems(unsigned int items) { NoOfItemsField = items; } 00059 00061 Value const &GetValue() const { return *DataField; } 00062 Value &GetValue() { return *DataField; } 00063 void SetValue(Value const & vl) { 00064 //assert( DataField == 0 ); 00065 DataField = vl; 00066 } 00068 bool IsEmpty() const { return DataField == 0; } 00069 00071 void SetByteValue(const char *array, VL length) 00072 { 00073 ByteValue *bv = new ByteValue(array,length); 00074 SetValue( *bv ); 00075 } 00078 const ByteValue* GetByteValue() const { 00079 // Get the raw pointer from the gdcm::SmartPointer 00080 const ByteValue *bv = dynamic_cast<const ByteValue*>(DataField.GetPointer()); 00081 return bv; // Will return NULL if not ByteValue 00082 } 00083 00084 CSAElement(const CSAElement &_val) 00085 { 00086 if( this != &_val) 00087 { 00088 *this = _val; 00089 } 00090 } 00091 00092 bool operator<(const CSAElement &de) const 00093 { 00094 return GetKey() < de.GetKey(); 00095 } 00096 CSAElement &operator=(const CSAElement &de) 00097 { 00098 KeyField = de.KeyField; 00099 NameField = de.NameField; 00100 ValueMultiplicityField = de.ValueMultiplicityField; 00101 VRField = de.VRField; 00102 SyngoDTField = de.SyngoDTField; 00103 NoOfItemsField = de.NoOfItemsField; 00104 DataField = de.DataField; // Pointer copy 00105 return *this; 00106 } 00107 00108 bool operator==(const CSAElement &de) const 00109 { 00110 return KeyField == de.KeyField 00111 && NameField == de.NameField 00112 && ValueMultiplicityField == de.ValueMultiplicityField 00113 && VRField == de.VRField 00114 && SyngoDTField == de.SyngoDTField 00115 //&& ValueField == de.ValueField; 00116 ; 00117 } 00118 00119 protected: 00120 unsigned int KeyField; 00121 std::string NameField; 00122 VM ValueMultiplicityField; 00123 VR VRField; 00124 unsigned int SyngoDTField; 00125 unsigned int NoOfItemsField; 00126 typedef SmartPointer<Value> DataPtr; 00127 DataPtr DataField; 00128 }; 00129 //----------------------------------------------------------------------------- 00130 inline std::ostream& operator<<(std::ostream &os, const CSAElement &val) 00131 { 00132 os << val.KeyField; 00133 os << " - '" << val.NameField; 00134 os << "' VM " << val.ValueMultiplicityField; 00135 os << ", VR " << val.VRField; 00136 os << ", SyngoDT " << val.SyngoDTField; 00137 os << ", NoOfItems " << val.NoOfItemsField; 00138 os << ", Data "; 00139 if( val.DataField ) 00140 { 00141 //val.DataField->Print( os << "'" ); 00142 const ByteValue * bv = dynamic_cast<ByteValue*>(&*val.DataField); 00143 assert( bv ); 00144 const char * p = bv->GetPointer(); 00145 std::string str(p, p + bv->GetLength() ); 00146 if( val.ValueMultiplicityField == VM::VM1 ) 00147 { 00148 os << "'" << str.c_str() << "'"; 00149 } 00150 else 00151 { 00152 std::istringstream is( str ); 00153 std::string s; 00154 bool sep = false; 00155 while( std::getline(is, s, '\\' ) ) 00156 { 00157 if( sep ) 00158 { 00159 os << '\\'; 00160 } 00161 sep = true; 00162 os << "'" << s.c_str() << "'"; 00163 } 00164 //bv->Print( os << "'" ); 00165 //os << "'"; 00166 } 00167 } 00168 return os; 00169 } 00170 00171 } // end namespace gdcm 00172 00173 #endif //GDCMCSAELEMENT_H