X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmUtil.cxx;h=a89ca6878c8166564769a478dd8f3286c714d196;hb=6d79b5e185867ef00629f1ccb279c32daa6357d2;hp=7ba0e2bf83a000d014f8008d83ed062cd18a0f98;hpb=cac8f308365b0b699f01063395715550daae3a3e;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 7ba0e2bf..a89ca687 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2005/10/24 21:31:11 $ - Version: $Revision: 1.167 $ + Date: $Date: 2005/11/28 16:50:33 $ + Version: $Revision: 1.178 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,18 +18,18 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" + #include +#include // for va_list // For GetCurrentDate, GetCurrentTime #include #include #include -// Two approaches, *NIX or Win32 -#ifdef CMAKE_HAVE_SYS_TIMEB_H +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) #include -#endif -#ifdef CMAKE_HAVE_SYS_TIMES_H +#else #include #endif @@ -112,7 +112,7 @@ std::string Util::GDCM_MAC_ADRESS = GetMACAddress(); /** * \brief Provide a better 'c++' approach for sprintf * For example c code is: - * char result[200]; // hope 200 is enough + * char result[2048]; // hope 2048 is enough * sprintf(result, "%04x|%04x", group , elem); * * c++ code is @@ -128,7 +128,7 @@ std::string Util::GDCM_MAC_ADRESS = GetMACAddress(); */ std::string Util::Format(const char *format, ...) { - char buffer[2048]; + char buffer[2048]; // hope 2048 is enough va_list args; va_start(args, format); vsprintf(buffer, format, args); //might be a security flaw @@ -194,10 +194,9 @@ int Util::CountSubstring (const std::string &str, */ bool Util::IsCleanString(std::string const &s) { - std::cout<< std::endl << s << std::endl; + //std::cout<< std::endl << s << std::endl; for(unsigned int i=0; i 64 ) { - gdcmErrorMacro( "Size of UID is too long." ); + gdcmStaticErrorMacro( "Size of UID is too long." ); // we need a hash function to truncate this number // if only md5 was cross plateform // MD5(append); @@ -941,7 +940,7 @@ const std::string &Util::GetRootUID() /** * \brief binary_write binary_write * @param os ostream to write to - * @param val val + * @param val 16 bits value to write */ std::ostream &binary_write(std::ostream &os, const uint16_t &val) { @@ -958,7 +957,7 @@ std::ostream &binary_write(std::ostream &os, const uint16_t &val) /** * \brief binary_write binary_write * @param os ostream to write to - * @param val val + * @param val 32 bits value to write */ std::ostream &binary_write(std::ostream &os, const uint32_t &val) { @@ -972,10 +971,39 @@ std::ostream &binary_write(std::ostream &os, const uint32_t &val) #endif //GDCM_WORDS_BIGENDIAN } + +/** + * \brief binary_write binary_write + * @param os ostream to write to + * @param val double (64 bits) value to write + */ +std::ostream &binary_write(std::ostream &os, const double &val) +{ +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) + double swap = val; + + char *beg = (char *)&swap; + char *end = beg + 7; + char t; + for (unsigned int i = 0; i<7; i++) + { + t = *beg; + *beg = *end; + *end = t; + beg++, + end--; + } + return os.write(reinterpret_cast(&swap), 8); +#else + return os.write(reinterpret_cast(&val), 8); +#endif //GDCM_WORDS_BIGENDIAN +} + + /** * \brief binary_write binary_write * @param os ostream to write to - * @param val val + * @param val 8 bits characters aray to write */ std::ostream &binary_write(std::ostream &os, const char *val) { @@ -983,9 +1011,9 @@ std::ostream &binary_write(std::ostream &os, const char *val) } /** - * \brief + * \brief binary_write binary_write * @param os ostream to write to - * @param val val + * @param val std::string value to write */ std::ostream &binary_write(std::ostream &os, std::string const &val) { @@ -995,7 +1023,7 @@ std::ostream &binary_write(std::ostream &os, std::string const &val) /** * \brief binary_write binary_write * @param os ostream to write to - * @param val value + * @param val 8 bits 'characters' aray to write * @param len length of the 'value' to be written */ std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len) @@ -1007,8 +1035,8 @@ std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len) /** * \brief binary_write binary_write * @param os ostream to write to - * @param val val - * @param len length of the 'value' to be written + * @param val 16 bits words aray to write + * @param len length (in bytes) of the 'value' to be written */ std::ostream &binary_write(std::ostream &os, const uint16_t *val, size_t len) {