X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmUtil.cxx;h=bf3b7056397b9f147328be167ab74fbd690efd1f;hb=df1540af8230b8ca5e3cba23e9127e2a2428df78;hp=576d31800a46a1a38ee358d00ab027071d7750be;hpb=8132e180439a6e41d07240cad48be249b66e5e05;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 576d3180..bf3b7056 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2006/05/31 16:09:29 $ - Version: $Revision: 1.184 $ + Date: $Date: 2008/01/02 14:58:00 $ + Version: $Revision: 1.190 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -92,7 +92,7 @@ #include #endif -namespace gdcm +namespace GDCM_NAME_SPACE { //------------------------------------------------------------------------- const std::string Util::GDCM_UID = "1.2.826.0.1.3680043.2.1143"; @@ -103,9 +103,15 @@ std::string Util::RootUID = GDCM_UID; * value 0x0001 encoded as a little endian 16 bit short value, * which would be the other way around... */ -const uint16_t Util::FMIV = 0x0100; -uint8_t *Util::FileMetaInformationVersion = (uint8_t *)&FMIV; -std::string Util::GDCM_MAC_ADRESS = GetMACAddress(); + +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) + const uint16_t Util::FMIV = 0x0001; +#else + const uint16_t Util::FMIV = 0x0100; +#endif + uint8_t *Util::FileMetaInformationVersion = (uint8_t *)&FMIV; + + std::string Util::GDCM_MAC_ADDRESS = GetMACAddress(); //------------------------------------------------------------------------- // Public @@ -237,7 +243,6 @@ std::string Util::CreateCleanString(std::string const &s) str[i] = '.'; } } - if (str.size() > 0 ) { if (!isprint((unsigned char)s[str.size()-1]) ) @@ -248,9 +253,32 @@ std::string Util::CreateCleanString(std::string const &s) } } } - return str; } +/** + * \brief Replaces all special characters + * @param s string to modify + * @param rep replacement char + */ +void Util::ReplaceSpecChar(std::string &s, std::string &rep) +{ + unsigned int s_size = s.size(); + for(unsigned int i=0; i= '+' && s[i] <= '-') + || (s[i] >= 'a' && s[i] <= 'z') + || (s[i] >= '0' && s[i] <= '9') + || (s[i] >= 'A' && s[i] <= 'Z'))) + { + s.replace(i, 1, rep); + } + } + // deal with Dicom strings trailing '\0' + if(s[s_size-1] == rep.c_str()[0]) + s.erase(s_size-1, 1); +} + /** * \brief Weed out a string from the non-printable characters (in order @@ -855,8 +883,14 @@ int GetMacAddrSys ( unsigned char *addr ) } close(sd); #endif - // Not implemented platforms (or no cable !) - perror("in Get MAC Adress (internal) : There was a configuration problem (or no cable !) on your plateform"); + // Not implemented platforms (or no Ethernet cable !) + + /// \todo FIXME I wish we don't pollute command line applications when no Ethernet cable ! + //perror("Probabely your computer is not connected on a network, therefore its MAC adress cannot be found (or there is a configuration problem on your platform)"); + + // But the following -> error: invalid use of 'this' in non-member function + //gdcmWarningMacro( "Probabely your computer is not connected on a network, therefore its MAC adress cannot be found (or there is a configuration problem on your platform)"); + memset(addr,0,6); return -1; #endif //__sun @@ -931,6 +965,7 @@ std::string Util::CreateUniqueUID(const std::string &root) if ( root.empty() ) { // gdcm UID prefix, as supplied by http://www.medicalconnections.co.uk + assert( !RootUID.empty() ); prefix = RootUID; } else @@ -941,8 +976,11 @@ std::string Util::CreateUniqueUID(const std::string &root) // A root was specified use it to forge our new UID: append += "."; //append += Util::GetMACAddress(); // to save CPU time - append += Util::GDCM_MAC_ADRESS; - append += "."; + if( !Util::GDCM_MAC_ADDRESS.empty() ) // When mac address was empty we would end up with a double . which is illegal + { + append += Util::GDCM_MAC_ADDRESS; + append += "."; + } append += Util::GetCurrentDateTime(); append += "."; //Also add a mini random number just in case: @@ -1241,7 +1279,7 @@ void Util::hfpswap(double *a, double *b) ghost@aladdin.com */ -/* $Id: gdcmUtil.cxx,v 1.184 2006/05/31 16:09:29 jpr Exp $ */ +/* $Id: gdcmUtil.cxx,v 1.190 2008/01/02 14:58:00 malaterre Exp $ */ /* Independent implementation of MD5 (RFC 1321).