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/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
#include "gdcmUtil.h"
#include "gdcmDebug.h"
+
#include <iostream>
+#include <stdarg.h> // for va_list
// For GetCurrentDate, GetCurrentTime
#include <time.h>
/**
* \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
*/
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
*/
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<s.size(); i++)
{
- //std::cout<< std::endl << i << " : " << (unsigned char)s[i] << std::endl;
if (!isprint((unsigned char)s[i]) )
{
return false;
}
close(sd);
#endif
- // Not implemented platforms
- perror("in Get MAC Adress (internal) : There was a configuration problem on your plateform");
+ // Not implemented platforms (or no cable !)
+ perror("in Get MAC Adress (internal) : There was a configuration problem (or no cable !) on your plateform");
memset(addr,0,6);
return -1;
#endif //__sun
}
/**
- * \brief Encode the mac address on a fixed lenght string of 15 characters.
+ * \brief Encode the mac address on a fixed length string of 15 characters.
* we save space this way.
*/
std::string Util::GetMACAddress()
}
else
{
- gdcmWarningMacro("Problem in finding the MAC Address");
+ gdcmStaticWarningMacro("Problem in finding the MAC Address");
return "";
}
}
/**
- * \brief Creates a new UID. As stipulate in the DICOM ref
- * each time a DICOM image is create it should have
+ * \brief Creates a new UID. As stipulated in the DICOM ref
+ * each time a DICOM image is created it should have
* a unique identifier (URI)
* @param root is the DICOM prefix assigned by IOS group
*/
// If append is too long we need to rehash it
if ( (prefix + append).size() > 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);
/**
* \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)
{
/**
* \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)
{
#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<const char*>(&swap), 8);
+#else
+ return os.write(reinterpret_cast<const char*>(&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)
{
}
/**
- * \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)
{
/**
* \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)
/**
* \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)
{