14 #ifndef GDCMATTRIBUTE_H
15 #define GDCMATTRIBUTE_H
19 #include "gdcmTagToType.h"
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;
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
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 >
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 >
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 )
693 std::stringstream ss;
723 template<u
int16_t Group, u
int16_t Element,
int TVR>
730 template<u
int16_t Group, u
int16_t Element,
int TVR>
737 template<u
int16_t Group, u
int16_t Element,
int TVR>
744 template<u
int16_t Group, u
int16_t Element,
int TVR>
751 template<u
int16_t Group, u
int16_t Element,
int TVR>
758 template<u
int16_t Group, u
int16_t Element,
int TVR>
778 const char sep =
'\\';
779 std::string sarray = array;
780 std::string::size_type pos1 = 0;
781 std::string::size_type pos2 = sarray.find(sep, pos1+1);
782 while(pos2 != std::string::npos)
784 Internal[i++] = sarray.substr(pos1, pos2-pos1);
786 pos2 = sarray.find(sep, pos1+1);
788 Internal[i] = sarray.substr(pos1, pos2-pos1);
791 assert( GetLength()-1 == i );
794 unsigned long GetLength()
const {
795 return VMToLength<TVM>::Length;
798 void Print(std::ostream &_os)
const {
800 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
801 _os <<
"," << Internal[i];
804 void Read(std::istream &_is) {
807 void Write(std::ostream &_os)
const {
811 typename String Internal[VMToLength<TVM>::Length];
815 class Attribute<VR::PN, TVM> :
public StringAttribute<TVM>
828 explicit Attribute() { Internal=0; Length=0; }
837 unsigned long GetLength()
const {
return Length; }
838 typedef typename VRToType<TVR>::Type
ArrayType;
839 void SetLength(
unsigned long len) {
840 const unsigned int size =
sizeof(
ArrayType);
844 assert( (len / size) * size == len );
846 memcpy(
internal, Internal, Length * size);
856 void SetArray(
const ArrayType *array,
unsigned long len,
860 memcpy(Internal, array, len);
870 void Print(std::ostream &_os)
const {
874 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
875 for(
unsigned long i=1; i<length; ++i)
876 _os <<
"," << Internal[i];
878 void Read(std::istream &_is) {
882 void Write(std::ostream &_os)
const {
896 SetArray(_val.Internal, _val.Length,
true);
901 typename VRToType<TVR>::Type *
Internal;
902 unsigned long Length;
913 typedef Attribute<TVR, VM::VM1_n> Parent;
914 void SetLength(
int len) {
915 if( len <= 1 )
return;
916 Parent::SetLength(len);
923 typedef Attribute<TVR, VM::VM2_n> Parent;
924 void SetLength(
int len) {
925 if( len % 2 )
return;
926 Parent::SetLength(len);
933 typedef Attribute<TVR, VM::VM1_n> Parent;
934 void SetLength(
int len) {
935 if( len <= 2 )
return;
936 Parent::SetLength(len);
943 typedef Attribute<TVR, VM::VM3_n> Parent;
944 void SetLength(
int len) {
945 if( len % 3 )
return;
946 Parent::SetLength(len);
962 char Internal[VMToLength<VM::VM5>::Length];
963 void Print(std::ostream &_os)
const {
971 template <
int TVM>
class Attribute<VR::OB, TVM>;
977 template <
int TVM>
class Attribute<VR::OW, TVM>;
982 class
Attribute<0x7fe0,0x0010, VR::OW, VM::VM1>
986 unsigned long Length;
988 void Print(std::ostream &_os)
const {
991 void SetBytes(
char *bytes,
unsigned long length) {
995 void Read(std::istream &_is) {
997 _is.read((
char*)&c, 4);
999 _is.read((
char*)&l, 4);
1001 _is.read( Internal, Length );
1003 void Write(std::ostream &_os)
const {
1004 uint16_t c[] = {0x7fe0, 0x0010};
1005 _os.write((
char*)&c, 4);
1006 _os.write((
char*)&Length, 4);
1007 _os.write( Internal, Length );
1050 #endif //GDCMATTRIBUTE_H