Created
June 22, 2011 05:22
-
-
Save hpcx82/1039556 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <string.h> | |
#define RUNTIME_TYPE_ID_ROOT(typestr) \ | |
static const char* Type() {return typestr;} \ | |
virtual bool IsKindOf(const char* typeName) {return 0 == strcmp(typeName, Type());} | |
// how about multiple inheritance | |
#define RUNTIME_TYPE_ID(typestr, baseclass) \ | |
static const char* Type() {return typestr;} \ | |
virtual bool IsKindOf(const char* typeName) {return (0 == strcmp(typeName, Type())) || baseclass::IsKindOf(typeName);} | |
class IObject | |
{ | |
public: | |
virtual ~IObject() {} | |
RUNTIME_TYPE_ID_ROOT("IObject"); | |
}; | |
class IGeometry: public IObject | |
{ | |
public: | |
RUNTIME_TYPE_ID("IGeometry", IObject); | |
}; | |
class IStyle: public IObject | |
{ | |
public: | |
RUNTIME_TYPE_ID("IStyle", IObject); | |
}; | |
class IBrep: public IGeometry | |
{ | |
public: | |
RUNTIME_TYPE_ID("IBrep", IGeometry); | |
}; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
IBrep* pBrep = new IBrep; | |
IStyle* pStyle = new IStyle; | |
bool bOk = false; | |
bOk = pBrep->IsKindOf(IBrep::Type()); | |
bOk = pBrep->IsKindOf(IGeometry::Type()); | |
bOk = pBrep->IsKindOf(IObject::Type()); | |
bOk = pBrep->IsKindOf(IStyle::Type()); | |
bOk = pStyle->IsKindOf(IStyle::Type()); | |
bOk = pStyle->IsKindOf(IObject::Type()); | |
bOk = pStyle->IsKindOf(IGeometry::Type()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment