Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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: 2005/11/08 09:35:44 $
00007   Version:   $Revision: 1.10 $
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 
00030 {
00031 //-----------------------------------------------------------------------------
00032 class TagKey
00033 {
00034 public :
00035    TagKey(uint16_t gr, uint16_t elt) { tag[0] = gr;tag[1] = elt;}
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    }
00046 
00047    void SetGroup(uint16_t group) { tag[0] = group; }
00048    uint16_t GetGroup() const { return tag[0]; }
00049 
00050    void SetElement(uint16_t elem) { tag[1] = elem; }
00051    uint16_t GetElement() const { return tag[1]; }
00052 
00053    TagKey &operator=(const TagKey &_val)
00054    {
00055       tag[0] = _val.tag[0];
00056       tag[1] = _val.tag[1];
00057       return *this;
00058    }
00059 
00060    TagKey(const TagKey &_val)
00061    {
00062      tag[0] = _val[0];
00063      tag[1] = _val[1];
00064    }
00065 
00066    const uint16_t &operator[](const unsigned int &_id) const
00067    {
00068       assert(_id<2);
00069       return tag[_id];
00070    }
00071    const uint16_t &operator[](const unsigned int &_id)
00072    {
00073       assert(_id<2);
00074       return tag[_id];
00075    }
00076 
00077    bool operator==(const TagKey &_val) const
00078    {
00079       return tag[0] == _val.tag[0] && tag[1] == _val.tag[1];
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] 
00090         || (tag[0] == _val.tag[0] && tag[1] < _val.tag[1]);
00091    }
00092 
00093 private :
00094    uint16_t tag[2];
00095 };
00096 
00097 //-----------------------------------------------------------------------------
00098 inline std::ostream& operator<<(std::ostream& _os, const TagKey &_val)
00099 {
00100    _os.setf( std::ios::right);
00101    _os << std::hex << std::setw( 4 ) << std::setfill( '0' )
00102        << _val.tag[0] << '|' << std::setw( 4 ) << std::setfill( '0' )
00103        << _val.tag[1] << std::setfill( ' ' ) << std::dec;
00104    return _os;
00105 }
00106 
00107 //-----------------------------------------------------------------------------
00108 
00109 } // end namespace gdcm
00110 
00111 //-----------------------------------------------------------------------------
00112 #endif

Generated on Fri Jan 20 10:14:26 2006 for gdcm by  doxygen 1.4.4