14 #ifndef GDCMATTRIBUTE_H
15 #define GDCMATTRIBUTE_H
19 #include "gdcmTagToType.h"
36 template<
int T>
class VRVLSize;
39 template<>
class VRVLSize<0> {
41 static inline uint16_t
Read(std::istream &_is) {
43 _is.read((
char*)&l, 2);
47 static inline void Write(std::ostream &os) { (void)os;
51 template<>
class VRVLSize<1> {
53 static inline uint32_t
Read(std::istream &_is) {
58 _is.read((
char*)&l, 4);
62 static inline void Write(std::ostream &os) { (void)os;
81 template<uint16_t Group, uint16_t Element,
82 int TVR = TagToType<Group, Element>::VRType,
83 int TVM = TagToType<Group, Element>::VMType
89 enum {
VMType = VMToLength<TVM>::Length };
112 return VMToLength<TVM>::Length;
117 void Print(std::ostream &os)
const {
119 os << TagToType<Group,Element>::GetVRString() <<
" ";
120 os << TagToType<Group,Element>::GetVMString() <<
" ";
123 os <<
"," << Internal[i];
176 std::copy(array, array+numel,
Internal);
185 std::ostringstream os;
195 if( os.str().size() % 2 )
213 #ifdef GDCM_WORDS_BIGENDIAN
247 std::stringstream ss;
264 std::stringstream ss;
271 #if 0 // TODO FIXME the implicit way:
273 void Read(std::istream &_is) {
274 const uint16_t cref[] = { Group,
Element };
276 _is.read((
char*)&c,
sizeof(c));
277 assert( c[0] == cref[0] && c[1] == cref[1] );
280 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
281 uint32_t l = VRVLSize< (TVR & VR::VL32) >::Read(_is);
282 l /=
sizeof(
typename VRToType<TVR>::Type );
286 void Write(std::ostream &_os)
const {
287 uint16_t c[] = { Group, Element };
288 _os.write((
char*)&c, 4);
289 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
290 _os.write((
char*)&l, 4);
294 void Read(std::istream &_is) {
295 uint16_t cref[] = { Group, Element };
297 _is.read((
char*)&c, 4);
298 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
300 _is.read((
char*)&l, 4);
301 l /=
sizeof(
typename VRToType<TVR>::Type );
305 void Write(std::ostream &_os)
const {
306 uint16_t c[] = { Group, Element };
307 _os.write((
char*)&c, 4);
308 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
309 _os.write((
char*)&l, 4);
317 template<u
int16_t Group, u
int16_t Element,
int TVR >
322 enum {
VMType = VMToLength<VM::VM1>::Length };
347 return VMToLength<VM::VM1>::Length;
352 void Print(std::ostream &os)
const {
354 os << TagToType<Group,Element>::GetVRString() <<
" ";
355 os << TagToType<Group,Element>::GetVMString() <<
" ";
420 std::ostringstream os;
430 if( os.str().size() % 2 )
448 #ifdef GDCM_WORDS_BIGENDIAN
482 std::stringstream ss;
499 std::stringstream ss;
506 #if 0 // TODO FIXME the implicit way:
508 void Read(std::istream &_is) {
509 const uint16_t cref[] = { Group,
Element };
511 _is.read((
char*)&c,
sizeof(c));
512 assert( c[0] == cref[0] && c[1] == cref[1] );
515 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
516 uint32_t l = VRVLSize< (TVR & VR::VL32) >::Read(_is);
517 l /=
sizeof(
typename VRToType<TVR>::Type );
521 void Write(std::ostream &_os)
const {
522 uint16_t c[] = { Group, Element };
523 _os.write((
char*)&c, 4);
524 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
525 _os.write((
char*)&l, 4);
529 void Read(std::istream &_is) {
530 uint16_t cref[] = { Group, Element };
532 _is.read((
char*)&c, 4);
533 const uint32_t lref = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
535 _is.read((
char*)&l, 4);
536 l /=
sizeof(
typename VRToType<TVR>::Type );
540 void Write(std::ostream &_os)
const {
541 uint16_t c[] = { Group, Element };
542 _os.write((
char*)&c, 4);
543 uint32_t l = GetLength() *
sizeof(
typename VRToType<TVR>::Type );
544 _os.write((
char*)&l, 4);
554 template<u
int16_t Group, u
int16_t Element,
int TVR >
584 void SetNumberOfValues(
unsigned int numel)
592 void Print(std::ostream &os)
const {
594 os <<
GetVR() <<
" ";
595 os <<
GetVM() <<
" ";
598 os <<
"," << Internal[i];
637 std::copy(array, array+numel,
Internal);
649 std::ostringstream os;
658 if( os.str().size() % 2 )
682 std::stringstream ss;
712 template<u
int16_t Group, u
int16_t Element,
int TVR>
719 template<u
int16_t Group, u
int16_t Element,
int TVR>
726 template<u
int16_t Group, u
int16_t Element,
int TVR>
733 template<u
int16_t Group, u
int16_t Element,
int TVR>
740 template<u
int16_t Group, u
int16_t Element,
int TVR>
747 template<u
int16_t Group, u
int16_t Element,
int TVR>
767 const char sep =
'\\';
768 std::string sarray = array;
769 std::string::size_type pos1 = 0;
770 std::string::size_type pos2 = sarray.find(sep, pos1+1);
771 while(pos2 != std::string::npos)
773 Internal[i++] = sarray.substr(pos1, pos2-pos1);
775 pos2 = sarray.find(sep, pos1+1);
777 Internal[i] = sarray.substr(pos1, pos2-pos1);
780 assert( GetLength()-1 == i );
783 unsigned long GetLength()
const {
784 return VMToLength<TVM>::Length;
787 void Print(std::ostream &_os)
const {
789 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
790 _os <<
"," << Internal[i];
793 void Read(std::istream &_is) {
796 void Write(std::ostream &_os)
const {
800 typename String Internal[VMToLength<TVM>::Length];
804 class Attribute<VR::PN, TVM> :
public StringAttribute<TVM>
817 explicit Attribute() { Internal=0; Length=0; }
826 unsigned long GetLength()
const {
return Length; }
827 typedef typename VRToType<TVR>::Type
ArrayType;
828 void SetLength(
unsigned long len) {
829 const unsigned int size =
sizeof(
ArrayType);
833 assert( (len / size) * size == len );
835 memcpy(
internal, Internal, Length * size);
845 void SetArray(
const ArrayType *array,
unsigned long len,
849 memcpy(Internal, array, len);
859 void Print(std::ostream &_os)
const {
863 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
864 for(
unsigned long i=1; i<length; ++i)
865 _os <<
"," << Internal[i];
867 void Read(std::istream &_is) {
871 void Write(std::ostream &_os)
const {
885 SetArray(_val.Internal, _val.Length,
true);
890 typename VRToType<TVR>::Type *
Internal;
891 unsigned long Length;
902 typedef Attribute<TVR, VM::VM1_n> Parent;
903 void SetLength(
int len) {
904 if( len <= 1 )
return;
905 Parent::SetLength(len);
912 typedef Attribute<TVR, VM::VM2_n> Parent;
913 void SetLength(
int len) {
914 if( len % 2 )
return;
915 Parent::SetLength(len);
922 typedef Attribute<TVR, VM::VM1_n> Parent;
923 void SetLength(
int len) {
924 if( len <= 2 )
return;
925 Parent::SetLength(len);
932 typedef Attribute<TVR, VM::VM3_n> Parent;
933 void SetLength(
int len) {
934 if( len % 3 )
return;
935 Parent::SetLength(len);
951 char Internal[VMToLength<VM::VM5>::Length];
952 void Print(std::ostream &_os)
const {
960 template <
int TVM>
class Attribute<VR::OB, TVM>;
966 template <
int TVM>
class Attribute<VR::OW, TVM>;
971 class
Attribute<0x7fe0,0x0010, VR::OW, VM::VM1>
975 unsigned long Length;
977 void Print(std::ostream &_os)
const {
980 void SetBytes(
char *bytes,
unsigned long length) {
984 void Read(std::istream &_is) {
986 _is.read((
char*)&c, 4);
988 _is.read((
char*)&l, 4);
990 _is.read( Internal, Length );
992 void Write(std::ostream &_os)
const {
993 uint16_t c[] = {0x7fe0, 0x0010};
994 _os.write((
char*)&c, 4);
995 _os.write((
char*)&Length, 4);
996 _os.write( Internal, Length );
1039 #endif //GDCMATTRIBUTE_H