00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GDCMVRKEY_H
00020 #define GDCMVRKEY_H
00021
00022 #include "gdcmCommon.h"
00023
00024 #include <assert.h>
00025 #include <iomanip>
00026
00027 namespace gdcm
00028 {
00029
00030 class VRKey
00031 {
00032 public :
00033 inline VRKey() { key[0] = key[1] = ' ';}
00034 inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
00035 inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
00036
00037 inline std::string str() const { return std::string(key,2); }
00038
00039 friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
00040 friend std::istream &operator>>(std::istream &_is, VRKey &_val);
00041
00042 inline VRKey &operator=(const VRKey &_val)
00043 {
00044 key[0] = _val.key[0];
00045 key[1] = _val.key[1];
00046 return *this;
00047 }
00048
00049 inline VRKey &operator=(const std::string &_val)
00050 {
00051 key[0] = _val[0];
00052 key[1] = _val[1];
00053 return *this;
00054 }
00055
00056 inline VRKey &operator=(const char *_val)
00057 {
00058 key[0] = _val[0];
00059 key[1] = _val[1];
00060 return *this;
00061 }
00062
00063 inline const char &operator[](const unsigned int &_id) const
00064 {
00065 assert(_id<2);
00066 return key[_id];
00067 }
00068
00069 inline char &operator[](const unsigned int &_id)
00070 {
00071 assert(_id<2);
00072 return key[_id];
00073 }
00074
00075 inline bool operator==(const VRKey &_val) const
00076 {
00077 return key[0] == _val.key[0] && key[1] == _val.key[1];
00078 }
00079
00080 inline bool operator==(const std::string &_val) const
00081 {
00082 return key[0] == _val[0] && key[1] == _val[1];
00083 }
00084
00085 inline bool operator==(const char *_val) const
00086 {
00087 return key[0] == _val[0] && key[1] == _val[1];
00088 }
00089
00090 inline bool operator!=(const VRKey &_val) const
00091 {
00092 return key[0] != _val.key[0] || key[1] != _val.key[1];
00093 }
00094
00095 inline bool operator!=(const std::string &_val) const
00096 {
00097 return key[0] != _val[0] || key[1] != _val[1];
00098 }
00099 inline bool operator!=(const char *_val) const
00100 {
00101 return key[0] != _val[0] || key[1] != _val[1];
00102 }
00103
00104 inline bool operator<(const VRKey &_val) const
00105 {
00106 return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
00107 }
00108
00109 private :
00110 char key[2];
00111 };
00112
00113
00114 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
00115 {
00116 _os << _val.key[0] << _val.key[1];
00117 return _os;
00118 }
00119
00120 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
00121 {
00122 _is >> _val.key[0] >> _val.key[1];
00123 return _is;
00124 }
00125
00126
00127
00128 }
00129
00130
00131 #endif