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