diff --git a/Core/Code/Algorithms/mitkUIDGenerator.cpp b/Core/Code/Algorithms/mitkUIDGenerator.cpp index 58fd873075..c41afcee4a 100644 --- a/Core/Code/Algorithms/mitkUIDGenerator.cpp +++ b/Core/Code/Algorithms/mitkUIDGenerator.cpp @@ -1,119 +1,118 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include -#include #include #include #include #include #include #ifdef WIN32 #include "process.h" #endif namespace mitk { UIDGenerator::UIDGenerator(const char* prefix, unsigned int lengthOfRandomPart) :m_Prefix(prefix), m_LengthOfRandomPart(lengthOfRandomPart) { if (lengthOfRandomPart < 5) { MITK_ERROR << "To few digits requested (" <tm_year + 1900; if (t->tm_mon < 9) s << "0"; // add a 0 for months 1 to 9 s << t->tm_mon + 1; if (t->tm_mday < 10) s << "0"; // add a 0 for days 1 to 9 s << t->tm_mday; if (t->tm_hour < 10) s << "0"; // add a 0 for hours 1 to 9 s << t->tm_hour; if (t->tm_min < 10) s << "0"; // add a 0 for minutes 1 to 9 s << t->tm_min; if (t->tm_sec < 10) s << "0"; // add a 0 for seconds 1 to 9 s << t->tm_sec; std::ostringstream rs; rs << (long int)( pow(10.0, double(m_LengthOfRandomPart)) / double(RAND_MAX) * double(rand()) ); for (size_t i = rs.str().length(); i < m_LengthOfRandomPart; ++i) { s << "X"; } s << rs.str(); } return s.str(); } } -unsigned int UIDGenerator::hash( time_t t, clock_t c ) +unsigned int UIDGenerator::seedhash( time_t t, clock_t c ) { unsigned int h1 = 0; unsigned char *p = (unsigned char *) &t; for( size_t i = 0; i < sizeof(t); ++i ) { h1 *= UCHAR_MAX + 2U; h1 += p[i]; } unsigned int h2 = 0; p = (unsigned char *) &c; for( size_t j = 0; j < sizeof(c); ++j ) { h2 *= UCHAR_MAX + 2U; h2 += p[j]; } return h1 ^ h2; } diff --git a/Core/Code/Algorithms/mitkUIDGenerator.h b/Core/Code/Algorithms/mitkUIDGenerator.h index de1c78f52c..992b1dac95 100644 --- a/Core/Code/Algorithms/mitkUIDGenerator.h +++ b/Core/Code/Algorithms/mitkUIDGenerator.h @@ -1,59 +1,60 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITK_UID_GENERATOR_INDCLUDED_FASAWE #define MITK_UID_GENERATOR_INDCLUDED_FASAWE #include +#include #include #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4251) #endif namespace mitk { /*! \brief Generated unique IDs Creates (somehow most of the time) unique IDs from a given prefix, the current date/time and a random part. The prefix is given to the constructor, together with the desired length of the random part (minimum 5 digits). You will get another quite unique ID each time you call GetUID. */ class MITK_CORE_EXPORT UIDGenerator { public: UIDGenerator(const char* prefix = "UID_", unsigned int lengthOfRandomPart = 8); std::string GetUID(); private: std::string m_Prefix; unsigned int m_LengthOfRandomPart; - unsigned int hash( time_t t, clock_t c ); + unsigned int seedhash( time_t t, clock_t c ); }; } #ifdef _MSC_VER # pragma warning(pop) #endif #endif