Skip to content

Instantly share code, notes, and snippets.

@brenttaylor
Created May 17, 2012 02:23
Show Gist options
  • Save brenttaylor/2715742 to your computer and use it in GitHub Desktop.
Save brenttaylor/2715742 to your computer and use it in GitHub Desktop.
DarkGDK DBObject ID generator
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;
@brenttaylor
Copy link
Author

An example of a DarkGDK Object ID generator I used to use. Referenced here: http://www.leadwerks.com/werkspace/topic/4959-darkgdk/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment