void CBaseControl::InsertChildAtIndex(const CBaseControlPtr & control, unsigned index) { if (!control) { throw std::invalid_argument("Invalid control"); } if (control.get() == this) { throw std::invalid_argument("Can not insert itself as a child"); } if (IsItOneOfMyParents(control)) { throw std::invalid_argument("Can not insert any control parent as a child"); } const bool itIsMyChild = (control->GetParent().get() == this); if (itIsMyChild) { ChangeChildIndex(control, index); } else { AdoptChild(control, index); } }
/*! ****************************************************************************** @Function PVRSRVAllocSubHandle @Description Allocate a subhandle @Input phHandle - location for new subhandle pvData - pointer to resource to be associated with the subhandle eType - the type of resource hParent - parent handle @Output phHandle - points to new subhandle @Return Error code or PVRSRV_OK ******************************************************************************/ PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_HANDLE hParent) { HANDLE_DATA *psPHandleData = IMG_NULL; HANDLE_DATA *psCHandleData = IMG_NULL; IMG_HANDLE hParentKey; IMG_HANDLE hHandle; PVRSRV_ERROR eError; *phHandle = IMG_NULL; /* PVRSRV_HANDLE_TYPE_NONE is reserved for internal use */ PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE); PVR_ASSERT(gpsHandleFuncs); if (psBase == IMG_NULL) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Missing handle base")); eError = PVRSRV_ERROR_INVALID_PARAMS; goto err; } hParentKey = TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_PRIVATE) ? hParent : IMG_NULL; /* Lookup the parent handle */ eError = GetHandleData(psBase, &psPHandleData, hParent, PVRSRV_HANDLE_TYPE_NONE); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure")); goto err; } if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI)) { /* See if there is already a handle for this data pointer */ hHandle = FindHandle(psBase, pvData, eType, hParentKey); if (hHandle != IMG_NULL) { eError = GetHandleData(psBase, &psCHandleData, hHandle, eType); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Lookup of existing handle failed")); goto err; } PVR_ASSERT(hParentKey != IMG_NULL && ParentHandle(psCHandleData) == hParent); /* * If the client is willing to share a handle, the * existing handle is marked as shareable, and the * existing handle has the same parent, return the * existing handle. */ if (TEST_FLAG(psCHandleData->eFlag & eFlag, PVRSRV_HANDLE_ALLOC_FLAG_SHARED) && ParentHandle(psCHandleData) == hParent) { psCHandleData->ui32Refs++; *phHandle = hHandle; eError = PVRSRV_OK; goto err; } eError = PVRSRV_ERROR_HANDLE_NOT_SHAREABLE; goto err; } } eError = AllocHandle(psBase, &hHandle, pvData, eType, eFlag, hParentKey); if (eError != PVRSRV_OK) { goto err; } eError = GetHandleData(psBase, &psCHandleData, hHandle, PVRSRV_HANDLE_TYPE_NONE); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure")); /* If we were able to allocate the handle then there should be no reason why we can't also get it's handle structure. Otherwise something has gone badly wrong. */ PVR_ASSERT(eError == PVRSRV_OK); goto err; } /* * Get the parent handle structure again, in case the handle * structure has moved (depending on the implementation * of AllocHandle). */ eError = GetHandleData(psBase, &psPHandleData, hParent, PVRSRV_HANDLE_TYPE_NONE); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure")); FreeHandle(psBase, hHandle, eType, IMG_NULL); goto err; } eError = AdoptChild(psBase, psPHandleData, psCHandleData); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Parent handle failed to adopt subhandle")); FreeHandle(psBase, hHandle, eType, IMG_NULL); goto err; } *phHandle = hHandle; eError = PVRSRV_OK; err: return eError; }