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();
80 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
85 "BUGGY HEADER: Your dicom contain odd length value field." );
97 #ifdef SHORT_READ_HACK
106 throw Exception(
"Impossible to allocate" );
112 operator const std::vector<char>& ()
const {
return Internal; }
115 Internal = val.Internal;
121 if( Length != val.Length )
123 if( Internal == val.Internal )
130 return Length == bv.Length && Internal == bv.Internal;
139 if(!Internal.empty())
return &Internal[0];
144 std::vector<char>::iterator it = Internal.begin();
145 for(; it != Internal.end(); ++it) *it = c;
147 bool GetBuffer(
char *buffer,
unsigned long length)
const;
151 assert( !(Internal.size() % 2) );
152 os.write(&Internal[0], Internal.size() );
157 template <
typename TSwap,
typename TType>
158 std::istream &
Read(std::istream &is,
bool readvalues =
true) {
167 is.read(&Internal[0], Length);
168 assert( Internal.size() == Length || Internal.size() == Length + 1 );
169 TSwap::SwapArray((TType*)&Internal[0], Internal.size() /
sizeof(TType) );
173 is.seekg(Length, std::ios::cur);
179 template <
typename TSwap>
180 std::istream &
Read(std::istream &is) {
181 return Read<TSwap,uint8_t>(is);
185 template <
typename TSwap,
typename TType>
186 std::ostream
const &
Write(std::ostream &os)
const {
187 assert( !(Internal.size() % 2) );
188 if( !Internal.empty() ) {
190 std::vector<char> copy = Internal;
191 TSwap::SwapArray((TType*)©[0], Internal.size() /
sizeof(TType) );
192 os.write(©[0], copy.size());
197 template <
typename TSwap>
198 std::ostream
const &
Write(std::ostream &os)
const {
199 return Write<TSwap,uint8_t>(os);
209 assert( length <= Length );
210 for(
unsigned int i=0; i<length; i++)
212 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
213 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
223 void Print(std::ostream &os)
const {
226 if( !Internal.empty() )
228 if( IsPrintable(Length) )
231 std::vector<char>::size_type length = Length;
232 if( Internal.back() == 0 ) --length;
233 std::copy(Internal.begin(), Internal.begin()+length,
234 std::ostream_iterator<char>(os));
237 os <<
"Loaded:" << Internal.size();
242 os <<
"(no value available)";
251 std::vector<char> Internal;
261 #endif //GDCMBYTEVALUE_H
ByteValue(std::vector< char > &v)
Definition: gdcmByteValue.h:47
std::istream & Read(std::istream &is, bool readvalues=true)
Definition: gdcmByteValue.h:158
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:208
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:186
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
bool operator==(const ByteValue &val) const
Definition: gdcmByteValue.h:120
void Print(std::ostream &os) const
Definition: gdcmByteValue.h:223
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:142
bool operator==(const Value &val) const
Definition: gdcmByteValue.h:127
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:148
std::ostream const & Write(std::ostream &os) const
Definition: gdcmByteValue.h:198
void SetLengthOnly(VL vl)
Definition: gdcmByteValue.h:246
std::istream & Read(std::istream &is)
Definition: gdcmByteValue.h:180
bool IsUndefined() const
Definition: gdcmVL.h:39
void Clear()
Definition: gdcmByteValue.h:134
bool IsEmpty() const
Definition: gdcmByteValue.h:68
const char * GetPointer() const
Definition: gdcmByteValue.h:138
Exception.
Definition: gdcmException.h:33
ByteValue & operator=(const ByteValue &val)
Definition: gdcmByteValue.h:114
void SetLength(VL vl)
Definition: gdcmByteValue.h:78