]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
* Add Command and CommandManager to have possible callback
[gdcm.git] / src / gdcmUtil.cxx
index 7ac1484ca0683a69fb55e8ddd6c3425a4d8bffcb..d351e406d85edccebf9b5d6249dabb08c6b94f28 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/27 17:04:36 $
-  Version:   $Revision: 1.170 $
+  Date:      $Date: 2005/11/28 15:20:34 $
+  Version:   $Revision: 1.177 $
                                                                                 
   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 <iostream>
+#include <stdarg.h> // for va_list
 
 // For GetCurrentDate, GetCurrentTime
 #include <time.h>
@@ -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<s.size(); i++)
    {
-      //std::cout<< std::endl << i << " : " << (unsigned char)s[i] << std::endl;
       if (!isprint((unsigned char)s[i]) )
       {
          return false;
@@ -452,7 +453,7 @@ bool Util::IsCurrentProcessorBigEndian()
 std::string Util::DicomString(const char *s, size_t l)
 {
    std::string r(s, s+l);
-   gdcmAssertMacro( !(r.size() % 2) ); // == basically 'l' is even
+   gdcmStaticAssertMacro( !(r.size() % 2) ); // == basically 'l' is even
    return r;
 }
 
@@ -475,7 +476,7 @@ std::string Util::DicomString(const char *s)
       l++;
    }
    std::string r(s, s+l);
-   gdcmAssertMacro( !(r.size() % 2) );
+   gdcmStaticAssertMacro( !(r.size() % 2) );
    return r;
 }
 
@@ -527,7 +528,7 @@ bool Util::CompareDicomString(const std::string &s1, const char *s2, int op)
      case GDCM_LESSOREQUAL :
         return s1_even <= s2_even;
      default :
-        gdcmDebugMacro(" Wrong operator : " << op);
+        gdcmStaticDebugMacro(" Wrong operator : " << op);
         return false;
   }
 }
@@ -814,7 +815,7 @@ 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 on your plateform");
+   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
@@ -838,7 +839,7 @@ inline int getlastdigit(unsigned char *data)
 }
 
 /**
- * \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()
@@ -871,14 +872,14 @@ 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
  */
@@ -913,7 +914,7 @@ std::string Util::CreateUniqueUID(const std::string &root)
    // 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);
@@ -979,7 +980,7 @@ std::ostream &binary_write(std::ostream &os, const uint32_t &val)
 std::ostream &binary_write(std::ostream &os, const double &val)
 {
 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)    
-   double swap;
+   double swap = val;
    
    char *beg = (char *)&swap;
    char *end = beg + 7;
@@ -1027,7 +1028,6 @@ std::ostream &binary_write(std::ostream &os, std::string const &val)
  */ 
 std::ostream &binary_write(std::ostream &os, const uint8_t *val, size_t len)
 {
-std::cout << "binary_write " << len << std::endl;
    // We are writting sizeof(char) thus no need to swap bytes
    return os.write(reinterpret_cast<const char*>(val), len);
 }