00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GDCMTAGKEY_H
00020 #define GDCMTAGKEY_H
00021
00022 #include "gdcmCommon.h"
00023
00024 #include <assert.h>
00025 #include <iostream>
00026 #include <iomanip>
00027 #include <stdio.h>
00028
00029 namespace gdcm
00030 {
00031
00032 class TagKey
00033 {
00034 public :
00035 TagKey(uint16_t gr, uint16_t elt) { tag[0] = gr;tag[1] = elt;}
00036 TagKey() { tag[0] = tag[1] = 0x0000;}
00037
00038 friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val);
00039
00040 std::string str() const
00041 {
00042 char res[10];
00043 sprintf(res,"%04x|%04x",tag[0],tag[1]);
00044 return std::string(res);
00045 }
00046
00047 void SetGroup(uint16_t group) { tag[0] = group; }
00048 uint16_t GetGroup() const { return tag[0]; }
00049
00050 void SetElement(uint16_t elem) { tag[1] = elem; }
00051 uint16_t GetElement() const { return tag[1]; }
00052
00053 TagKey &operator=(const TagKey &_val)
00054 {
00055 tag[0] = _val.tag[0];
00056 tag[1] = _val.tag[1];
00057 return *this;
00058 }
00059
00060 TagKey(const TagKey &_val)
00061 {
00062 tag[0] = _val[0];
00063 tag[1] = _val[1];
00064 }
00065
00066 const uint16_t &operator[](const unsigned int &_id) const
00067 {
00068 assert(_id<2);
00069 return tag[_id];
00070 }
00071 const uint16_t &operator[](const unsigned int &_id)
00072 {
00073 assert(_id<2);
00074 return tag[_id];
00075 }
00076
00077 bool operator==(const TagKey &_val) const
00078 {
00079 return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
00080 }
00081
00082 bool operator!=(const TagKey &_val) const
00083 {
00084 return tag[0] != _val.tag[0] || tag[1] != _val.tag[1];
00085 }
00086
00087 bool operator<(const TagKey &_val) const
00088 {
00089 return tag[0] < _val.tag[0]
00090 || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
00091 }
00092
00093 private :
00094 uint16_t tag[2];
00095 };
00096
00097
00098 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
00099 {
00100 _os.setf( std::ios::right);
00101 _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
00102 << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
00103 << _val.tag[1] << std::setfill( ' ' ) << std::dec;
00104 return _os;
00105 }
00106
00107
00108
00109 }
00110
00111
00112 #endif