]> Creatis software - gdcm.git/commitdiff
* src/gdcmUtil.cxx : compilation fix on Win32
authorregrain <regrain>
Fri, 28 Jan 2005 09:37:28 +0000 (09:37 +0000)
committerregrain <regrain>
Fri, 28 Jan 2005 09:37:28 +0000 (09:37 +0000)
   * src/gdcmUtil.[h|cxx] : Set the default GDCM UID in a static constant
     variable, to be easy found. Add methods to change the default UID.
     Amelioration of the CreateUniqueUID to use the correct default UID.
   * src/gdcmFile.cxx : correct use of the CreateUniqueUID method to create
     a new file
   -- BeNours

ChangeLog
src/gdcmFile.cxx
src/gdcmUtil.cxx
src/gdcmUtil.h

index f596beef1ab184f98f9b5e6def60218de6977f9a..d4cd467cfd44d4690413c04094e3c98746a5339a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-01-28 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * src/gdcmUtil.cxx : compilation fix on Win32
+   * src/gdcmUtil.[h|cxx] : Set the default GDCM UID in a static constant
+     variable, to be easy found. Add methods to change the default UID.
+     Amelioration of the CreateUniqueUID to use the correct default UID.
+   * src/gdcmFile.cxx : correct use of the CreateUniqueUID method to create
+     a new file
+
 2005-01-28 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * Test/TestVR.cxx : fix memory leaks
 
index aa6db0bd2c5a347c4e1cd9e77a0caa20b254a1b0..9ba43132d36993af2ca089078c337e4afbace32a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/26 17:17:31 $
-  Version:   $Revision: 1.202 $
+  Date:      $Date: 2005/01/28 09:37:29 $
+  Version:   $Revision: 1.203 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1347,10 +1347,10 @@ void File::InitializeDefaultFile()
    std::string time = Util::GetCurrentTime();
    std::string uid  = Util::CreateUniqueUID();
    std::string uidMedia = uid;
-   std::string uidClass = uid + ".1";
-   std::string uidInst  = uid + ".10";
-   std::string uidStudy = uid + ".100";
-   std::string uidSerie = uid + ".1000";
+   std::string uidInst  = uid;
+   std::string uidClass = Util::CreateUniqueUID();
+   std::string uidStudy = Util::CreateUniqueUID();
+   std::string uidSerie = Util::CreateUniqueUID();
 
    static DICOM_DEFAULT_VALUE defaultvalue[] = {
     { "146 ",                      0x0002, 0x0000}, // Meta Element Group Length // FIXME: how to recompute ?
@@ -1404,7 +1404,6 @@ void File::InitializeDefaultFile()
    }
 }
 
