Created
May 17, 2012 02:23
-
-
Save brenttaylor/2715742 to your computer and use it in GitHub Desktop.
DarkGDK DBObject ID generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef unsigned int DBObjectID; | |
class DBObject { | |
private: | |
static DBObjectID IDCounter; | |
static std::list<DBObjectID> RecycledIDs; | |
protected: | |
const DBObjectID ID; | |
public: | |
DBObject() : ID(GetNewID()) { | |
} | |
static DBObjectID GetNewID() { | |
DBObjectID TempID; | |
if (RecycledIDs.empty()) { | |
TempID = IDCounter++; | |
} | |
else { | |
TempID = RecycledIDs.front(); | |
RecycledIDs.pop_front(); | |
} | |
return TempID; | |
} | |
~DBObject() { | |
RecycledIDs.push_back(ID); | |
} | |
}; | |
DBObjectID DBObject::IDCounter = 1; | |
std::list<DBObjectID> DBObject::RecycledIDs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of a DarkGDK Object ID generator I used to use. Referenced here: http://www.leadwerks.com/werkspace/topic/4959-darkgdk/