14 #ifndef GDCMBYTEVALUE_H
15 #define GDCMBYTEVALUE_H
37 Internal(array, array+vl),Length(vl) {
41 Internal.resize(vl+1);
47 ByteValue(std::vector<char> &v):Internal(v),Length((uint32_t)v.size()) {}
58 void PrintASCII(std::ostream &os,
VL maxlength )
const;
60 void PrintHex(std::ostream &os,
VL maxlength)
const;
64 assert( Length == 2 );
70 if( Internal.empty() ) assert( Length == 0 );
71 return Internal.empty();
82 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
87 "BUGGY HEADER: Your dicom contain odd length value field." );
99 #ifdef SHORT_READ_HACK
108 throw Exception(
"Impossible to allocate" );
114 operator const std::vector<char>& ()
const {
return Internal; }
117 Internal = val.Internal;
123 if( Length != val.Length )
125 if( Internal == val.Internal )
132 return Length == bv.Length && Internal == bv.Internal;
142 if(!Internal.empty())
return &Internal[0];
147 std::vector<char>::iterator it = Internal.begin();
148 for(; it != Internal.end(); ++it) *it = c;
150 bool GetBuffer(
char *buffer,
unsigned long length)
const;
154 assert( !(Internal.size() % 2) );
155 os.write(&Internal[0], Internal.size() );
160 template <
typename TSwap,
typename TType>
161 std::istream &
Read(std::istream &is,
bool readvalues =
true) {
170 is.read(&Internal[0], Length);
171 assert( Internal.size() == Length || Internal.size() == Length + 1 );
172 TSwap::SwapArray((TType*)&Internal[0], Internal.size() /
sizeof(TType) );
176 is.seekg(Length, std::ios::cur);
182 template <
typename TSwap>
183 std::istream &
Read(std::istream &is) {
184 return Read<TSwap,uint8_t>(is);
188 template <
typename TSwap,
typename TType>
189 std::ostream
const &
Write(std::ostream &os)
const {
190 assert( !(Internal.size() % 2) );
191 if( !Internal.empty() ) {
193 std::vector<char> copy = Internal;
194 TSwap::SwapArray((TType*)©[0], Internal.size() /
sizeof(TType) );
195 os.write(©[0], copy.size());
200 template <
typename TSwap>
201 std::ostream
const &
Write(std::ostream &os)
const {
202 return Write<TSwap,uint8_t>(os);
212 assert( length <= Length );
213 for(
unsigned int i=0; i<length; i++)
215 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
216 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
226 void PrintPNXML(std::ostream &os)
const;
227 void PrintASCIIXML(std::ostream &os)
const;
228 void PrintHexXML(std::ostream &os)
const;
230 void Print(std::ostream &os)
const {
233 if( !Internal.empty() )
235 if( IsPrintable(Length) )
238 std::vector<char>::size_type length = Length;
239 if( Internal.back() == 0 ) --length;
240 std::copy(Internal.begin(), Internal.begin()+length,
241 std::ostream_iterator<char>(os));
244 os <<
"Loaded:" << Internal.size();
249 os <<
"(no value available)";
262 std::vector<char> Internal;
272 #endif //GDCMBYTEVALUE_H
ByteValue(std::vector< char > &v)
Definition: gdcmByteValue.h:47
std::istream & Read(std::istream &is, bool readvalues=true)
Definition: gdcmByteValue.h:161
bool IsPrintable(VL length) const
Checks whether a 'ByteValue' is printable or not (in order to avoid corrupting the terminal of invoca...
Definition: gdcmByteValue.h:211
Class to represent the value of a Data Element.
Definition: gdcmValue.h:29
VL GetLength() const
Definition: gdcmByteValue.h:76
~ByteValue()
Definition: gdcmByteValue.h:52
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:189
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
bool operator==(const ByteValue &val) const
Definition: gdcmByteValue.h:122
void Print(std::ostream &os) const
Definition: gdcmByteValue.h:230
Value Length.
Definition: gdcmVL.h:29
#define gdcmDebugMacro(msg)
Debug.
Definition: gdcmTrace.h:119
ByteValue(const char *array=0, VL const &vl=0)
Definition: gdcmByteValue.h:36
bool IsOdd() const
Return whether or not the VL is odd or not.
Definition: gdcmVL.h:47
void Fill(char c)
Definition: gdcmByteValue.h:145
bool operator==(const Value &val) const
Definition: gdcmByteValue.h:129
Class to represent binary value (array of bytes)
Definition: gdcmByteValue.h:33
void PrintGroupLength(std::ostream &os)
Definition: gdcmByteValue.h:63
bool WriteBuffer(std::ostream &os) const
Definition: gdcmByteValue.h:151
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:201
VL ComputeLength() const
Definition: gdcmByteValue.h:78
void SetLengthOnly(VL vl)
Definition: gdcmByteValue.h:257
std::istream & Read(std::istream &is)
Definition: gdcmByteValue.h:183
bool IsUndefined() const
Definition: gdcmVL.h:39
void Clear()
Definition: gdcmByteValue.h:137
bool IsEmpty() const
Definition: gdcmByteValue.h:68
const char * GetPointer() const
Definition: gdcmByteValue.h:141
Definition: gdcmASN1.h:20
Exception.
Definition: gdcmException.h:43
ByteValue & operator=(const ByteValue &val)
Definition: gdcmByteValue.h:116
void SetLength(VL vl)
Definition: gdcmByteValue.h:80