實(shí)現(xiàn)原理
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、開平ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的開平網(wǎng)站制作公司Category和Class Extension的區(qū)別
Category添加的實(shí)例方法是存儲(chǔ)在其對應(yīng)的類對象里,類方法存儲(chǔ)在其對應(yīng)的元類對象里
Category添加的方法是在runtime過程中動(dòng)態(tài)添加的
Category編譯完成后結(jié)構(gòu)
多個(gè)分類
int mcount = 0;
int i = cats->count; // cats 為分類數(shù)組
while (i--) {
auto& entry = cats->list[i];
method_list_t *mlist = entry.cat->methodsFoMeta(isMeta);
mlists[mcount++] = mlist;
// 后編譯的分類方法先取出來添加到方法
// ...
}
struct _category_t {
const char *name;
struct _class_t *cls;
const struct _method_list_t *instance_methods;
const struct _method_list_t *class_methods;
const struct _protocol_list_t *protocols;
const struct _prop_list_t *properties;
};
void attachList(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (haveArray()) {
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
setArray((array_t *)realloc(array(), array_t::byteSize(newCount)));
array()->count = newCount;
memmove(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
memcopy(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
}
}
void attachLists(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (hasArray()) {
// many lists ->many lists
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
array_t *newArray = (array_t *)malloc(array_t::byteSize(newCount));
newArray->count = newCount;
array()->count = newCount;
for (int i = oldCount - 1; i >= 0; i--)
newArray->lists[i + addedCount] = array()->lists[i];
for (unsigned i = 0; i< addedCount; i++)
newArray->lists[i] = addedLists[i];
free(array());
setArray(newArray);
validate();
}
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
網(wǎng)站欄目:Category-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://bm7419.com/article32/dicdpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)頁設(shè)計(jì)公司、搜索引擎優(yōu)化、網(wǎng)站排名、移動(dòng)網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容