1 /*=========================================================================
4 Module: $RCSfile: gdcmVRKey.h,v $
6 Date: $Date: 2010/09/01 15:42:28 $
7 Version: $Revision: 1.13 $
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
28 #include <stdio.h> // for sprintf
30 namespace GDCM_NAME_SPACE
32 //-----------------------------------------------------------------------------
36 inline VRKey() { key[0] = key[1] = ' ';}
37 inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
38 inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
40 inline std::string str() const { return std::string(key,2); }
42 friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
43 friend std::istream &operator>>(std::istream &_is, VRKey &_val);
45 inline VRKey &operator=(const VRKey &_val)
52 inline VRKey &operator=(const std::string &_val)
59 inline VRKey &operator=(const char *_val)
66 inline const char &operator[](const unsigned int &_id) const
72 inline char &operator[](const unsigned int &_id)
78 inline bool operator==(const VRKey &_val) const
80 return key[0] == _val.key[0] && key[1] == _val.key[1];
83 inline bool operator==(const std::string &_val) const
85 return key[0] == _val[0] && key[1] == _val[1];
88 inline bool operator==(const char *_val) const
90 return key[0] == _val[0] && key[1] == _val[1];
93 inline bool operator!=(const VRKey &_val) const
95 return key[0] != _val.key[0] || key[1] != _val.key[1];
98 inline bool operator!=(const std::string &_val) const
100 return key[0] != _val[0] || key[1] != _val[1];
102 inline bool operator!=(const char *_val) const
104 return key[0] != _val[0] || key[1] != _val[1];
107 inline bool operator<(const VRKey &_val) const
109 return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
112 inline std::string GetHexaRepresentation()
114 // We could probabelly write something much more complicated using C++ features !
115 // (I really want HexaRepresentation as xx|xx, not ffffffxx|ffffffxx !)
118 sprintf(buf, "%04x",( unsigned short int)key[0]);
121 sprintf(buf, "%04x",( unsigned short int)key[1]);
133 //-----------------------------------------------------------------------------
134 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
136 _os << _val.key[0] << _val.key[1];
140 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
142 _is >> _val.key[0] >> _val.key[1];
146 //-----------------------------------------------------------------------------
148 } // end namespace gdcm
150 //-----------------------------------------------------------------------------