41 template<
int T>
class EncodingImplementation;
48 template<
int TVR,
int TVM>
52 typename VRToType<TVR>::Type
Internal[VMToLength<TVM>::Length];
53 typedef typename VRToType<TVR>::Type
Type;
59 return VMToLength<TVM>::Length;
64 void Print(std::ostream &_os)
const {
66 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
67 _os <<
"," << Internal[i];
70 const typename VRToType<TVR>::Type *
GetValues()
const {
73 const typename VRToType<TVR>::Type &
GetValue(
unsigned int idx = 0)
const {
74 assert( idx < VMToLength<TVM>::Length );
77 typename VRToType<TVR>::Type &
GetValue(
unsigned int idx = 0) {
78 assert( idx < VMToLength<TVM>::Length );
81 typename VRToType<TVR>::Type
operator[] (
unsigned int idx)
const {
84 void SetValue(
typename VRToType<TVR>::Type v,
unsigned int idx = 0) {
85 assert( idx < VMToLength<TVM>::Length );
92 #ifdef GDCM_WORDS_BIGENDIAN
108 std::ostringstream os;
117 if( os.str().size() % 2 )
133 void Write(std::ostream &_os)
const {
144 std::stringstream ss;
156 std::stringstream ss;
172 in.clear(in.rdstate() & ~std::ios_base::failbit);
173 if (in.get() != ic.
m_char)
174 in.setstate(std::ios_base::failbit);
180 template<>
class EncodingImplementation<
VR::VRASCII> {
183 static inline void ReadComputeLength(T* data,
unsigned int &length,
191 while( _is >> data[length++] )
196 assert( sep ==
'\\' || sep ==
' ' );
197 if( sep ==
' ' ) length--;
200 while( _is >> std::ws >> data[length++] >> std::ws >>
backslash )
207 static inline void Read(T* data,
unsigned long length,
214 _is >> std::ws >> data[0];
217 for(
unsigned long i=1; i<length;++i) {
220 _is >> std::ws >> sep;
221 assert( sep ==
'\\' );
222 _is >> std::ws >> data[i];
227 static inline void ReadNoSwap(T* data,
unsigned long length,
229 Read(data,length,_is);
232 static inline void Write(
const T* data,
unsigned long length,
238 for(
unsigned long i=1; i<length; ++i) {
240 _os <<
"\\" << data[i];
245 template <
typename Float >
247 std::stringstream in;
249 unsigned long const digits =
250 static_cast< unsigned long >(
251 - std::log( std::numeric_limits<Float>::epsilon() )
252 / std::log( 10.0 ) );
253 if ( in << std::dec << std::setprecision(digits) << data ) {
256 throw "Impossible Conversion";
267 for(
unsigned long i=1; i<length; ++i) {
278 for(
unsigned long i=1; i<length; ++i) {
293 static inline void ReadComputeLength(T* data,
unsigned int &length,
295 const unsigned int type_size =
sizeof(T);
300 _is.read( reinterpret_cast<char*>(data+0), type_size);
301 for(
unsigned long i=1; i<length; ++i) {
303 _is.read( reinterpret_cast<char*>(data+i), type_size );
307 static inline void ReadNoSwap(T* data,
unsigned long length,
309 const unsigned int type_size =
sizeof(T);
313 _is.read( reinterpret_cast<char*>(data+0), type_size);
314 for(
unsigned long i=1; i<length; ++i) {
316 _is.read( reinterpret_cast<char*>(data+i), type_size );
323 static inline void Read(T* data,
unsigned long length,
325 const unsigned int type_size =
sizeof(T);
329 _is.read( reinterpret_cast<char*>(data+0), type_size);
330 for(
unsigned long i=1; i<length; ++i) {
332 _is.read( reinterpret_cast<char*>(data+i), type_size );
339 static inline void Write(
const T* data,
unsigned long length,
341 const unsigned int type_size =
sizeof(T);
348 _os.write( reinterpret_cast<const char*>(&swappedData), type_size);
349 for(
unsigned long i=1; i<length;++i) {
352 _os.write( reinterpret_cast<const char*>(&swappedData), type_size );
368 Element(
const char array[])
371 const char sep =
'\\';
372 std::string sarray = array;
373 std::string::size_type pos1 = 0;
374 std::string::size_type pos2 = sarray.find(sep, pos1+1);
375 while(pos2 != std::string::npos)
377 Internal[i++] = sarray.substr(pos1, pos2-pos1);
379 pos2 = sarray.find(sep, pos1+1);
381 Internal[i] = sarray.substr(pos1, pos2-pos1);
388 return VMToLength<TVM>::Length;
391 void Print(std::ostream &_os)
const {
393 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
394 _os <<
"," << Internal[i];
397 void Read(std::istream &_is) {
400 void Write(std::ostream &_os)
const {
404 typename String Internal[VMToLength<TVM>::Length];
408 class Element<VR::PN, TVM> :
public StringElement<TVM>
419 explicit Element() { Internal=0; Length=0; Save =
false; }
434 typedef typename VRToType<TVR>::Type
Type;
437 const unsigned int size =
sizeof(
Type);
441 assert( (len / size) * size == len );
442 Type *
internal =
new Type[len / size];
443 assert( Save ==
false );
447 memcpy(
internal, Internal, len);
458 void SetArray(
const Type *array,
unsigned long len,
462 memcpy(Internal, array, len);
463 assert( Save ==
false );
467 assert( Length == 0 );
468 assert( Internal == 0 );
469 assert( Save ==
false );
470 Length = len /
sizeof(
Type);
474 if( (len /
sizeof(
Type)) *
sizeof(
Type) != len ) { Internal = 0; Length = 0; }
475 else Internal =
const_cast<Type*
>(array);
479 void SetValue(
typename VRToType<TVR>::Type v,
unsigned int idx = 0) {
480 assert( idx < Length );
483 const typename VRToType<TVR>::Type &
GetValue(
unsigned int idx = 0)
const {
484 assert( idx < Length );
485 return Internal[idx];
487 typename VRToType<TVR>::Type &
GetValue(
unsigned int idx = 0) {
488 assert( idx < Length );
489 return Internal[idx];
491 typename VRToType<TVR>::Type
operator[] (
unsigned int idx)
const {
502 assert( Internal == 0 );
507 std::stringstream ss;
517 #ifdef GDCM_WORDS_BIGENDIAN
538 void Print(std::ostream &_os)
const {
543 for(
unsigned long i=1; i<length; ++i)
544 _os <<
"," << Internal[i];
547 if( !Internal )
return;
556 void Write(std::ostream &_os)
const {
567 std::ostringstream os;
574 if( os.str().size() % 2 )
595 SetArray(_val.Internal, _val.Length,
true);
607 assert( Internal == 0 );
612 std::stringstream ss;
621 typename VRToType<TVR>::Type *
Internal;
622 unsigned long Length;
636 if( len != 1 || len != 2 )
return;
637 Parent::SetLength(len);
646 if( len <= 1 )
return;
647 Parent::SetLength(len);
656 if( len % 2 )
return;
657 Parent::SetLength(len);
666 if( len <= 2 )
return;
667 Parent::SetLength(len);
676 if( len % 3 )
return;
677 Parent::SetLength(len);
693 char Internal[VMToLength<VM::VM5>::Length *
sizeof( VRToType<VR::AS>::Type )];
694 void Print(std::ostream &_os)
const {
698 return VMToLength<VM::VM5>::Length;
705 template <
int TVM>
class Element<
VR::OB, TVM>;
711 template <
int TVM>
class Element<
VR::OW, TVM>;
715 #endif //GDCMELEMENT_H