rc_t KeyRingDataInsertObject(ObjectTable* data, uint32_t p_id, const String* name, const String* project, const String* display_name, uint64_t size, const String* checksum, const String* encryption_key) { rc_t rc = 0; Object* obj = (Object*) malloc(sizeof(Object)); if (obj != NULL) { rc = ObjectInit(obj, p_id, name, project, display_name, size, checksum, encryption_key); if (rc == 0) { rc = BSTreeInsert(data, &obj->dad, SortObjects); if (rc != 0) ProjectWhack(&obj->dad, NULL); } else free(obj); } else rc = RC ( rcApp, rcDatabase, rcUpdating, rcMemory, rcExhausted ); return rc; }
People* PeopleInit(People* p,int age){ ObjectInit((Object*)p); p->age = age; p->sayHello = PeopleSayHello; p->onDelete = PeopleOnDelete; return p; }
void IntegerInit(Integer self) { static struct integer model; if (model.objectName == NULL) { ObjectInit(&model); /* Overrides. */ model.objectSize = sizeof (struct integer); model.objectName = "Integer"; model.clone = IntegerClone; model.equals = IntegerEquals; model.compare = IntegerCompare; model.hashcode = IntegerHashcode; /* Methods */ #ifdef REALLY_WANT_ACCESSORS_FOR_PUBLIC_INSTANCE_VARIABLE model.objectMethodCount += 2; model.set = IntegerSet; model.get = IntegerGet; #endif /* Instance variables. */ model.value = 0; } *self = model; }
void DataInit(Data self) { static struct data model; if (model.objectName != DataName) { ObjectInit(&model); /* Overrides */ model.objectSize = sizeof (struct data); model.objectName = DataName; model.clone = DataClone; model.equals = DataEquals; model.compare = DataCompare; model.hashcode = DataHashcode; /* Methods */ model.base = DataBase; model.length = DataLength; model.objectMethodCount += 2; #ifdef ASSERT_STATIC_MEMBERS_ARE_NULL /* Instance variables. */ model._base = NULL; model._length = 0; #endif } *self = model; }
void ArrayInit(Array *arr) { ObjectInit((Object*)arr); arr->_length = 0; arr->_cap = 100; arr->_index = 0; arr->onDestory = &ArrayOnDestory; arr->_arr = malloc(sizeof(void*)*arr->_cap); }
bool Direct3DInit(HWND hwnd) { LPDIRECT3D9 pD3D9 = Direct3DCreate9(D3D_SDK_VERSION); if (pD3D9 == nullptr) { return false; } D3DCAPS9 caps; if (FAILED(pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps))) { return false; } int vp = 0; if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; } else { vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.BackBufferWidth = WINDOW_WIDTH; d3dpp.BackBufferHeight = WINDOW_HEIGHT; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hwnd; d3dpp.Windowed = true; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; if (FAILED(pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, vp, &d3dpp, &gPD3DDevice))) { return false; } SAFE_RELEASE(pD3D9); if (!ObjectInit(hwnd)) { return false; } return true; }
int main(int argc, char **argv) { int x, y; Object a, b, c; struct object obj; printf("\n--Object--\n"); printf("init local stack object\n"); ObjectInit(&obj); printf("destroy local stack object\n"); obj.destroy(&obj); printf("create dynamic object"); isNotNull((a = ObjectCreate())); printf("destroy dynamic object\n"); a->destroy(a); printf("create b"); isNotNull((b = ObjectCreate())); printf("clone c from b"); isNotNull((c = b->clone(b))); printf("reflexive: b equals self...%s\n", b->equals(b, b) ? "OK" : "FAIL"); printf("reflexive: c equals self...%s\n", c->equals(c, c) ? "OK" : "FAIL"); printf("b not equal NULL...%s\n", !b->equals(b, NULL) ? "OK" : "FAIL"); printf("c not equal NULL...%s\n", !c->equals(c, NULL) ? "OK" : "FAIL"); printf("b not equal c...%s\n", !b->equals(b, c) ? "OK" : "FAIL"); printf("c not equal b...%s\n", !c->equals(c, b) ? "OK" : "FAIL"); printf("b compared to b is %d...%s\n", b->compare(b, b), b->compare(b, b) == 0 ? "OK" : "FAIL"); printf("c compared to c is %d...%s\n", c->compare(c, c), c->compare(c, c) == 0 ? "OK" : "FAIL"); printf("b compared to c is %d\n", x = b->compare(b, c)); printf("c compared to b is %d\n", y = c->compare(c, b)); printf("b compared c equals -(c compared to b)...%s\n", x == -y ? "OK" : "FAIL"); printf("hashcodes for b and c are different...%s\n", b->hashcode(b) != c->hashcode(c) ? "OK" : "FAIL"); printf("destroy b & c\n"); b->destroy(b); c->destroy(c); printf("\n--DONE--\n"); return 0; }
/** * Create and initialise a new Object. * * @return * An object; otherwise null on error. */ Object ObjectCreate(void) { Object self; if ((self = malloc(sizeof (*self))) == NULL) return NULL; ObjectInit(self); /*@-type@*/ self->destroy = free; /*@=type@*/ return self; }
/*========================================================================*/ ObjectCallback *ObjectCallbackNew(PyMOLGlobals * G) { OOAlloc(G, ObjectCallback); ObjectInit(G, (CObject *) I); I->State = VLACalloc(ObjectCallbackState, 10); /* autozero */ I->NState = 0; I->Obj.type = cObjectCallback; I->Obj.fFree = (void (*)(CObject *)) ObjectCallbackFree; I->Obj.fUpdate = (void (*)(CObject *)) ObjectCallbackUpdate; I->Obj.fRender = (void (*)(CObject *, RenderInfo *)) ObjectCallbackRender; I->Obj.fGetNFrame = (int (*)(CObject *)) ObjectCallbackGetNStates; return (I); }
bool Direct3DInit(HWND hwnd, HINSTANCE hInstance) { LPDIRECT3D9 pD3D9; pD3D9 = Direct3DCreate9(D3D_SDK_VERSION); if (pD3D9 == nullptr) { return false; } D3DCAPS9 caps; if (FAILED(pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps))) { return false; } int vp = 0; if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; } else { vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.BackBufferWidth = WINDOW_WIDTH; d3dpp.BackBufferHeight = WINDOW_HEIGHT; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 2; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hwnd; d3dpp.Windowed = true; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; if (FAILED(pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, vp, &d3dpp, &gPD3DDevice))) { return false; } D3DADAPTER_IDENTIFIER9 ident; pD3D9->GetAdapterIdentifier(0, 0, &ident); int len = MultiByteToWideChar(CP_ACP, 0, ident.Description, -1, 0, 0); MultiByteToWideChar(CP_ACP, 0, ident.Description, -1, gStrAdapterDesc, len); DirectInput8Create(hInstance, 0x0800, IID_IDirectInput8, (void**)&gPDirectInput, nullptr); gPDirectInput->CreateDevice(GUID_SysMouse, &gPMouseInput, nullptr); gPMouseInput->SetDataFormat(&c_dfDIMouse); gPMouseInput->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); gPMouseInput->Acquire(); gPDirectInput->CreateDevice(GUID_SysKeyboard, &gPKeyboardInput, nullptr); gPKeyboardInput->SetDataFormat(&c_dfDIKeyboard); gPKeyboardInput->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_NONEXCLUSIVE); gPKeyboardInput->Acquire(); if (!ObjectInit(hwnd)) { return false; } SAFE_RELEASE(pD3D9); return true; }
void TextInitEmptyString(Text self) { static struct text model; if (model.objectName == NULL) { ObjectInit(&model); /* Overrides. */ model.objectSize = sizeof (struct text); model.objectName = "Text"; model.clone = TextClone; model.compare = TextCompareCase; model.equals = TextEqualsCase; model.hashcode = TextHashcodeCase; /* Methods */ model.string = TextString; model.length = TextLength; model.isBlank = text_is_blank; model.isInteger = TextIsInt; model.getOctet = TextGetOctet; model.setOctet = TextSetOctet; model.append = TextAppend; model.appendC = TextAppendC; model.getIgnoreCase = TextGetIgnoreCase; model.setIgnoreCase = TextSetIgnoreCase; model.compareCase = TextCompareCase; model.compareCaseC = TextCompareCaseC; model.compareIgnoreCase = TextCompareIgnoreCase; model.compareIgnoreCaseC = TextCompareIgnoreCaseC; model.equalsCase = TextEqualsCase; model.equalsIgnoreCase = TextEqualsIgnoreCase; model.hashcodeCase = TextHashcodeCase; model.hashcodeIgnoreCase = TextHashcodeIgnoreCase; model.compareCaseN = TextCompareCaseN; model.compareCaseNC = TextCompareCaseNC; model.compareIgnoreCaseN = TextCompareIgnoreCaseN; model.compareIgnoreCaseNC = TextCompareIgnoreCaseNC; model.findCase = TextFindCase; model.findCaseC = TextFindCaseC; model.findIgnoreCase = TextFindIgnoreCase; model.findIgnoreCaseC = TextFindIgnoreCaseC; model.endsWithCase = TextEndsWithCase; model.endsWithCaseC = TextEndsWithCaseC; model.endsWithIgnoreCase = TextEndsWithIgnoreCase; model.endsWithIgnoreCaseC = TextEndsWithIgnoreCaseC; model.startsWithCase = TextStartsWithCase; model.startsWithCaseC = TextStartsWithCaseC; model.startsWithIgnoreCase = TextStartsWithIgnoreCase; model.startsWithIgnoreCaseC = TextStartsWithIgnoreCaseC; model.invertCase = TextInvertCase; model.lowerCase = TextLowerCase; model.upperCase = TextUpperCase; model.reverse = TextReverseRegion; model.substring = TextGetSubstring; model.resetTokens = TextResetTokens; model.hasMoreTokens = TextHasMoreTokens; model.nextToken = TextNextToken; model.nextTokenC = TextNextTokenC; model.split = TextSplitOn; model.splitC = TextSplitOnC; model.objectMethodCount += 45; /* Instance variables. */ #ifdef ASSERT_STATIC_MEMBERS_ARE_NULL model._nextToken = NULL; model._string = NULL; model._length = 0; #endif } *self = model; }
bool Direct3DInit(HWND hwnd) { ////////////////////////////////////////////////////////////////////////// // D3D Init step1: D3D9 ////////////////////////////////////////////////////////////////////////// LPDIRECT3D9 pD3D9 = Direct3DCreate9(D3D_SDK_VERSION); if (pD3D9 == nullptr) { return false; } ////////////////////////////////////////////////////////////////////////// // D3D Init Step2: caps&vp ////////////////////////////////////////////////////////////////////////// D3DCAPS9 caps; if (FAILED(pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps))) { return false; } int vp; if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; } else { vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; } ////////////////////////////////////////////////////////////////////////// // D3D Init step3: parameter ////////////////////////////////////////////////////////////////////////// D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = WINDOW_WIDTH; d3dpp.BackBufferHeight = WINDOW_HEIGHT; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hwnd; d3dpp.Windowed = true; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; ////////////////////////////////////////////////////////////////////////// // D3D Init step4: createDevice with vp&D3D9&presentParameters ////////////////////////////////////////////////////////////////////////// if (FAILED(pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, vp, &d3dpp, &gPD3DDevice))) { return false; } SAFE_RELEASE(pD3D9); //gPD3DDevice->SetRenderState(D3DRS_LIGHTING, false); //关闭光照 //gPD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); //背面消隐 //gPD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); if (!ObjectInit(hwnd)) { return -1; } return true; }