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;
141 if(!Internal.empty())
return &Internal[0];
146 std::vector<char>::iterator it = Internal.begin();
147 for(; it != Internal.end(); ++it) *it = c;
149 bool GetBuffer(
char *buffer,
unsigned long length)
const;
153 assert( !(Internal.size() % 2) );
154 os.write(&Internal[0], Internal.size() );
159 template <
typename TSwap,
typename TType>
160 std::istream &
Read(std::istream &is,
bool readvalues =
true) {
169 is.read(&Internal[0], Length);
170 assert( Internal.size() == Length || Internal.size() == Length + 1 );
171 TSwap::SwapArray((TType*)&Internal[0], Internal.size() /
sizeof(TType) );
175 is.seekg(Length, std::ios::cur);
181 template <
typename TSwap>
182 std::istream &
Read(std::istream &is) {
183 return Read<TSwap,uint8_t>(is);
187 template <
typename TSwap,
typename TType>
188 std::ostream
const &
Write(std::ostream &os)
const {
189 assert( !(Internal.size() % 2) );
190 if( !Internal.empty() ) {
192 std::vector<char> copy = Internal;
193 TSwap::SwapArray((TType*)©[0], Internal.size() /
sizeof(TType) );
194 os.write(©[0], copy.size());
199 template <
typename TSwap>
200 std::ostream
const &
Write(std::ostream &os)
const {
201 return Write<TSwap,uint8_t>(os);
211 assert( length <= Length );
212 for(
unsigned int i=0; i<length; i++)
214 if ( i == (length-1) && Internal[i] ==
'\0')
continue;
215 if ( !( isprint((
unsigned char)Internal[i]) || isspace((
unsigned char)Internal[i]) ) )
225 void PrintPNXML(std::ostream &os)
const;
226 void PrintASCIIXML(std::ostream &os)
const;
227 void PrintHexXML(std::ostream &os)
const;
229 void Print(std::ostream &os)
const {
232 if( !Internal.empty() )
234 if( IsPrintable(Length) )
237 std::vector<char>::size_type length = Length;
238 if( Internal.back() == 0 ) --length;
239 std::copy(Internal.begin(), Internal.begin()+length,
240 std::ostream_iterator<char>(os));
243 os <<
"Loaded:" << Internal.size();
248 os <<
"(no value available)";
261 std::vector<char> Internal;
271 #endif //GDCMBYTEVALUE_H