gdcmVRKey.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmVRKey.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 16:14:05 $
00007   Version:   $Revision: 1.8 $
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 _GDCMVRKEY_H_
00020 #define _GDCMVRKEY_H_
00021 
00022 #include "gdcmCommon.h"
00023 
00024 #include <assert.h>
00025 #include <iomanip> // important
00026 #include <string>
00027 
00028 namespace GDCM_NAME_SPACE 
00029 {
00030 //-----------------------------------------------------------------------------
00031 class VRKey
00032 {
00033 public :
00034    inline VRKey() { key[0] = key[1] = ' ';}
00035    inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];}
00036    inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];}
00037 
00038    inline std::string str() const { return std::string(key,2); }
00039 
00040    friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val);
00041    friend std::istream &operator>>(std::istream &_is, VRKey &_val);
00042 
00043    inline VRKey &operator=(const VRKey &_val)
00044    {
00045       key[0] = _val.key[0];
00046       key[1] = _val.key[1];
00047       return *this;
00048    }
00049    
00050    inline VRKey &operator=(const std::string &_val)
00051    {
00052       key[0] = _val[0];
00053       key[1] = _val[1];
00054       return *this;
00055    }
00056    
00057    inline VRKey &operator=(const char *_val)
00058    {
00059       key[0] = _val[0];
00060       key[1] = _val[1];
00061       return *this;
00062    }
00063 
00064    inline const char &operator[](const unsigned int &_id) const
00065    {
00066       assert(_id<2);
00067       return key[_id];
00068    }
00069    
00070    inline char &operator[](const unsigned int &_id)
00071    {
00072       assert(_id<2);
00073       return key[_id];
00074    }
00075 
00076    inline bool operator==(const VRKey &_val) const
00077    {
00078       return key[0] == _val.key[0] && key[1] == _val.key[1];
00079    }
00080    
00081    inline bool operator==(const std::string &_val) const
00082    {
00083       return key[0] == _val[0] && key[1] == _val[1];
00084    }
00085    
00086    inline bool operator==(const char *_val) const
00087    {
00088       return key[0] == _val[0] && key[1] == _val[1];
00089    }
00090 
00091    inline bool operator!=(const VRKey &_val) const
00092    {
00093       return key[0] != _val.key[0] || key[1] != _val.key[1];
00094    }
00095    
00096    inline bool operator!=(const std::string &_val) const
00097    {
00098       return key[0] != _val[0] || key[1] != _val[1];
00099    }
00100    inline bool operator!=(const char *_val) const
00101    {
00102       return key[0] != _val[0] || key[1] != _val[1];
00103    }
00104 
00105    inline bool operator<(const VRKey &_val) const
00106    {
00107       return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]);
00108    }
00109 
00110 private :
00111    char key[2];
00112 };
00113 
00114 //-----------------------------------------------------------------------------
00115 inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val)
00116 {
00117    _os << _val.key[0] << _val.key[1];
00118    return _os;
00119 }
00120 
00121 inline std::istream &operator>>(std::istream &_is, VRKey &_val)
00122 {
00123    _is >> _val.key[0] >> _val.key[1];
00124    return _is;
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00128 
00129 } // end namespace gdcm
00130 
00131 //-----------------------------------------------------------------------------
00132 #endif

Generated on Fri Aug 24 12:53:20 2007 for gdcm by  doxygen 1.4.6