]> Creatis software - gdcm.git/blob - src/gdcmVRKey.h
UserDefinedFileIdentifier is now more human readable
[gdcm.git] / src / gdcmVRKey.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVRKey.h,v $
5   Language:  C++
6   Date:      $Date: 2007/08/22 16:14:05 $
7   Version:   $Revision: 1.8 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef _GDCMVRKEY_H_
20 #define _GDCMVRKEY_H_
21
22 #include "gdcmCommon.h"
23
24 #include <assert.h>
25 #include <iomanip> // important
26 #include <string>
27
28 namespace GDCM_NAME_SPACE 
29 {
30 //-----------------------------------------------------------------------------
31 class VRKey
32 {
33 public :
34    inline VRKey() { key[0] = key[1] = ' ';}
35    inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
36    inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
37
38    inline std::string str() const { return std::string(key,2); }
39
40    friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
41    friend std::istream &operator>>(std::istream &_is, VRKey &_val);
42
43    inline VRKey &operator=(const VRKey &_val)
44    {
45       key[0] = _val.key[0];
46       key[1] = _val.key[1];
47       return *this;
48    }
49    
50    inline VRKey &operator=(const std::string &_val)
51    {
52       key[0] = _val[0];
53       key[1] = _val[1];
54       return *this;
55    }
56    
57    inline VRKey &operator=(const char *_val)
58    {
59       key[0] = _val[0];
60       key[1] = _val[1];
61       return *this;
62    }
63
64    inline const char &operator[](const unsigned int &_id) const
65    {
66       assert(_id<2);
67       return key[_id];
68    }
69    
70    inline char &operator[](const unsigned int &_id)
71    {
72       assert(_id<2);
73       return key[_id];
74    }
75
76    inline bool operator==(const VRKey &_val) const
77    {
78       return key[0] == _val.key[0] && key[1] == _val.key[1];
79    }
80    
81    inline bool operator==(const std::string &_val) const
82    {
83       return key[0] == _val[0] && key[1] == _val[1];
84    }
85    
86    inline bool operator==(const char *_val) const
87    {
88       return key[0] == _val[0] && key[1] == _val[1];
89    }
90
91    inline bool operator!=(const VRKey &_val) const
92    {
93       return key[0] != _val.key[0] || key[1] != _val.key[1];
94    }
95    
96    inline bool operator!=(const std::string &_val) const
97    {
98       return key[0] != _val[0] || key[1] != _val[1];
99    }
100    inline bool operator!=(const char *_val) const
101    {
102       return key[0] != _val[0] || key[1] != _val[1];
103    }
104
105    inline bool operator<(const VRKey &_val) const
106    {
107       return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
108    }
109
110 private :
111    char key[2];
112 };
113
114 //-----------------------------------------------------------------------------
115 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
116 {
117    _os << _val.key[0] << _val.key[1];
118    return _os;
119 }
120
121 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
122 {
123    _is >> _val.key[0] >> _val.key[1];
124    return _is;
125 }
126
127 //-----------------------------------------------------------------------------
128
129 } // end namespace gdcm
130
131 //-----------------------------------------------------------------------------
132 #endif