custom RTTI - using the preprocessor

Started by
3 comments, last by supagu 16 years, 4 months ago
i have my own run time type info. system which goes something like this:

class BaseClass
{
enum
	{
		Type = -1,
		ParentType = -1,
	};

	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

class ClassA : public BaseClass
{
enum
	{
		Type = 1,
		ParentType = BaseClass::Type,
	};


	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

class ClassB : public ClassA
{
enum
	{
		Type = 2,
		ParentType = ClassA::Type,
	};


	virtual unsigned int GetType() { return Type; }
	virtual unsigned int GetParentType() { return ParentType; }
};

now, i want to change this to use macros, and i want the preprocessor to generate the Type = xxx I saw a thread on here once about a preprocessor macro that would increment a value each time it was used, but i forgot what it was.
Advertisement
In Visual C++, you have the __COUNTER__ predefined macro.
__COUNTER__ is almost certainly reset for each compilation unit though, so you'll probably need to define all of your IDs in one unit (Or header and make sure that __COUNTER__ isn't used elsewhere).
Look into Loki typelists.
i assume __COUNTER__ is microsoft specific, better than nothing for now though :) . Would also be nice if there was a general cross platform solution.

Can you explain further how this typelists' can be used for RTTI?

This topic is closed to new replies.

Advertisement