1 /*=========================================================================
4 Module: $RCSfile: gdcmVRKey.h,v $
6 Date: $Date: 2008/04/10 12:15:36 $
7 Version: $Revision: 1.10 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 #include "gdcmCommon.h"
25 #include <iomanip> // important
26 #include <iostream> // important
29 namespace GDCM_NAME_SPACE
31 //-----------------------------------------------------------------------------
35 inline VRKey() { key[0] = key[1] = ' ';}
36 inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
37 inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
39 inline std::string str() const { return std::string(key,2); }
41 friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
42 friend std::istream &operator>>(std::istream &_is, VRKey &_val);
44 inline VRKey &operator=(const VRKey &_val)
51 inline VRKey &operator=(const std::string &_val)
58 inline VRKey &operator=(const char *_val)
65 inline const char &operator[](const unsigned int &_id) const
71 inline char &operator[](const unsigned int &_id)
77 inline bool operator==(const VRKey &_val) const
79 return key[0] == _val.key[0] && key[1] == _val.key[1];
82 inline bool operator==(const std::string &_val) const
84 return key[0] == _val[0] && key[1] == _val[1];
87 inline bool operator==(const char *_val) const
89 return key[0] == _val[0] && key[1] == _val[1];
92 inline bool operator!=(const VRKey &_val) const
94 return key[0] != _val.key[0] || key[1] != _val.key[1];
97 inline bool operator!=(const std::string &_val) const
99 return key[0] != _val[0] || key[1] != _val[1];
101 inline bool operator!=(const char *_val) const
103 return key[0] != _val[0] || key[1] != _val[1];
106 inline bool operator<(const VRKey &_val) const
108 return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
111 inline std::string GetHexaRepresentation()
113 // We could probabelly write something much more complicated using C++ features !
114 // (I really want HexaRepresentation as xx|xx, not ffffffxx|ffffffxx !)
117 sprintf(buf, "%04x",( unsigned short int)key[0]);
120 sprintf(buf, "%04x",( unsigned short int)key[1]);
132 //-----------------------------------------------------------------------------
133 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
135 _os << _val.key[0] << _val.key[1];
139 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
141 _is >> _val.key[0] >> _val.key[1];
145 //-----------------------------------------------------------------------------
147 } // end namespace gdcm
149 //-----------------------------------------------------------------------------