Nearly all typical OO C++ code is just snazzy syntax around the old technique of creating libraries that created a "cookie" and required it to be passed into every call. So if none of the classes have virtual methods (no runtime dispatch) you should be able to do the following:
- Think of all class names as "facility" or "library" names.
- Put all data members of the class into a struct named classname (what the class used to be named)
- Turn all the methods into functions named classname_methodname.
- Add a pointer to the classname struct to the parameter list of all the functions (methods) for that class.
- Turn the constructors into a functions named classname_construct(# for overloads perhaps) and the destructor into a function named classname_destruct.
- Change all the method calls in other code from
objectname.methodname (...)
to classname_methodname (objecname, ...)
.
- This is the tricky part: You will have to put in code to call the destructors manually, since those are automagically called in C++.
Taking the example given in the comments:
class QtCommandData {
public:
QtCommandData(unsigned short net, unsigned short command,
unsigned long n_data_bytes, unsigned short flgs,
unsigned char* data = NULL);
QtCommandData();
~QtCommandData();
public:
unsigned char* m_pData;
int m_Async;
protected:
unsigned int m_nDataBytes;
unsigned int m_BytesAllocated;
protected:
int Fill_Trailer();
};
...becomes (I'll abbreviate the "facility name" from QtCommandData
to QtCD
):
typedef struct {
unsigned char* m_pData;
int m_Async;
unsigned int m_nDataBytes;
unsigned int m_BytesAllocated;
} QtCD;
QtCD_Construct(QtCD * handle,
unsigned short net, unsigned short command,
unsigned long n_data_bytes, unsigned short flgs,
unsigned char* data);
QtCD_Destruct(QtCD * handle);
QtCD_Fill_Trailer (QtCD * handle);
That's the general idea. Templates and dynamic dispatch and a few other things may throw you a monkeywrench or two, but I'm sure you are up to the challenge. :-)