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 #include <string>
00027
00028 namespace GDCM_NAME_SPACE
00029 {
00030
00031 class VRKey
00032 {
00033 public :
00034 inline VRKey() { key[0] = key[1] = ' ';}
00035 inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
00036 inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
00037
00038 inline std::string str() const { return std::string(key,2); }
00039
00040 friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
00041 friend std::istream &operator>>(std::istream &_is, VRKey &_val);
00042
00043 inline VRKey &operator=(const VRKey &_val)
00044 {
00045 key[0] = _val.key[0];
00046 key[1] = _val.key[1];
00047 return *this;
00048 }
00049
00050 inline VRKey &operator=(const std::string &_val)
00051 {
00052 key[0] = _val[0];
00053 key[1] = _val[1];
00054 return *this;
00055 }
00056
00057 inline VRKey &operator=(const char *_val)
00058 {
00059 key[0] = _val[0];
00060 key[1] = _val[1];
00061 return *this;
00062 }
00063
00064 inline const char &operator[](const unsigned int &_id) const
00065 {
00066 assert(_id<2);
00067 return key[_id];
00068 }
00069
00070 inline char &operator[](const unsigned int &_id)
00071 {
00072 assert(_id<2);
00073 return key[_id];
00074 }
00075
00076 inline bool operator==(const VRKey &_val) const
00077 {
00078 return key[0] == _val.key[0] && key[1] == _val.key[1];
00079 }
00080
00081 inline bool operator==(const std::string &_val) const
00082 {
00083 return key[0] == _val[0] && key[1] == _val[1];
00084 }
00085
00086 inline bool operator==(const char *_val) const
00087 {
00088 return key[0] == _val[0] && key[1] == _val[1];
00089 }
00090
00091 inline bool operator!=(const VRKey &_val) const
00092 {
00093 return key[0] != _val.key[0] || key[1] != _val.key[1];
00094 }
00095
00096 inline bool operator!=(const std::string &_val) const
00097 {
00098 return key[0] != _val[0] || key[1] != _val[1];
00099 }
00100 inline bool operator!=(const char *_val) const
00101 {
00102 return key[0] != _val[0] || key[1] != _val[1];
00103 }
00104
00105 inline bool operator<(const VRKey &_val) const
00106 {
00107 return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
00108 }
00109
00110 private :
00111 char key[2];
00112 };
00113
00114
00115 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
00116 {
00117 _os << _val.key[0] << _val.key[1];
00118 return _os;
00119 }
00120
00121 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
00122 {
00123 _is >> _val.key[0] >> _val.key[1];
00124 return _is;
00125 }
00126
00127
00128
00129 }
00130
00131
00132 #endif