Subject: RFC: getting a unique integer value
From: Matti Picus (matti@picus.org)
Date: Fri Oct 12 2001 - 03:22:43 CDT
Generating a unique int ID seems to be faulty in many places in AbiWord.
The general method is to use the result from UT_rand() and hope that it is
unique. I recently modified the RTF importer with a different method:
using a static member variable.
I hope the construct is portable to all platforms.
Here is what it looks like:
-------- NeedToIncrement.h-----------------
class NeedToIncrement
{
static UT_uint32 m_incrementer;
UT_uint32 m_ID;
}
-----------------------------------------
--------NeedToIncrement.cpp---------------
NeedToImcrement::NeedToIncrement()
{
m_ID = m_incrementer++;
}
// Static data members must be initialized at file scope.
UT_uint32 NeedToImcrement::m_incrementer = 100;
-------------------------------------------
Any comments?
Matti
This archive was generated by hypermail 2b25 : Fri Oct 12 2001 - 03:27:45 CDT