00001 #ifndef SWOBJECT_H 00002 #define SWOBJECT_H 00003 00004 #include <utilfuns.h> 00005 #if !defined(__GNUC__) && !defined(_WIN32_WCE) 00006 #else 00007 #include <unixstr.h> 00008 #endif 00009 00010 #include <defs.h> 00011 #include <string.h> 00012 00013 #define SWDYNAMIC_CAST(className, object) (className *)((object)?((object->getClass()->isAssignableFrom(#className))?object:0):0) 00014 00018 class SWDLLEXPORT SWClass { 00019 private: 00020 const char **descends; 00021 00022 public: 00023 SWClass(const char **descends) { 00024 this->descends = descends; 00025 } 00026 00027 bool isAssignableFrom(const char *className) const { 00028 for (int i = 0; descends[i]; i++) { 00029 if (!stricmp(descends[i], className)) 00030 return true; 00031 } 00032 return false; 00033 } 00034 }; 00035 00041 class SWObject { 00042 protected: 00043 SWClass * myclass; 00044 00045 public: 00049 const SWClass *getClass () const { 00050 return myclass; 00051 } 00052 }; 00053 00054 #endif