]> Creatis software - gdcm.git/blob - src/gdcmVRKey.h
* Correctly use the VRKey for all vr variables... instead of TagName
[gdcm.git] / src / gdcmVRKey.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVRKey.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/18 12:58:29 $
7   Version:   $Revision: 1.1 $
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 #include "gdcmDebug.h"
24
25 #include <assert.h>
26
27 namespace gdcm 
28 {
29 //-----------------------------------------------------------------------------
30 class VRKey
31 {
32 public :
33    inline VRKey() { key[0] = key[1] = ' ';}
34    inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
35    inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
36
37    inline std::string str() const { return std::string(key,2); }
38
39    friend std::ostream& operator<<(std::ostream& _os, const VRKey &_val);
40    friend std::istream& operator>>(std::istream& _is, VRKey &_val);
41
42    inline VRKey &operator=(const VRKey &_val)
43    {
44       key[0] = _val.key[0];
45       key[1] = _val.key[1];
46       return *this;
47    }
48    inline VRKey &operator=(const std::string &_val)
49    {
50       key[0] = _val[0];
51       key[1] = _val[1];
52       return *this;
53    }
54    inline VRKey &operator=(const char *_val)
55    {
56       key[0] = _val[0];
57       key[1] = _val[1];
58       return *this;
59    }
60
61    inline const char &operator[](const unsigned int &_id) const
62    {
63       assert(_id<2);
64       return key[_id];
65    }
66    inline char &operator[](const unsigned int &_id)
67    {
68       assert(_id<2);
69       return key[_id];
70    }
71
72    inline bool operator==(const VRKey &_val) const
73    {
74       return key[0] == _val.key[0] && key[1] == _val.key[1];
75    }
76    inline bool operator==(const std::string &_val) const
77    {
78       return key[0] == _val[0] && key[1] == _val[1];
79    }
80    inline bool operator==(const char *_val) const
81    {
82       return key[0] == _val[0] && key[1] == _val[1];
83    }
84
85    inline bool operator!=(const VRKey &_val) const
86    {
87       return key[0] != _val.key[0] || key[1] != _val.key[1];
88    }
89    inline bool operator!=(const std::string &_val) const
90    {
91       return key[0] != _val[0] || key[1] != _val[1];
92    }
93    inline bool operator!=(const char *_val) const
94    {
95       return key[0] != _val[0] || key[1] != _val[1];
96    }
97
98    inline bool operator<(const VRKey &_val) const
99    {
100       return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
101    }
102
103 private :
104    char key[2];
105 };
106
107 //-----------------------------------------------------------------------------
108 inline std::ostream& operator<<(std::ostream& _os, const VRKey &_val)
109 {
110    _os << _val.key[0] << _val[1];
111    return _os;
112 }
113
114 inline std::istream& operator>>(std::istream& _is, VRKey &_val)
115 {
116    _is >> _val.key[0] >> _val[1];
117    return _is;
118 }
119
120 //-----------------------------------------------------------------------------
121
122 } // end namespace gdcm
123
124 //-----------------------------------------------------------------------------
125 #endif