51 template <
int TVR,
int TVM>
68 template<int TVR, int TVM>
85 void Print(std::ostream &_os)
const {
87 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
88 _os <<
"," << Internal[i];
100 return Internal[idx];
103 return GetValue(idx);
113 #ifdef GDCM_WORDS_BIGENDIAN
129 std::ostringstream os;
138 if( os.str().size() % 2 )
154 void Write(std::ostream &_os)
const {
165 std::stringstream ss;
177 std::stringstream ss;
193 in.clear(in.rdstate() & ~std::ios_base::failbit);
194 if (in.get() != ic.
m_char)
195 in.setstate(std::ios_base::failbit);
212 while( _is >> data[length++] )
217 assert( sep ==
'\\' || sep ==
' ' );
218 if( sep ==
' ' ) length--;
221 while( _is >> std::ws >> data[length++] >> std::ws >>
backslash )
228 static inline void Read(T* data,
unsigned long length,
235 _is >> std::ws >> data[0];
238 for(
unsigned long i=1; i<length;++i) {
241 _is >> std::ws >> sep;
242 assert( sep ==
'\\' );
243 _is >> std::ws >> data[i];
250 Read(data,length,_is);
253 static inline void Write(
const T* data,
unsigned long length,
259 for(
unsigned long i=1; i<length; ++i) {
261 _os <<
"\\" << data[i];
266 template <
typename Float >
268 std::stringstream in;
272 - std::log( std::numeric_limits<Float>::epsilon() )
273 / std::log( 10.0 ) );
274 if ( in << std::dec << std::setprecision(digits) << data ) {
277 throw "Impossible Conversion";
288 for(
unsigned long i=1; i<length; ++i) {
299 for(
unsigned long i=1; i<length; ++i) {
316 const unsigned int type_size =
sizeof(T);
321 _is.read( reinterpret_cast<char*>(data+0), type_size);
322 for(
unsigned long i=1; i<length; ++i) {
324 _is.read( reinterpret_cast<char*>(data+i), type_size );
330 const unsigned int type_size =
sizeof(T);
334 _is.read( reinterpret_cast<char*>(data+0), type_size);
335 for(
unsigned long i=1; i<length; ++i) {
337 _is.read( reinterpret_cast<char*>(data+i), type_size );
344 static inline void Read(T* data,
unsigned long length,
346 const unsigned int type_size =
sizeof(T);
350 _is.read( reinterpret_cast<char*>(data+0), type_size);
351 for(
unsigned long i=1; i<length; ++i) {
353 _is.read( reinterpret_cast<char*>(data+i), type_size );
360 static inline void Write(
const T* data,
unsigned long length,
362 const unsigned int type_size =
sizeof(T);
369 _os.write( reinterpret_cast<const char*>(&swappedData), type_size);
370 for(
unsigned long i=1; i<length;++i) {
373 _os.write( reinterpret_cast<const char*>(&swappedData), type_size );
389 Element(
const char array[])
392 const char sep =
'\\';
393 std::string sarray = array;
394 std::string::size_type pos1 = 0;
395 std::string::size_type pos2 = sarray.find(sep, pos1+1);
396 while(pos2 != std::string::npos)
398 Internal[i++] = sarray.substr(pos1, pos2-pos1);
400 pos2 = sarray.find(sep, pos1+1);
402 Internal[i] = sarray.substr(pos1, pos2-pos1);
405 assert( GetLength()-1 == i );
408 unsigned long GetLength()
const {
409 return VMToLength<TVM>::Length;
412 void Print(std::ostream &_os)
const {
414 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
415 _os <<
"," << Internal[i];
418 void Read(std::istream &_is) {
421 void Write(std::ostream &_os)
const {
425 typename String Internal[VMToLength<TVM>::Length];
429 class Element<VR::PN, TVM> :
public StringElement<TVM>
431 enum { ElementDisableCombinationsCheck =
sizeof ( ElementDisableCombinations<VR::PN, TVM> ) };
442 explicit Element() { Internal=0; Length=0; Save =
false; }
460 const unsigned int size =
sizeof(Type);
464 assert( (len / size) * size == len );
465 Type *
internal =
new Type[len / size];
466 assert( Save ==
false );
470 memcpy(
internal, Internal, len);
481 void SetArray(
const Type *array,
unsigned long len,
485 memcpy(Internal, array, len);
486 assert( Save ==
false );
490 assert( Length == 0 );
491 assert( Internal == 0 );
492 assert( Save ==
false );
493 Length = len /
sizeof(Type);
497 if( (len /
sizeof(Type)) *
sizeof(Type) != len ) { Internal = 0; Length = 0; }
498 else Internal =
const_cast<Type*
>(array);
503 assert( idx < Length );
507 assert( idx < Length );
508 return Internal[idx];
511 assert( idx < Length );
512 return Internal[idx];
515 return GetValue(idx);
525 assert( Internal == 0 );
530 std::stringstream ss;
540 #ifdef GDCM_WORDS_BIGENDIAN
561 void Print(std::ostream &_os)
const {
565 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
566 for(
unsigned long i=1; i<length; ++i)
567 _os <<
"," << Internal[i];
570 if( !Internal )
return;
579 void Write(std::ostream &_os)
const {
590 std::ostringstream os;
597 if( os.str().size() % 2 )
618 SetArray(_val.Internal, _val.Length,
true);
630 assert( Internal == 0 );
635 std::stringstream ss;
645 unsigned long Length;
659 if( len != 1 || len != 2 )
return;
660 Parent::SetLength(len);
670 if( len <= 1 )
return;
671 Parent::SetLength(len);
681 if( len % 2 )
return;
682 Parent::SetLength(len);
692 if( len <= 2 )
return;
693 Parent::SetLength(len);
703 if( len % 3 )
return;
704 Parent::SetLength(len);
722 void Print(std::ostream &_os)
const {
741 #endif //GDCMELEMENT_H