/*! \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 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 <ext/hash_map>
#define SUBTRACT_RNG_H <ext/functional>
#ifdef USING_PCH
#endif
#include "guid.h"
+#include "quick_rng.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HASH_MAP_H
#include HASH_MAP_H
-using namespace __gnu_cxx;
#endif
#ifdef SUBTRACT_RNG_H
/* === 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
static void _set_up_rand_long_long(uint64_t &x)
{
#ifdef _DEBUG
- synfig::info("Starting up GUID system...");
+ // synfig::info("Starting up GUID system...");
#endif
_a=GUID_RNG(time(0)+clock());
_b=GUID_RNG(clock());
{
//subtractive_rng _c(clock());
unsigned short* data(reinterpret_cast<unsigned short *>(&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
static void get_rand_long_long(uint64_t &x)
{
_GUID* guid(reinterpret_cast<_GUID*>(&x));
- CoCreateGuid(guid);
+ CoCreateGuid(guid);
}
#else
static void _set_up_rand_long_long(uint64_t &x)
{
#ifdef _DEBUG
- synfig::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;
synfig::GUID
synfig::GUID::hasher(const String& str)
-{
+{
#ifdef HASH_MAP_H
- hash<const char*> string_hash_;
+ HASH_MAP_NAMESPACE::hash<const char*> string_hash_;
const unsigned int seed(
string_hash_(
str.c_str()
seed=(seed>>(32-(i%24)))^(seed<<(i%24))
}
#endif
-
+
GUID_RNG random(seed);
GUID ret(0);
ret.data.u_32.a=random(~(unsigned int)0);