void Entity::RemoveAllComponents() { TraceObject(""); // C++- Factory-made components for (auto& component : ActiveComponents) { component->Terminate(); } ActiveComponents.clear(); }
Component::Ptr Entity::AddComponent(const std::string & name, bool init) { TraceObject("Adding '" + name + "'"); // Request the object factory to construct the component auto component = Systems::FactoryInstance->ConstructComponentByName(name, *this); // We have to use std::move to be able to move unique_ptrs around ActiveComponents.emplace_back(std::move(component)); // If its meant to be initialized, do so right away if (init) ActiveComponents.back()->Initialize(); return ActiveComponents.back().get(); }
bool Entity::RemoveComponent(const std::string & name) { TraceObject("Removing '" + name + "'"); // Factory-owned components for (auto& component : ActiveComponents) { if (component->Name == name) { // Call it's terminate method component->Terminate(); // Remove it std::swap(component, ActiveComponents.back()); ActiveComponents.pop_back(); return true; } } return false; }
FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) { if (!pObj) return FALSE; FX_DWORD dwObjNum = pObj->GetObjNum(); switch (pObj->GetType()) { case PDFOBJ_ARRAY: { CPDF_Array* pArray = (CPDF_Array*)pObj; for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) { CPDF_Object* pElement = pArray->GetElementValue(i); TraceObject(pElement); } } break; case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; FX_POSITION fPos = pDict->GetStartPos(); CFX_ByteString csKey; do { CPDF_Object* pElement = pDict->GetNextElement(fPos, csKey); //TRACE(csKey + "\n"); if (!pElement) break; TraceObject(pElement); }while (TRUE); } break; case PDFOBJ_STREAM: { CPDF_Stream* pStream = (CPDF_Stream*)pObj; CPDF_Dictionary* pDict = pStream->GetDict(); TraceObject(pDict); } break; case PDFOBJ_REFERENCE: { CPDF_Object* pDirectObj = pObj->GetDirect(); TraceObject(pDirectObj); } break; case PDFOBJ_BOOLEAN: break; case PDFOBJ_NUMBER: //TRACE("%d\n",(int32_t)pObj); break; case PDFOBJ_STRING: //TRACE(((CPDF_String*)pObj)->GetString() + "\n"); break; case PDFOBJ_NAME: //TRACE(((CPDF_Name*)pObj)->GetString() + "\n"); break; case PDFOBJ_NULL: // case PDFOBJ_KEYWORD: // case PDFOBJ_EOF: default: break; } if (dwObjNum == 0) return FALSE; return TRUE; }
Component::Component(std::string name, Entity & owner) : Object(name), OwnerRef(&owner) { TraceObject(""); }
void Component::Destroy() { TraceObject(""); Systems::FactoryInstance->Destroy(this); }