X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fguid.cpp;h=e537ba661410cfbd2cfc567e768b4ca88c793c34;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=0c94eb55fb53ef05bc006b95ea9748ec238d8757;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/guid.cpp b/synfig-core/trunk/src/synfig/guid.cpp index 0c94eb5..e537ba6 100644 --- a/synfig-core/trunk/src/synfig/guid.cpp +++ b/synfig-core/trunk/src/synfig/guid.cpp @@ -1,29 +1,28 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file guid.cpp ** \brief Template File ** -** $Id: guid.cpp,v 1.4 2005/01/13 06:48:39 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ /* === H E A D E R S ======================================================= */ -#define HASH_MAP_H -#define SUBTRACT_RNG_H - #ifdef USING_PCH # include "pch.h" #else @@ -32,6 +31,7 @@ #endif #include "guid.h" +#include "quick_rng.h" #include #include #include @@ -45,12 +45,7 @@ #ifdef HASH_MAP_H #include HASH_MAP_H -using namespace __gnu_cxx; -#endif - -#ifdef SUBTRACT_RNG_H -#include SUBTRACT_RNG_H -using namespace __gnu_cxx; +#include FUNCTIONAL_H #endif #ifdef _WIN32 @@ -63,7 +58,7 @@ using namespace __gnu_cxx; using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -75,50 +70,6 @@ using namespace sinfg; /* === M E T H O D S ======================================================= */ -// A fast 32-bit linear congruential random number generator -class quick_rng -{ - unsigned long next; -public: - quick_rng(unsigned long seed=0):next(seed) { } - - void set_seed(unsigned long x) - { - next=x; - } - - unsigned long i32() - { - static const unsigned long a(1664525); - static const unsigned long c(1013904223); - - return next=next*a+c; - } - - unsigned long i16() - { - return i32()>>16; - } - - float f() - { - static const float m(int(65535)); - - return float(i16())/m; - } - - unsigned long operator()(const unsigned long& m) - { - if(m==65536) - return i16(); - else - if(m<=65536) - return i16()%m; - else - return i32()%m; - } -}; - #define GUID_RNG quick_rng //#define GUID_RNG subtractive_rng @@ -133,7 +84,7 @@ static void (*get_rand_long_long)(uint64_t&)=_set_up_rand_long_long; static void _set_up_rand_long_long(uint64_t &x) { #ifdef _DEBUG - sinfg::info("Starting up GUID system..."); + // synfig::info("Starting up GUID system..."); #endif _a=GUID_RNG(time(0)+clock()); _b=GUID_RNG(clock()); @@ -145,10 +96,10 @@ static void _get_rand_long_long(uint64_t &x) { //subtractive_rng _c(clock()); unsigned short* data(reinterpret_cast(&x)); - data[0]=_a(65536); - data[1]=_a(65536); - data[2]=_a(65536); - data[3]=_a(65536); + data[0]=_a(65536); + data[1]=_a(65536); + data[2]=_a(65536); + data[3]=_a(65536); } #else @@ -159,7 +110,7 @@ static void _get_rand_long_long(uint64_t &x) static void get_rand_long_long(uint64_t &x) { _GUID* guid(reinterpret_cast<_GUID*>(&x)); - CoCreateGuid(guid); + CoCreateGuid(guid); } #else @@ -171,7 +122,7 @@ static void (*get_rand_long_long)(uint64_t&)=_set_up_rand_long_long; static void _set_up_rand_long_long(uint64_t &x) { #ifdef _DEBUG - sinfg::info("Starting up GUID system..."); + // synfig::info("Starting up GUID system..."); #endif rand_fd=open("/dev/urandom",O_RDONLY); get_rand_long_long=_get_rand_long_long; @@ -186,31 +137,42 @@ static void _get_rand_long_long(uint64_t &x){ read(rand_fd,&x,sizeof(x));} void -sinfg::GUID::make_unique() +synfig::GUID::make_unique() { get_rand_long_long(data.u_64.a); get_rand_long_long(data.u_64.b); } -sinfg::GUID -sinfg::GUID::hasher(const String& str) -{ +synfig::GUID +synfig::GUID::hasher(const String& str) +{ #ifdef HASH_MAP_H - hash string_hash_; - const unsigned int seed( - string_hash_( - str.c_str() - ) - ); -#else - const unsigned int seed(0x3B642879); - for(int i=0;i string_hash_; + const unsigned int seed(string_hash_(str)); +# else // FUNCTIONAL_HASH_ON_STRING + HASH_MAP_NAMESPACE::hash string_hash_; + const unsigned int seed(string_hash_(str.c_str())); +# endif // FUNCTIONAL_HASH_ON_STRING +#else // HASH_MAP_H + unsigned int seed(0x3B642879); + for(unsigned int i=0;i>(32-(i%24)))^(seed<<(i%24)) + seed^=(seed*str[i])*i; + seed=(seed>>(32-(i%24)))^(seed<<(i%24)); } -#endif - +#endif // HASH_MAP_H + GUID_RNG random(seed); GUID ret(0); ret.data.u_32.a=random(~(unsigned int)0); @@ -220,8 +182,8 @@ sinfg::GUID::hasher(const String& str) return ret; } -sinfg::GUID -sinfg::GUID::hasher(int i) +synfig::GUID +synfig::GUID::hasher(int i) { GUID ret(0); GUID_RNG random(i); @@ -233,12 +195,12 @@ sinfg::GUID::hasher(int i) } String -sinfg::GUID::get_string()const +synfig::GUID::get_string()const { return strprintf("%08X%08X%08X%08X",data.u_32.a,data.u_32.b,data.u_32.c,data.u_32.d); } -sinfg::GUID::GUID(const String &str) +synfig::GUID::GUID(const String &str) { strscanf(str,"%08X%08X%08X%08X",&data.u_32.a,&data.u_32.b,&data.u_32.c,&data.u_32.d); }