]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
The automatic set to VR = "LO" for shadow elements that could be
[gdcm.git] / src / gdcmUtil.cxx
index df341c88e32bd444b5630709504cab3b082e0aa2..19895c1f4e960b4b09ff98135f55a897a9d7d5a3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/11/03 08:47:52 $
-  Version:   $Revision: 1.173 $
+  Date:      $Date: 2006/01/10 15:54:03 $
+  Version:   $Revision: 1.182 $
                                                                                 
   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>
@@ -192,7 +194,6 @@ int Util::CountSubstring (const std::string &str,
  */
 bool Util::IsCleanString(std::string const &s)
 {
-   //std::cout<< std::endl << s << std::endl;
    for(unsigned int i=0; i<s.size(); i++)
    {
       if (!isprint((unsigned char)s[i]) )
@@ -276,20 +277,27 @@ std::string Util::CreateCleanString(uint8_t *s, int l)
    return str;
 }
 /**
- * \brief   Add a SEPARATOR to the end of the name is necessary
+ * \brief   Add a SEPARATOR to the end of the name if necessary
  * @param   pathname file/directory name to normalize 
  */
 std::string Util::NormalizePath(std::string const &pathname)
 {
+/*
    const char SEPARATOR_X      = '/';
    const char SEPARATOR_WIN    = '\\';
+#ifdef _WIN32
+   const std::string SEPARATOR = "\\";
+#else
    const std::string SEPARATOR = "/";
+#endif
+*/
    std::string name = pathname;
    int size = name.size();
 
-   if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN )
+//   if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN )
+   if ( name[size-1] != GDCM_FILESEPARATOR )
    {
-      name += SEPARATOR;
+      name += GDCM_FILESEPARATOR;
    }
    return name;
 }
@@ -301,6 +309,8 @@ std::string Util::NormalizePath(std::string const &pathname)
 std::string Util::GetPath(std::string const &fullName)
 {
    std::string res = fullName;
+/*
+   
    int pos1 = res.rfind("/");
    int pos2 = res.rfind("\\");
    if ( pos1 > pos2 )
@@ -311,7 +321,9 @@ std::string Util::GetPath(std::string const &fullName)
    {
       res.resize(pos2);
    }
-
+*/
+   int pos = res.rfind(GDCM_FILESEPARATOR);
+   res.resize(pos);
    return res;
 }
 
@@ -322,10 +334,14 @@ std::string Util::GetPath(std::string const &fullName)
 std::string Util::GetName(std::string const &fullName)
 {   
   std::string filename = fullName;
-
+/*
   std::string::size_type slash_pos = filename.rfind("/");
   std::string::size_type backslash_pos = filename.rfind("\\");
-  slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos;
+  // At least with my gcc4.0.1, unfound char results in pos =4294967295 ...
+  //slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos;  
+  slash_pos = slash_pos < backslash_pos ? slash_pos : backslash_pos;
+*/
+  std::string::size_type slash_pos = filename.rfind(GDCM_FILESEPARATOR);
   if (slash_pos != std::string::npos )
     {
     return filename.substr(slash_pos + 1);
@@ -481,8 +497,8 @@ std::string Util::DicomString(const char *s)
 /**
  * \brief Safely check the equality of two Dicom String:
  *        - Both strings should be of even length
- *        - We allow padding of even length string by either a null 
- *          character of a space
+ *        - We allow padding of even length string by either 
+ *           a null character of a space
  */
 bool Util::DicomStringEqual(const std::string &s1, const char *s2)
 {
@@ -499,8 +515,8 @@ bool Util::DicomStringEqual(const std::string &s1, const char *s2)
 /**
  * \brief Safely compare two Dicom String:
  *        - Both strings should be of even length
- *        - We allow padding of even length string by either a null 
- *          character of a space
+ *        - We allow padding of even length string by either  
+ *          a null character of a space
  */
 bool Util::CompareDicomString(const std::string &s1, const char *s2, int op)
 {
@@ -813,7 +829,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
@@ -837,7 +853,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()
@@ -870,14 +886,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
  */
@@ -912,7 +928,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);
@@ -978,7 +994,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;
@@ -1145,6 +1161,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