]> Creatis software - gdcm.git/blob - src/gdcmTagKey.h
* Remove the Key information in Entry
[gdcm.git] / src / gdcmTagKey.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTagKey.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/19 13:17:05 $
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 GDCMTAGKEY_H
20 #define GDCMTAGKEY_H
21
22 #include "gdcmCommon.h"
23
24 #include <assert.h>
25 #include <iostream>
26 #include <iomanip> // for std::ios::left, ...
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 class TagKey
32 {
33 public :
34    inline TagKey(const uint16_t &gr, const uint16_t &elt) { tag[0] = gr;tag[1] = elt;}
35    inline TagKey() { tag[0] = tag[1] = 0x0000;}
36
37    friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val);
38
39    inline void SetGroup(const uint16_t &val) { tag[0] = val; }
40    inline const uint16_t &GetGroup(void) { return tag[0]; }
41
42    inline void SetElement(const uint16_t &val) { tag[1] = val; }
43    inline const uint16_t &GetElement(void) { return tag[1]; }
44
45    inline TagKey &operator=(const TagKey &_val)
46    {
47       tag[0] = _val.tag[0];
48       tag[1] = _val.tag[1];
49       return *this;
50    }
51
52    inline const uint16_t &operator[](const unsigned int &_id) const
53    {
54       assert(_id<2);
55       return tag[_id];
56    }
57    inline const uint16_t &operator[](const unsigned int &_id)
58    {
59       assert(_id<2);
60       return tag[_id];
61    }
62
63    inline bool operator==(const TagKey &_val) const
64    {
65       return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
66    }
67
68    inline bool operator!=(const TagKey &_val) const
69    {
70       return tag[0] != _val.tag[0] || tag[1] != _val.tag[1];
71    }
72
73    inline bool operator<(const TagKey &_val) const
74    {
75       return tag[0] < _val.tag[0] || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
76    }
77
78 private :
79    uint16_t tag[2];
80 };
81
82 //-----------------------------------------------------------------------------
83 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
84 {
85    _os.setf( std::ios::right);
86    _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
87        << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
88        << _val.tag[1] << std::setfill( ' ' ) << std::dec;
89    return _os;
90 }
91
92 //-----------------------------------------------------------------------------
93
94 } // end namespace gdcm
95
96 //-----------------------------------------------------------------------------
97 #endif