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] );
286 void Write(std::ostream &_os)
const {
287 uint16_t c[] = { Group, Element };
288 _os.write((
char*)&c, 4);
290 _os.write((
char*)&l, 4);
294 void Read(std::istream &_is) {
295 uint16_t cref[] = { Group, Element };
297 _is.read((
char*)&c, 4);
300 _is.read((
char*)&l, 4);
305 void Write(std::ostream &_os)
const {
306 uint16_t c[] = { Group, Element };
307 _os.write((
char*)&c, 4);
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] );
521 void Write(std::ostream &_os)
const {
522 uint16_t c[] = { Group, Element };
523 _os.write((
char*)&c, 4);
525 _os.write((
char*)&l, 4);
529 void Read(std::istream &_is) {
530 uint16_t cref[] = { Group, Element };
532 _is.read((
char*)&c, 4);
535 _is.read((
char*)&l, 4);
540 void Write(std::ostream &_os)
const {
541 uint16_t c[] = { Group, Element };
542 _os.write((
char*)&c, 4);
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 )
683 std::stringstream ss;
713 template<u
int16_t Group, u
int16_t Element,
int TVR>
720 template<u
int16_t Group, u
int16_t Element,
int TVR>
727 template<u
int16_t Group, u
int16_t Element,
int TVR>
734 template<u
int16_t Group, u
int16_t Element,
int TVR>
741 template<u
int16_t Group, u
int16_t Element,
int TVR>
748 template<u
int16_t Group, u
int16_t Element,
int TVR>
768 const char sep =
'\\';
769 std::string sarray = array;
770 std::string::size_type pos1 = 0;
771 std::string::size_type pos2 = sarray.find(sep, pos1+1);
772 while(pos2 != std::string::npos)
774 Internal[i++] = sarray.substr(pos1, pos2-pos1);
776 pos2 = sarray.find(sep, pos1+1);
778 Internal[i] = sarray.substr(pos1, pos2-pos1);
781 assert( GetLength()-1 == i );
784 unsigned long GetLength()
const {
788 void Print(std::ostream &_os)
const {
790 for(
int i=1; i<VMToLength<TVM>::Length; ++i)
791 _os <<
"," << Internal[i];
794 void Read(std::istream &_is) {
797 void Write(std::ostream &_os)
const {
805 class Attribute<VR::PN, TVM> :
public StringAttribute<TVM>
818 explicit Attribute() { Internal=0; Length=0; }
827 unsigned long GetLength()
const {
return Length; }
829 void SetLength(
unsigned long len) {
830 const unsigned int size =
sizeof(
ArrayType);
834 assert( (len / size) * size == len );
836 memcpy(
internal, Internal, Length * size);
846 void SetArray(
const ArrayType *array,
unsigned long len,
850 memcpy(Internal, array, len);
860 void Print(std::ostream &_os)
const {
864 const unsigned long length = GetLength() < 25 ? GetLength() : 25;
865 for(
unsigned long i=1; i<length; ++i)
866 _os <<
"," << Internal[i];
868 void Read(std::istream &_is) {
872 void Write(std::ostream &_os)
const {
886 SetArray(_val.Internal, _val.Length,
true);
892 unsigned long Length;
903 typedef Attribute<TVR, VM::VM1_n> Parent;
904 void SetLength(
int len) {
905 if( len <= 1 )
return;
906 Parent::SetLength(len);
913 typedef Attribute<TVR, VM::VM2_n> Parent;
914 void SetLength(
int len) {
915 if( len % 2 )
return;
916 Parent::SetLength(len);
923 typedef Attribute<TVR, VM::VM1_n> Parent;
924 void SetLength(
int len) {
925 if( len <= 2 )
return;
926 Parent::SetLength(len);
933 typedef Attribute<TVR, VM::VM3_n> Parent;
934 void SetLength(
int len) {
935 if( len % 3 )
return;
936 Parent::SetLength(len);
953 void Print(std::ostream &_os)
const {
961 template <
int TVM>
class Attribute<VR::OB, TVM>;
967 template <
int TVM>
class Attribute<VR::OW, TVM>;
972 class
Attribute<0x7fe0,0x0010, VR::OW, VM::VM1>
976 unsigned long Length;
978 void Print(std::ostream &_os)
const {
981 void SetBytes(
char *bytes,
unsigned long length) {
985 void Read(std::istream &_is) {
987 _is.read((
char*)&c, 4);
989 _is.read((
char*)&l, 4);
991 _is.read( Internal, Length );
993 void Write(std::ostream &_os)
const {
994 uint16_t c[] = {0x7fe0, 0x0010};
995 _os.write((
char*)&c, 4);
996 _os.write((
char*)&Length, 4);
997 _os.write( Internal, Length );
1040 #endif //GDCMATTRIBUTE_H