I have an event class that I am trying to make available in python using Boost.Python. Here is a list, as well as related macros and an example event class.
class Event
{
private:
unsigned __int64 m_TimeStamp;
public:
struct Params { };
Event();
virtual unsigned int Type() const = 0;
virtual const char* TypeName() const = 0;
unsigned __int64 TimeStamp() const { return m_TimeStamp; }
};
typedef shared_ptr<Event> EventPtr;
#define DECLARE_EVENTTYPE(typeName, id) \
enum { TYPE = id }; \
unsigned int Type() const { return static_cast<unsigned int>(id); } \
const char* TypeName() const { return typeName; }
#define START_EVENTPARAMS() struct Params : public Event::Params {
#define END_EVENTPARAMS(eventName) \
} m_Params; \
eventName(const Event::Params* pkParams = NULL) : Event() \
{ \
if (NULL != pkParams) \
{ \
const eventName::Params* pkEventParams = \
reinterpret_cast<const eventName::Params*>(pkParams); \
if (NULL != pkEventParams) \
m_Params = *pkEventParams; \
} \
} \
static const eventName::Params& Parameters(const EventPtr pkEvent) \
{ \
const shared_ptr<eventName> pkErrorEvent( \
dynamic_pointer_cast<eventName>(pkEvent)); \
return pkErrorEvent->m_Params; \
}
#define EVENT_NOPARAMS(eventName) \
eventName(const Event::Params*) : Event() { }
struct ExampleEvent : public Event
{
START_EVENTPARAMS()
std::string m_strMsg;
END_EVENTPARAMS(ExampleEvent)
DECLARE_EVENTTYPE("ExampleEvent", 1);
};
The goal is that I want to be able to derive python-based event classes from this, however the mechanism for declaring and using event parameters is built into macros. Honestly, I do not think that the way it is configured in C ++ will work in python anyway, since any parameters that the event would have in python are likely to be stored in a dictionary.
Is there a way to export this function using boost.python or is there a better way to create a class to support common parameters that will work well in C ++ and Python?