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 );
69 if( Internal.empty() ) assert( Length == 0 );
70 return Internal.empty();
76 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
81 "BUGGY HEADER: Your dicom contain odd length value field." );
93 #ifdef SHORT_READ_HACK
102 throw Exception(
"Impossible to allocate" );
108 operator const std::vector<char>& ()
const {
return Internal; }
111 Internal = val.Internal;
117 if( Length != val.Length )
119 if( Internal == val.Internal )
126 return Length == bv.Length && Internal == bv.Internal;
135 if(!Internal.empty())
return &Internal[0];
140 std::vector<char>::iterator it = Internal.begin();
141 for(; it != Internal.end(); ++it) *it = c;
143 bool GetBuffer(
char *buffer,
unsigned long length)
const;
147 assert( !(Internal.size() % 2) );
148 os.write(&Internal[0], Internal.size() );
153 template <
typename TSwap,
typename TType>
154 std::istream &
Read(std::istream &is) {
161 is.read(&Internal[0], Length);
162 assert( Internal.size() == Length || Internal.size() == Length + 1 );
163 TSwap::SwapArray((TType*)&Internal[0], Internal.size() /
sizeof(TType) );
168 template <
typename TSwap>
169 std::istream &
Read(std::istream &is) {
170 return Read<TSwap,uint8_t>(is);
174 template <
typename TSwap,
typename TType>
175 std::ostream
const &
Write(std::ostream &os)
const {
176 assert( !(Internal.size() % 2) );
177 if( !Internal.empty() ) {
179 std::vector<char> copy = Internal;
180 TSwap::SwapArray((TType*)©[0], Internal.size() /
sizeof(TType) );
181 os.write(©[0], copy.size());
186 template <
typename TSwap>
187 std::ostream
const &
Write(std::ostream &os)
const {
188 return Write<TSwap,uint8_t>(os);
198 assert( length <= Length );
199 for(
unsigned int i=0; i<length; i++)
201 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
202 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
212 void Print(std::ostream &os)
const {
215 if( !Internal.empty() )
217 if( IsPrintable(Length) )
220 std::vector<char>::size_type length = Length;
221 if( Internal.back() == 0 ) --length;
222 std::copy(Internal.begin(), Internal.begin()+length,
223 std::ostream_iterator<char>(os));
226 os <<
"Loaded:" << Internal.size();
231 os <<
"(no value available)";
237 std::vector<char> Internal;
247 #endif //GDCMBYTEVALUE_H
ByteValue(std::vector< char > &v)
Definition: gdcmByteValue.h:47
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:197
Class to represent the value of a Data Element.
Definition: gdcmValue.h:29
VL GetLength() const
Definition: gdcmByteValue.h:72
~ByteValue()
Definition: gdcmByteValue.h:52
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:175
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
bool operator==(const ByteValue &val) const
Definition: gdcmByteValue.h:116
void Print(std::ostream &os) const
Definition: gdcmByteValue.h:212
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:138
bool operator==(const Value &val) const
Definition: gdcmByteValue.h:123
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:144
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:187
std::istream & Read(std::istream &is)
Definition: gdcmByteValue.h:169
bool IsUndefined() const
Definition: gdcmVL.h:39
void Clear()
Definition: gdcmByteValue.h:130
bool IsEmpty() const
Definition: gdcmByteValue.h:68
const char * GetPointer() const
Definition: gdcmByteValue.h:134
std::istream & Read(std::istream &is)
Definition: gdcmByteValue.h:154
Exception.
Definition: gdcmException.h:33
ByteValue & operator=(const ByteValue &val)
Definition: gdcmByteValue.h:110
void SetLength(VL vl)
Definition: gdcmByteValue.h:74