/*! ****************************************************************************** @Function AllocHandle @Description Allocate a new handle @Input phHandle - location for new handle pvData - pointer to resource to be associated with the handle eType - the type of resource hParent - parent handle or IMG_NULL @Output phHandle - points to new handle @Return Error code or PVRSRV_OK ******************************************************************************/ static PVRSRV_ERROR AllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_HANDLE hParent) { HANDLE_DATA *psNewHandleData; IMG_HANDLE hHandle; PVRSRV_ERROR eError; /* PVRSRV_HANDLE_TYPE_NONE is reserved for internal use */ PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE); PVR_ASSERT(psBase != IMG_NULL && psBase->psHashTab != IMG_NULL); PVR_ASSERT(gpsHandleFuncs); if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI)) { /* Handle must not already exist */ PVR_ASSERT(FindHandle(psBase, pvData, eType, hParent) == IMG_NULL); } psNewHandleData = OSAllocZMem(sizeof(*psNewHandleData)); if (psNewHandleData == IMG_NULL) { PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Couldn't allocate handle data")); return PVRSRV_ERROR_OUT_OF_MEMORY; } eError = gpsHandleFuncs->pfnAcquireHandle(psBase->psImplBase, &hHandle, psNewHandleData); if (eError != PVRSRV_OK) { PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Failed to acquire a handle")); goto ErrorFreeHandleData; } /* * If a data pointer can be associated with multiple handles, we * don't put the handle in the hash table, as the data pointer * may not map to a unique handle */ if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI)) { HAND_KEY aKey; /* Initialise hash key */ InitKey(aKey, psBase, pvData, eType, hParent); /* Put the new handle in the hash table */ if (!HASH_Insert_Extended(psBase->psHashTab, aKey, (IMG_UINTPTR_T)hHandle)) { PVR_DPF((PVR_DBG_ERROR, "AllocHandle: Couldn't add handle to hash table")); eError = PVRSRV_ERROR_UNABLE_TO_ADD_HANDLE; goto ErrorReleaseHandle; } } psNewHandleData->hHandle = hHandle; psNewHandleData->eType = eType; psNewHandleData->eFlag = eFlag; psNewHandleData->pvData = pvData; psNewHandleData->ui32Refs = 1; InitParentList(psNewHandleData); #if defined(DEBUG) PVR_ASSERT(NoChildren(psNewHandleData)); #endif InitChildEntry(psNewHandleData); #if defined(DEBUG) PVR_ASSERT(NoParent(psNewHandleData)); #endif /* Return the new handle to the client */ *phHandle = psNewHandleData->hHandle; return PVRSRV_OK; ErrorReleaseHandle: (IMG_VOID)gpsHandleFuncs->pfnReleaseHandle(psBase->psImplBase, hHandle, IMG_NULL); ErrorFreeHandleData: OSFreeMem(psNewHandleData); return eError; }
const bool _toXMLImpl(std::ifstream& pInput, TiXmlDocument* pOutput) { if (!pInput) return false; auto spellsElement = static_cast<TiXmlElement*>(pOutput->LinkEndChild(new TiXmlElement("spells"))); String line; auto c = 0; while (std::getline(pInput, line)) { if (c >= 100) break; c++; Spell s; spellLineSplit(line, s); auto spellElement = static_cast<TiXmlElement*>(spellsElement->LinkEndChild(new TiXmlElement("spell"))); spellElement->SetAttribute("id", s[FieldIndex::ID].c_str()); spellElement->SetAttribute("name", s[FieldIndex::Name].c_str()); spellElement->SetAttribute("mana", s[FieldIndex::ManaCost].c_str()); spellElement->SetAttribute("target", s[FieldIndex::TargetType].c_str()); spellElement->SetAttribute("range", s[FieldIndex::Range].c_str()); if (s[FieldIndex::ResistType] != "0") spellElement->SetAttribute("resist", s[FieldIndex::ResistType].c_str()); //spellElement->SetAttribute("zone", s[FieldIndex::ZoneType].c_str()); //spellElement->SetAttribute("env", s[FieldIndex::EnvironmentType].c_str()); // Classes. auto classesElement = static_cast<TiXmlElement*>(spellElement->LinkEndChild(new TiXmlElement("classes"))); for (auto i = 0; i < NumClasses; i++) { if (s[FieldIndex::WAR_Level + i] == "255") continue; classesElement->SetAttribute(Classes[i].c_str(), s[FieldIndex::WAR_Level + i].c_str()); } // Effects. auto effectsElement = static_cast<TiXmlElement*>(spellElement->LinkEndChild(new TiXmlElement("effects"))); for (auto i = 0; i < NumEffects; i++) { if (s[FieldIndex::EffectID1 + i] == "254") continue; auto effectElement = static_cast<TiXmlElement*>(effectsElement->LinkEndChild(new TiXmlElement("effect"))); // ID effectElement->SetAttribute("type", s[FieldIndex::EffectID1 + i].c_str()); // Formula effectElement->SetAttribute("formula", s[FieldIndex::EffectFormula1 + i].c_str()); // Base effectElement->SetAttribute("base", s[FieldIndex::EffectBase1 + i].c_str()); // Limit effectElement->SetAttribute("limit", s[FieldIndex::EffectLimit1 + i].c_str()); // Max effectElement->SetAttribute("max", s[FieldIndex::EffectMax1 + i].c_str()); } // Strip element if the spell has no effects. if (effectsElement->NoChildren()) spellElement->RemoveChild(effectsElement); } return true; //if (!pInput) { return false; } //auto spellsElement = static_cast<TiXmlElement*>(pOutput->LinkEndChild(new TiXmlElement("spells"))); //static const std::list<std::pair<int, int>> ignore = { // { FieldIndex::EffectBase1, FieldIndex::EffectMax12 }, // { FieldIndex::ComponentID_1, FieldIndex::ComponentCount_4 }, // { FieldIndex::EffectFormula1, FieldIndex::EffectFormula12 }, // { FieldIndex::EffectID1, FieldIndex::EffectID12 }, //}; //auto inIgnored = [=](const int pFieldID){ // for (auto i : ignore) { // if (pFieldID >= i.first && pFieldID <= i.second) // return true; // } // return false; //}; //// Iterate lines //String line; //auto count = 1; //while (std::getline(pInput, line)) { // if (count >= 1000) break; // std::cout << count << std::endl; // auto spellElement = static_cast<TiXmlElement*>(spellsElement->LinkEndChild(new TiXmlElement("spell"))); // auto field = 0; // std::vector<String> values = split(line, '^'); // for (auto i : values) { // if (inIgnored(field)) { field++; continue; } // if (i.empty()) { field++; continue; } // spellElement->SetAttribute(FieldNames[field].c_str(), i.c_str()); // field++; // } // // Write effects. // auto effectsElement = new TiXmlElement("effects"); // auto effectCount = 0; // for (auto i = 0; i < 12; i++) { // // Check for non 254 effect ID. // if (values[FieldIndex::EffectID1 + i] == "254") continue; // effectCount++; // auto effectElement = static_cast<TiXmlElement*>(effectsElement->LinkEndChild(new TiXmlElement("effect"))); // // ID // effectElement->SetAttribute("id", values[FieldIndex::EffectID1 + i].c_str()); // // Formula // effectElement->SetAttribute("formula", values[FieldIndex::EffectFormula1 + i].c_str()); // // Base // effectElement->SetAttribute("base", values[FieldIndex::EffectBase1 + i].c_str()); // // Limit // effectElement->SetAttribute("limit", values[FieldIndex::EffectLimit1 + i].c_str()); // // Max // effectElement->SetAttribute("max", values[FieldIndex::EffectMax1 + i].c_str()); // } // if (effectCount) // spellElement->LinkEndChild(effectsElement); // else // delete effectsElement; // // Write Components. // auto componentsElement = new TiXmlElement("components"); // auto componentCount = 0; // for (auto i = 0; i < 4; i++) { // // Check for non -1 component item ID. // if (values[FieldIndex::ComponentID_1 + i] == "-1") continue; // componentCount++; // auto componentElement = static_cast<TiXmlElement*>(componentsElement->LinkEndChild(new TiXmlElement("component"))); // // Item ID. // componentElement->SetAttribute("id", values[FieldIndex::ComponentID_1 + i].c_str()); // // Item count. // componentElement->SetAttribute("count", values[FieldIndex::ComponentCount_1 + i].c_str()); // } // if (componentCount) // spellElement->LinkEndChild(componentsElement); // else // delete componentsElement; // line.clear(); // count++; //} return true; }