X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmVRKey.h;h=c895781bd6be3dce470a3af1b69cc73fc2dcf631;hb=c1a305b54c1a9dd1bfe2173940ba84ccd1b4bb27;hp=a594abbc7f1ee2287d9246aa8c7cc393a44bd460;hpb=9aa702d6397e3e490263a0791dd6c8ed2f3d1e83;p=gdcm.git diff --git a/src/gdcmVRKey.h b/src/gdcmVRKey.h index a594abbc..c895781b 100644 --- a/src/gdcmVRKey.h +++ b/src/gdcmVRKey.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVRKey.h,v $ Language: C++ - Date: $Date: 2005/10/19 13:17:05 $ - Version: $Revision: 1.2 $ + Date: $Date: 2009/06/23 09:01:43 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,14 +16,18 @@ =========================================================================*/ -#ifndef GDCMVRKEY_H -#define GDCMVRKEY_H +#ifndef _GDCMVRKEY_H_ +#define _GDCMVRKEY_H_ #include "gdcmCommon.h" #include +#include // important +#include // important +#include +#include // for sprintf -namespace gdcm +namespace GDCM_NAME_SPACE { //----------------------------------------------------------------------------- class VRKey @@ -35,8 +39,8 @@ public : inline std::string str() const { return std::string(key,2); } - friend std::ostream& operator<<(std::ostream& _os, const VRKey &_val); - friend std::istream& operator>>(std::istream& _is, VRKey &_val); + friend std::ostream &operator<<(std::ostream &_os, const VRKey &_val); + friend std::istream &operator>>(std::istream &_is, VRKey &_val); inline VRKey &operator=(const VRKey &_val) { @@ -44,12 +48,14 @@ public : key[1] = _val.key[1]; return *this; } + inline VRKey &operator=(const std::string &_val) { key[0] = _val[0]; key[1] = _val[1]; return *this; } + inline VRKey &operator=(const char *_val) { key[0] = _val[0]; @@ -62,6 +68,7 @@ public : assert(_id<2); return key[_id]; } + inline char &operator[](const unsigned int &_id) { assert(_id<2); @@ -72,10 +79,12 @@ public : { return key[0] == _val.key[0] && key[1] == _val.key[1]; } + inline bool operator==(const std::string &_val) const { return key[0] == _val[0] && key[1] == _val[1]; } + inline bool operator==(const char *_val) const { return key[0] == _val[0] && key[1] == _val[1]; @@ -85,6 +94,7 @@ public : { return key[0] != _val.key[0] || key[1] != _val.key[1]; } + inline bool operator!=(const std::string &_val) const { return key[0] != _val[0] || key[1] != _val[1]; @@ -99,20 +109,37 @@ public : return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]); } + inline std::string GetHexaRepresentation() + { + // We could probabelly write something much more complicated using C++ features ! + // (I really want HexaRepresentation as xx|xx, not ffffffxx|ffffffxx !) + char vr_char[6]; + char buf[5]; + sprintf(buf, "%04x",( unsigned short int)key[0]); + vr_char[0] = buf[2]; + vr_char[1] = buf[3]; + sprintf(buf, "%04x",( unsigned short int)key[1]); + vr_char[2] = '|'; + vr_char[3] = buf[2]; + vr_char[4] = buf[3]; + vr_char[5] = '\0'; + return(vr_char); + } + private : char key[2]; }; //----------------------------------------------------------------------------- -inline std::ostream& operator<<(std::ostream& _os, const VRKey &_val) +inline std::ostream &operator<<(std::ostream &_os, const VRKey &_val) { - _os << _val.key[0] << _val[1]; + _os << _val.key[0] << _val.key[1]; return _os; } -inline std::istream& operator>>(std::istream& _is, VRKey &_val) +inline std::istream &operator>>(std::istream &_is, VRKey &_val) { - _is >> _val.key[0] >> _val[1]; + _is >> _val.key[0] >> _val.key[1]; return _is; }