14#ifndef GDCMBYTEVALUE_H
15#define GDCMBYTEVALUE_H
28#if !defined(SWIGPYTHON) && !defined(SWIGCSHARP) && !defined(SWIGJAVA) && !defined(SWIGPHP)
38 Internal(array, array+vl),Length(vl) {
42 Internal.resize(vl+1);
48 ByteValue(std::vector<char> &v):Internal(v),Length((uint32_t)v.size()) {}
65 assert( Length == 2 );
71 if( Internal.empty() ) assert( Length == 0 );
72 return Internal.empty();
83 operator const std::vector<char>& ()
const {
return Internal; }
86 Internal = val.Internal;
92 if( Length != val.Length )
94 if( Internal == val.Internal )
101 return Length == bv.Length && Internal == bv.Internal;
111 if(!Internal.empty())
return &Internal[0];
116 if(!Internal.empty())
return &Internal[0];
120 if(!Internal.empty())
return &Internal[0];
125 std::vector<char>::iterator it = Internal.begin();
126 for(; it != Internal.end(); ++it) *it = c;
128 bool GetBuffer(
char *buffer,
unsigned long length)
const;
132 assert( !(Internal.size() % 2) );
133 os.write(&Internal[0], Internal.size() );
138 template <
typename TSwap,
typename TType>
139 std::istream &
Read(std::istream &is,
bool readvalues =
true) {
148 is.read(&Internal[0], Length);
149 assert( Internal.size() == Length || Internal.size() == Length + 1 );
150 TSwap::SwapArray((TType*)GetVoidPointer(), Internal.size() /
sizeof(TType) );
154 is.seekg(Length, std::ios::cur);
160 template <
typename TSwap>
161 std::istream &
Read(std::istream &is) {
162 return Read<TSwap,uint8_t>(is);
166 template <
typename TSwap,
typename TType>
167 std::ostream
const &
Write(std::ostream &os)
const {
168 assert( !(Internal.size() % 2) );
169 if( !Internal.empty() ) {
171 std::vector<char> copy = Internal;
172 TSwap::SwapArray((TType*)(
void*)©[0], Internal.size() /
sizeof(TType) );
173 os.write(©[0], copy.size());
178 template <
typename TSwap>
179 std::ostream
const &
Write(std::ostream &os)
const {
180 return Write<TSwap,uint8_t>(os);
190 assert( length <= Length );
191 for(
unsigned int i=0; i<length; i++)
193 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
194 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
208 void Print(std::ostream &os)
const override {
211 if( !Internal.empty() )
213 if( IsPrintable(Length) )
216 std::vector<char>::size_type length = Length;
217 if( Internal.back() == 0 ) --length;
218 std::copy(Internal.begin(), Internal.begin()+length,
219 std::ostream_iterator<char>(os));
222 os <<
"Loaded:" << Internal.size();
227 os <<
"(no value available)";
240 std::vector<char> Internal;
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
bool operator==(const ByteValue &val) const
Definition gdcmByteValue.h:91
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:189
void Append(ByteValue const &bv)
ByteValue & operator=(const ByteValue &val)
Definition gdcmByteValue.h:85
std::istream & Read(std::istream &is, bool readvalues=true)
Definition gdcmByteValue.h:139
void SetLengthOnly(VL vl) override
Definition gdcmByteValue.h:235
bool operator==(const Value &val) const override
Definition gdcmByteValue.h:98
bool IsEmpty() const
Definition gdcmByteValue.h:69
const void * GetVoidPointer() const
Definition gdcmByteValue.h:115
std::ostream const & Write(std::ostream &os) const
Definition gdcmByteValue.h:179
void SetLength(VL vl) override
std::istream & Read(std::istream &is)
Definition gdcmByteValue.h:161
bool GetBuffer(char *buffer, unsigned long length) const
std::ostream const & Write(std::ostream &os) const
Definition gdcmByteValue.h:167
void PrintGroupLength(std::ostream &os)
Definition gdcmByteValue.h:64
void PrintPNXML(std::ostream &os) const
void PrintASCIIXML(std::ostream &os) const
void Fill(char c)
Definition gdcmByteValue.h:123
bool WriteBuffer(std::ostream &os) const
Definition gdcmByteValue.h:129
const char * GetPointer() const
Definition gdcmByteValue.h:110
void PrintHexXML(std::ostream &os) const
void Clear() override
Definition gdcmByteValue.h:106
ByteValue(const char *array=nullptr, VL const &vl=0)
Definition gdcmByteValue.h:37
VL ComputeLength() const
Definition gdcmByteValue.h:79
void Print(std::ostream &os) const override
Definition gdcmByteValue.h:208
void * GetVoidPointer()
Definition gdcmByteValue.h:119
VL GetLength() const override
Definition gdcmByteValue.h:77
void PrintHex(std::ostream &os, VL maxlength) const
~ByteValue() override
Definition gdcmByteValue.h:53
void PrintASCII(std::ostream &os, VL maxlength) const
ByteValue(std::vector< char > &v)
Definition gdcmByteValue.h:48
Value Length.
Definition gdcmVL.h:30
Class to represent the value of a Data Element.
Definition gdcmValue.h:32
#define gdcmDebugMacro(msg)
Debug.
Definition gdcmTrace.h:119
#define GDCM_EXPORT
Definition gdcmWin32.h:34