]> Creatis software - gdcm.git/blob - src/gdcmTagKey.h
Fix mistypings
[gdcm.git] / src / gdcmTagKey.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTagKey.h,v $
5   Language:  C++
6   Date:      $Date: 2007/08/22 16:14:05 $
7   Version:   $Revision: 1.13 $
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_NAME_SPACE 
30 {
31 //-----------------------------------------------------------------------------
32 class TagKey
33 {
34 public :
35    TagKey(uint16_t group, uint16_t elem) { tag[0] = group;tag[1] = elem;}
36    TagKey() { tag[0] = tag[1] = 0x0000;}
37
38    friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val);
39
40    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    ///\brief sets the Group Number for the TagKey
47    void SetGroup(uint16_t group) { tag[0] = group; }
48    uint16_t GetGroup() const { return tag[0]; }
49
50    ///\brief sets the Element Number for the TagKey
51    void SetElement(uint16_t elem) { tag[1] = elem; }   
52    uint16_t GetElement() const { return tag[1]; }
53
54    ///\brief sets the Group Number and Element Number for the TagKey
55    void SetGroupElem(uint16_t group, uint16_t elem) 
56                                { tag[0] = group;tag[1] = elem; }
57    
58    TagKey &operator=(const TagKey &_val)
59    {
60       tag[0] = _val.tag[0];
61       tag[1] = _val.tag[1];
62       return *this;
63    }
64
65    TagKey(const TagKey &_val)
66    {
67      tag[0] = _val[0];
68      tag[1] = _val[1];
69    }
70
71    const uint16_t &operator[](const unsigned int &_id) const
72    {
73       assert(_id<2);
74       return tag[_id];
75    }
76    const uint16_t &operator[](const unsigned int &_id)
77    {
78       assert(_id<2);
79       return tag[_id];
80    }
81
82    bool operator==(const TagKey &_val) const
83    {
84       return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
85    }
86
87    bool operator!=(const TagKey &_val) const
88    {
89       return tag[0] != _val.tag[0] || tag[1] != _val.tag[1];
90    }
91
92    bool operator<(const TagKey &_val) const
93    {
94       return tag[0] < _val.tag[0] 
95         || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
96    }
97
98 private :
99    uint16_t tag[2];
100 };
101
102 //-----------------------------------------------------------------------------
103 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
104 {
105    _os.setf( std::ios::right);
106    _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
107        << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
108        << _val.tag[1] << std::setfill( ' ' ) << std::dec;
109    return _os;
110 }
111
112 //-----------------------------------------------------------------------------
113
114 } // end namespace gdcm
115
116 //-----------------------------------------------------------------------------
117 #endif