-
 //-----------------------------------------------------------------------------
 // Private
 /**
index 6880df0c9927683231d7d26a6237d137c85e0cd5..8433ad06ce08115ff2ec04b62d288bcb6c384da7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/28 00:02:15 $
-  Version:   $Revision: 1.125 $
+  Date:      $Date: 2005/01/28 09:37:29 $
+  Version:   $Revision: 1.126 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -90,6 +90,9 @@
 
 namespace gdcm 
 {
+const std::string Util::GDCM_UID = "1.2.826.0.1.3680043.2.1143";
+std::string Util::RootUID        = GDCM_UID;
+
 /**
  * \brief Provide a better 'c++' approach for sprintf
  * For example c code is:
@@ -695,7 +698,7 @@ std::string Util::GetMACAddress()
    // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be
    // http://bdn.borland.com/article/0,1410,26040,00.html
    unsigned char addr[6];
+
    int stat = GetMacAddrSys(addr);
    if (stat == 0)
    {
@@ -706,11 +709,11 @@ std::string Util::GetMACAddress()
       int res;
       std::string sres;
       while(!zero)
-        {
-        res = getlastdigit(addr);
-        sres.push_back( '0' + res );
-        zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0);
-        }
+      {
+         res = getlastdigit(addr);
+         sres += ('0' + res);
+         zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0);
+      }
       // Since we push back the proper number is reversed:
       std::reverse(sres.begin(),sres.end());
 
@@ -784,6 +787,37 @@ std::string Util::GetIPAddress()
    return str;
 }
 
+unsigned int Util::GetCurrentThreadID()
+{
+// FIXME the implementation is far from complete
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+  return (unsigned int)GetCurrentThreadId();
+#endif
+#ifdef __linux__
+   return 0;
+   // Doesn't work on fedora, but is in the man page...
+   //return (unsigned int)gettid();
+#endif
+#ifdef __sun
+   return (unsigned int)thr_self();
+#else
+   //default implementation
+   return 0;
+#endif
+}
+
+unsigned int Util::GetCurrentProcessID()
+{
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+  // NOTE: There is also a _getpid()...
+  return (unsigned int)GetCurrentProcessId();
+#else
+  // get process identification, POSIX
+  return (unsigned int)getpid();
+#endif
+
+}
+
 /**
  * \brief Creates a new UID. As stipulate in the DICOM ref
  *        each time a DICOM image is create it should have 
@@ -792,19 +826,18 @@ std::string Util::GetIPAddress()
  */
 std::string Util::CreateUniqueUID(const std::string &root)
 {
-   std::string prefix = root;
+   std::string prefix;
    std::string append;
    if( root.empty() )
    {
-      // No root was specified use "GDCM" then
-      // echo "gdcm" | od -b
-      // 0000000 147 144 143 155 012
-      //prefix = "147.144.143.155"; // special easter egg
-
       // gdcm UID prefix, as supplied by http://www.medicalconnections.co.uk
-      prefix = "1.2.826.0.1.3680043.2.1143"
+      prefix = RootUID
    }
-   // else
+   else
+   {
+      prefix = root;
+   }
+
    // A root was specified use it to forge our new UID:
    append += ".";
    append += Util::GetMACAddress();
@@ -827,35 +860,17 @@ std::string Util::CreateUniqueUID(const std::string &root)
    return prefix + append;
 }
 
-unsigned int Util::GetCurrentThreadID()
+void Util::SetRootUID(const std::string &root)
 {
-// FIXME the implementation is far from complete
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-  return (unsigned int)GetCurrentThreadId();
-#endif
-#ifdef __linux__
-   return 0;
-   // Doesn't work on fedora, but is in the man page...
-   //return (unsigned int)gettid();
-#endif
-#ifdef __sun
-   return (unsigned int)thr_self();
-#else
-   //default implementation
-   return 0;
-#endif
+   if( root.empty() )
+      RootUID = GDCM_UID;
+   else
+      RootUID = root;
 }
 
-unsigned int Util::GetCurrentProcessID()
+const std::string &Util::GetRootUID()
 {
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-  // NOTE: There is also a _getpid()...
-  return (unsigned int)GetCurrentProcessId();
-#else
-  // get process identification, POSIX
-  return (unsigned int)getpid();
-#endif
-
+   return RootUID;
 }
 
 /**
index 129b14b28e0ac797699abd5148d62c2d73a8cf4f..997b8752071737828f232eafd9c00cc2789709f9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 16:06:21 $
-  Version:   $Revision: 1.50 $
+  Date:      $Date: 2005/01/28 09:37:29 $
+  Version:   $Revision: 1.51 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,13 +57,19 @@ public:
    static std::string DicomString(const char *s, size_t l);
    static std::string DicomString(const char *s);
    static bool        DicomStringEqual(const std::string &s1, const char *s2);
-   static std::string CreateUniqueUID(const std::string &root = "");
    static bool        IsCurrentProcessorBigEndian();
 
    static std::string GetMACAddress();
 
+   static std::string CreateUniqueUID(const std::string &root = "");
+   static void SetRootUID(const std::string &root = "");
+   static const std::string &GetRootUID();
+
 private:
    static std::string GetIPAddress(); //Do not expose this method
+
+   static std::string RootUID;
+   static const std::string GDCM_UID;
 };
 
    template <class T>