gdcmTagKey.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmTagKey.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 16:14:05 $
00007   Version:   $Revision: 1.13 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #ifndef _GDCMTAGKEY_H_
00020 #define _GDCMTAGKEY_H_
00021 
00022 #include "gdcmCommon.h"
00023 
00024 #include <assert.h>
00025 #include <iostream>
00026 #include <iomanip> // for std::ios::left, ...
00027 #include <stdio.h> // for ugly sprintf
00028 
00029 namespace GDCM_NAME_SPACE 
00030 {
00031 //-----------------------------------------------------------------------------
00032 class TagKey
00033 {
00034 public :
00035    TagKey(uint16_t group, uint16_t elem) { tag[0] = group;tag[1] = elem;}
00036    TagKey() { tag[0] = tag[1] = 0x0000;}
00037 
00038    friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val);
00039 
00040    std::string str() const
00041    {
00042       char res[10];
00043       sprintf(res,"%04x|%04x",tag[0],tag[1]);
00044       return std::string(res);
00045    }
00047    void SetGroup(uint16_t group) { tag[0] = group; }
00048    uint16_t GetGroup() const { return tag[0]; }
00049 
00051    void SetElement(uint16_t elem) { tag[1] = elem; }   
00052    uint16_t GetElement() const { return tag[1]; }
00053 
00055    void SetGroupElem(uint16_t group, uint16_t elem) 
00056                                { tag[0] = group;tag[1] = elem; }
00057    
00058    TagKey &operator=(const TagKey &_val)
00059    {
00060       tag[0] = _val.tag[0];
00061       tag[1] = _val.tag[1];
00062       return *this;
00063    }
00064 
00065    TagKey(const TagKey &_val)
00066    {
00067      tag[0] = _val[0];
00068      tag[1] = _val[1];
00069    }
00070 
00071    const uint16_t &operator[](const unsigned int &_id) const
00072    {
00073       assert(_id<2);
00074       return tag[_id];
00075    }
00076    const uint16_t &operator[](const unsigned int &_id)
00077    {
00078       assert(_id<2);
00079       return tag[_id];
00080    }
00081 
00082    bool operator==(const TagKey &_val) const
00083    {
00084       return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
00085    }
00086 
00087    bool operator!=(const TagKey &_val) const
00088    {
00089       return tag[0] != _val.tag[0] || tag[1] != _val.tag[1];
00090    }
00091 
00092    bool operator<(const TagKey &_val) const
00093    {
00094       return tag[0] < _val.tag[0] 
00095         || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
00096    }
00097 
00098 private :
00099    uint16_t tag[2];
00100 };
00101 
00102 //-----------------------------------------------------------------------------
00103 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
00104 {
00105    _os.setf( std::ios::right);
00106    _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
00107        << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
00108        << _val.tag[1] << std::setfill( ' ' ) << std::dec;
00109    return _os;
00110 }
00111 
00112 //-----------------------------------------------------------------------------
00113 
00114 } // end namespace gdcm
00115 
00116 //-----------------------------------------------------------------------------
00117 #endif

Generated on Fri Aug 24 12:59:32 2007 for gdcm by  doxygen 1.4.6