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 17:29:59 $
+ Version: $Revision: 1.127 $
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 <algorithm>
// For GetCurrentDate, GetCurrentTime
#include <time.h>
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:
// 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)
{
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);
- }
- // Since we push back the proper number is reversed:
- std::reverse(sres.begin(),sres.end());
+ {
+ res = getlastdigit(addr);
+ sres.insert(sres.begin(), '0' + res);
+ zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0);
+ }
return sres;
}
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
*/
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();
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;
}
/**