brew物件導向C實現的巨集定義展開

2021-05-22 01:02:23 字數 3428 閱讀 4759

1.示例c語言源**實現:

typedef struct _iwindow  iwindow;

qinte***ce(iwindow)

// enables/disables the window. window controls will not process

// events if the window is disabled.

void     (*enable)(iwindow * po, boolean benable);

// redraws the window if enabled

void     (*redraw)(iwindow * po);

// handles the events routed to the window

boolean  (*handleevent)(iwindow * po, aeeevent ecode, uint16 wparam, uint32 dwparam);

// releases the window resources

void     (*delete)(iwindow * po);

#define iwindow_enable(p)                 get_pvtbl(p, iwindow)->enable(p, true)

#define iwindow_disable(p)                get_pvtbl(p, iwindow)->enable(p, false)

#define iwindow_redraw(p)                 get_pvtbl(p, iwindow)->redraw(p)

#define iwindow_handleevent(p, e, w, dw)  get_pvtbl(p, iwindow)->handleevent(p, e, w, dw)

#define iwindow_delete(p)                 get_pvtbl(p, iwindow)->delete(p)

#define inherit_cwindow(iname) /

declare_vtbl(iname) /

cmediaplayer * m_powner; /

ishell *       m_pishell; /

idisplay *     m_pidisplay; /

***            m_bactive:1

// base class of all iwindow objects.

struct cwindow

inherit_cwindow(iwindow);

// main window: displays main menu.

struct cmainwin

inherit_cwindow(iwindow);

iimage *       m_plogo;

aeerect        m_rectlogo;

imenuctl *     m_pmainmenu;

***            m_babout:1;

2.相關巨集定義內容

#define qinte***ce(iname) struct _##iname {/

struct vtbl(iname)  *pvt; /

typedef struct vtbl(iname) vtbl(iname); /

struct vtbl(iname)

#define vtbl(iname) iname##vtbl

3.展開後內容

struct _iwindow

struct iwindowvtbl  *pvt;

typedef struct iwindowvtbl iwindowvtbl;

struct iwindowvtbl

// enables/disables the window. window controls will not process

// events if the window is disabled.

void     (*enable)(iwindow * po, boolean benable);

// redraws the window if enabled

void     (*redraw)(iwindow * po);

// handles the events routed to the window

boolean  (*handleevent)(iwindow * po, aeeevent ecode, uint16 wparam, uint32 dwparam);

// releases the window resources

void     (*delete)(iwindow * po);

iwindow_enable(p)

((iwindow*)(void*)p)->pvt->enable(p,true);

#define iwindow_enable(p)                 get_pvtbl(p, iwindow)->enable(p, true)

#define iwindow_disable(p)                get_pvtbl(p, iwindow)->enable(p, false)

#define iwindow_redraw(p)                 get_pvtbl(p, iwindow)->redraw(p)

#define iwindow_handleevent(p, e, w, dw)  get_pvtbl(p, iwindow)->handleevent(p, e, w, dw)

#define iwindow_delete(p)                 get_pvtbl(p, iwindow)->delete(p)

#define declare_vtbl(iname)      iname   vt##iname;

iwindow vtiwindow

#define inherit_cwindow(iwindow)

expand:

iwindow vtiwindow   

cmediaplayer * m_powner;

ishell *       m_pishell;

idisplay *     m_pidisplay;

***            m_bactive:1

struct cwindow

inherit_cwindow(iwindow);

struct cwindow

iwindow vtiwindow;  //iwindowvtbl* pvt 

ishell *       m_pishell;

idisplay *     m_pidisplay;  

sizeof(cwindow) = 12;

c實現物件導向

c語言的結構體裡面沒有函式,但是c 裡面有函式,所以今天實現乙個c語言物件導向的程式 1 封裝 include include include typedef struct cmd newcmd void run newcmd pcmd void print newcmd pcmd int main...

Android SQLite實現物件導向CRUD

android中sqlite的使用,事實上倒也不難。可是與jdbc運算元據庫相比,這個還是有點不順手,並且我好久沒寫底層的封裝了,使用ssm框架這些都不須要考慮.好了,廢話不多說。以下直接建立乙個測試project來試試sqlite在android中的應用吧。1 新建乙個project 2 配置ju...

關於物件導向的定義

c 中關於物件導向的定義 1.lippman c 的第乙個編譯器cfront的參與開發者,c prime作者 c 通過class的pointers和refrences來支援多型,這種程式設計風格就稱為 物件導向 深度探索c 物件模型p34。文中還提到了其他其中程式設計模型 程式模型即面向過程 抽象資...