X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmUtil.cxx;h=936e0dde2985bf64a8f3a43c250290de15514f26;hb=cfc4bc0156d2846054d5e79cc6a9b5770a2a729f;hp=35384b64b2dd1ebbf2ac592d2ebd140fe0200490;hpb=c2c1e9db8ba607baf94c46d96b7cca9bead3ceb6;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 35384b64..936e0dde 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 22:49:57 $ - Version: $Revision: 1.168 $ + Date: $Date: 2005/11/29 13:02:46 $ + Version: $Revision: 1.179 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,7 +18,9 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" + #include +#include // for va_list // For GetCurrentDate, GetCurrentTime #include @@ -110,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 @@ -126,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 @@ -192,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); @@ -939,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) { @@ -956,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) { @@ -970,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) { @@ -981,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) { @@ -993,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) @@ -1005,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) { @@ -1117,6 +1147,14 @@ std::string Util::GetIPAddress() return str; } +void Util::hfpswap(double *a, double *b) +{ + double tmp; + tmp=*a; + *a=*b; + *b=tmp; +} + //------------------------------------------------------------------------- } // end namespace gdcm