]> Creatis software - gdcm.git/blob - src/gdcmTagKey.h
COMP: Fix bcc55
[gdcm.git] / src / gdcmTagKey.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTagKey.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/20 13:58:18 $
7   Version:   $Revision: 1.3 $
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 #include <stdio.h> // for ugly sprintf
28
29 namespace gdcm 
30 {
31 //-----------------------------------------------------------------------------
32 class TagKey
33 {
34 public :
35    inline TagKey(const uint16_t &gr, const uint16_t &elt) { tag[0] = gr;tag[1] = elt;}
36    inline TagKey() { tag[0] = tag[1] = 0x0000;}
37
38    friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val);
39
40    inline std::string str() const
41    {
42       char res[10];
43       sprintf(res,"%04x|%04x",tag[0],tag[1]);
44       return std::string(res);
45    }
46
47    inline void SetGroup(const uint16_t &val) { tag[0] = val; }
48    inline const uint16_t &GetGroup(void) { return tag[0]; }
49
50    inline void SetElement(const uint16_t &val) { tag[1] = val; }
51    inline const uint16_t &GetElement(void) { return tag[1]; }
52
53    inline TagKey &operator=(const TagKey &_val)
54    {
55       tag[0] = _val.tag[0];
56       tag[1] = _val.tag[1];
57       return *this;
58    }
59
60    inline const uint16_t &operator[](const unsigned int &_id) const
61    {
62       assert(_id<2);
63       return tag[_id];
64    }
65    inline const uint16_t &operator[](const unsigned int &_id)
66    {
67       assert(_id<2);
68       return tag[_id];
69    }
70
71    inline bool operator==(const TagKey &_val) const
72    {
73       return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
74    }
75
76    inline bool operator!=(const TagKey &_val) const
77    {
78       return tag[0] != _val.tag[0] || tag[1] != _val.tag[1];
79    }
80
81    inline bool operator<(const TagKey &_val) const
82    {
83       return tag[0] < _val.tag[0] || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
84    }
85
86 private :
87    uint16_t tag[2];
88 };
89
90 //-----------------------------------------------------------------------------
91 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
92 {
93    _os.setf( std::ios::right);
94    _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
95        << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
96        << _val.tag[1] << std::setfill( ' ' ) << std::dec;
97    return _os;
98 }
99
100 //-----------------------------------------------------------------------------
101
102 } // end namespace gdcm
103
104 //-----------------------------------------------------------------------------
105 #endif