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