Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GDCMFRAGMENT_H
00016 #define GDCMFRAGMENT_H
00017
00018 #include "gdcmDataElement.h"
00019 #include "gdcmByteValue.h"
00020 #include "gdcmSmartPointer.h"
00021 #include "gdcmParseException.h"
00022
00023 namespace gdcm
00024 {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044 class GDCM_EXPORT Fragment : public DataElement
00045 {
00046
00047
00048 public:
00049 Fragment() : DataElement(Tag(0xfffe, 0xe000), 0) {}
00050 friend std::ostream &operator<<(std::ostream &os, const Fragment &val);
00051
00052 VL GetLength() const {
00053 assert( !ValueLengthField.IsUndefined() );
00054 assert( !ValueField || ValueField->GetLength() == ValueLengthField );
00055 return TagField.GetLength() + ValueLengthField.GetLength()
00056 + ValueLengthField;
00057 }
00058
00059 template <typename TSwap>
00060 std::istream &Read(std::istream &is)
00061 {
00062
00063 const Tag itemStart(0xfffe, 0xe000);
00064 const Tag seqDelItem(0xfffe,0xe0dd);
00065 if( !TagField.Read<TSwap>(is) )
00066 {
00067
00068 throw Exception( "Problem" );
00069 return is;
00070 }
00071 if( !ValueLengthField.Read<TSwap>(is) )
00072 {
00073
00074
00075
00076 throw Exception( "Problem" );
00077 return is;
00078 }
00079 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
00080 if( TagField != itemStart && TagField != seqDelItem )
00081 {
00082 throw Exception( "Problem" );
00083 }
00084 #endif
00085
00086 SmartPointer<ByteValue> bv = new ByteValue;
00087 bv->SetLength(ValueLengthField);
00088 if( !bv->Read<TSwap>(is) )
00089 {
00090
00091 gdcmWarningMacro( "Fragment could not be read" );
00092
00093 ValueField = bv;
00094 ParseException pe;
00095 pe.SetLastElement( *this );
00096 throw pe;
00097 return is;
00098 }
00099 ValueField = bv;
00100 return is;
00101 }
00102
00103
00104 template <typename TSwap>
00105 std::ostream &Write(std::ostream &os) const {
00106 const Tag itemStart(0xfffe, 0xe000);
00107 const Tag seqDelItem(0xfffe,0xe0dd);
00108 if( !TagField.Write<TSwap>(os) )
00109 {
00110 assert(0 && "Should not happen");
00111 return os;
00112 }
00113 assert( TagField == itemStart
00114 || TagField == seqDelItem );
00115 const ByteValue *bv = GetByteValue();
00116
00117
00118
00119 if( IsEmpty() )
00120 {
00121
00122 VL zero = 0;
00123 if( !zero.Write<TSwap>(os) )
00124 {
00125 assert(0 && "Should not happen");
00126 return os;
00127 }
00128 }
00129 else
00130 {
00131 assert( ValueLengthField );
00132 if( !ValueLengthField.Write<TSwap>(os) )
00133 {
00134 assert(0 && "Should not happen");
00135 return os;
00136 }
00137 }
00138
00139 if( ValueLengthField && bv )
00140 {
00141
00142 assert( bv );
00143 assert( bv->GetLength() == ValueLengthField );
00144 if( !bv->Write<TSwap>(os) )
00145 {
00146 assert(0 && "Should not happen");
00147 return os;
00148 }
00149 }
00150 return os;
00151 }
00152 };
00153
00154 inline std::ostream &operator<<(std::ostream &os, const Fragment &val)
00155 {
00156 os << "Tag: " << val.TagField;
00157 os << "\tVL: " << val.ValueLengthField;
00158 if( val.ValueField )
00159 {
00160 os << "\t" << *(val.ValueField);
00161 }
00162
00163 return os;
00164 }
00165
00166
00167 }
00168
00169 #endif //GDCMFRAGMENT_H