X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftags%2Fsynfig_0_61_07%2Fsrc%2Fsynfig%2Fguid.cpp;fp=synfig-core%2Ftags%2Fsynfig_0_61_07%2Fsrc%2Fsynfig%2Fguid.cpp;h=0000000000000000000000000000000000000000;hb=6fa8f2f38d4b0b35f8539bf94e27ae27015c7689;hp=cfac979727a55683925773c9e4935b3cd1a07cd9;hpb=47fce282611fbba1044921d22ca887f9b53ad91a;p=synfig.git diff --git a/synfig-core/tags/synfig_0_61_07/src/synfig/guid.cpp b/synfig-core/tags/synfig_0_61_07/src/synfig/guid.cpp deleted file mode 100644 index cfac979..0000000 --- a/synfig-core/tags/synfig_0_61_07/src/synfig/guid.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file guid.cpp -** \brief Template File -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2007 Chris Moore -** -** 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. -** -** 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 -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "guid.h" -#include "quick_rng.h" -#include -#include -#include -#include -#include -#include - -#ifdef _DEBUG -#include "general.h" -#endif - -#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; -#endif - -#ifdef _WIN32 -#include -#endif - -#endif - -/* === U S I N G =========================================================== */ - -using namespace std; -using namespace etl; -using namespace synfig; - -/* === M A C R O S ========================================================= */ - -#define MANUAL_GUID_CALC - -/* === G L O B A L S ======================================================= */ - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - -#define GUID_RNG quick_rng -//#define GUID_RNG subtractive_rng - - - -#ifdef MANUAL_GUID_CALC -#include -static GUID_RNG _a, _b; -static void _set_up_rand_long_long(uint64_t &x); -static void _get_rand_long_long(uint64_t &x); -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 - synfig::info("Starting up GUID system..."); -#endif - _a=GUID_RNG(time(0)+clock()); - _b=GUID_RNG(clock()); - get_rand_long_long=_get_rand_long_long; - _get_rand_long_long(x); -} - -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); -} - -#else -// Use OS-Dependent method - -#ifdef _WIN32 -// Win32 -static void get_rand_long_long(uint64_t &x) -{ - _GUID* guid(reinterpret_cast<_GUID*>(&x)); - CoCreateGuid(guid); -} - -#else -// Unix -static int rand_fd; -static void _set_up_rand_long_long(uint64_t &x); -static void _get_rand_long_long(uint64_t &x); -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 - synfig::info("Starting up GUID system..."); -#endif - rand_fd=open("/dev/urandom",O_RDONLY); - get_rand_long_long=_get_rand_long_long; - _get_rand_long_long(x); -} - -static void _get_rand_long_long(uint64_t &x){ read(rand_fd,&x,sizeof(x));} - -#endif -#endif - - - -void -synfig::GUID::make_unique() -{ - get_rand_long_long(data.u_64.a); - get_rand_long_long(data.u_64.b); -} - -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>(32-(i%24)))^(seed<<(i%24)) - } -#endif - - GUID_RNG random(seed); - GUID ret(0); - ret.data.u_32.a=random(~(unsigned int)0); - ret.data.u_32.b=random(~(unsigned int)0); - ret.data.u_32.c=random(~(unsigned int)0); - ret.data.u_32.d=random(~(unsigned int)0); - return ret; -} - -synfig::GUID -synfig::GUID::hasher(int i) -{ - GUID ret(0); - GUID_RNG random(i); - ret.data.u_32.a=random(~(unsigned int)0); - ret.data.u_32.b=random(~(unsigned int)0); - ret.data.u_32.c=random(~(unsigned int)0); - ret.data.u_32.d=random(~(unsigned int)0); - return ret; -} - -String -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); -} - -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); -}