gdcmVL.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __gdcmVL_h
00016 #define __gdcmVL_h
00017
00018 #include "gdcmTypes.h"
00019
00020 #include <iostream>
00021
00022 namespace gdcm
00023 {
00024
00030 class GDCM_EXPORT VL
00031 {
00032 public:
00033 VL(uint32_t vl = 0) : ValueLength(vl) { }
00034
00035
00036 static uint32_t GetVL32Max() { return 0xFFFFFFFF; }
00037 static uint16_t GetVL16Max() { return 0xFFFF; }
00038
00039 bool IsUndefined() const {
00040 return ValueLength == 0xFFFFFFFF;
00041 }
00042 void SetToUndefined() {
00043 ValueLength = 0xFFFFFFFF;
00044 }
00045
00046 bool IsOdd() const {
00047 return !IsUndefined() && ValueLength % 2;
00048 }
00049
00050 VL& operator+=(VL const &vl) {
00051 ValueLength += vl.ValueLength;
00052 return *this;
00053 }
00054 VL& operator++() {
00055 ++ValueLength;
00056 return *this;
00057 }
00058 VL operator++(int) {
00059 uint32_t tmp(ValueLength);
00060 ++ValueLength;
00061 return tmp;
00062 }
00063
00064 operator uint32_t () const { return ValueLength; }
00065
00066 VL GetLength() const {
00067
00068
00069 return 4;
00070 }
00071
00072 friend std::ostream& operator<<(std::ostream& os, const VL& vl);
00073
00074
00075
00076
00077 template <typename TSwap>
00078 std::istream &Read(std::istream &is)
00079 {
00080 is.read((char*)(&ValueLength), sizeof(uint32_t));
00081 TSwap::SwapArray(&ValueLength,1);
00082 return is;
00083 }
00084
00085 template <typename TSwap>
00086 std::istream &Read16(std::istream &is)
00087 {
00088 uint16_t copy;
00089 is.read((char*)(©), sizeof(uint16_t));
00090 TSwap::SwapArray(©,1);
00091 ValueLength = copy;
00092 assert( ValueLength <= 65535 );
00093 return is;
00094 }
00095
00096 template <typename TSwap>
00097 const std::ostream &Write(std::ostream &os) const
00098 {
00099 uint32_t copy = ValueLength;
00100 #ifndef GDCM_WRITE_ODD_LENGTH
00101 if( IsOdd() )
00102 {
00103 ++copy;
00104 }
00105 #endif
00106 TSwap::SwapArray(©,1);
00107 return os.write((char*)(©), sizeof(uint32_t));
00108 }
00109
00110 template <typename TSwap>
00111 const std::ostream &Write16(std::ostream &os) const
00112 {
00113 assert( ValueLength <= 65535 );
00114 uint16_t copy = ValueLength;
00115 #ifndef GDCM_WRITE_ODD_LENGTH
00116 if( IsOdd() )
00117 {
00118 ++copy;
00119 }
00120 #endif
00121 TSwap::SwapArray(©,1);
00122 return os.write((char*)(©), sizeof(uint16_t));
00123 }
00124
00125 private:
00126 uint32_t ValueLength;
00127 };
00128
00129 inline std::ostream& operator<<(std::ostream& os, const VL& val)
00130 {
00131 os << val.ValueLength;
00132 return os;
00133 }
00134
00135 }
00136
00137 #endif //__gdcmVL_h