void OMFile::openModify(void) { TRACE("OMFile::openModify"); OMStoredObjectFactory* factory = 0; // if client said DontCare, get from isRecognized(_rawStorage, _encoding) if( nullOMStoredObjectEncoding == _encoding ) { #if defined(OM_DEBUG) bool result = #endif isRecognized(_rawStorage, _encoding); ASSERT("Recognized file", result); factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); } else { // else get exact: findfactory->isRecognized(_rawStorage) factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); #if defined(OM_DEBUG) bool result = #endif factory->isRecognized(_rawStorage); ASSERT("Recognized file", result); } _rootStore = factory->openModify(_rawStorage); ASSERT("Valid store", _rootStore != 0); }
void EventFactory::serialize(Payload *extension, QXmlStreamWriter *writer) { Event *event = se_cast<Event*>(extension); AbstractPayloadFactory *factory = 0; QString node; const QList<Payload::Ptr> items = event->items(); if (event->node().isEmpty() && items.isEmpty()) { return; } else if (!event->node().isEmpty()) { node = event->node(); factory = findFactory(QStringRef(&node)); } else { factory = findFactory(items.at(0)->payloadType()); node = factory ? factory->features().value(0) : QString(); } if (!factory || node.isEmpty()) { Logger::warning() << "Invalid stanza extension at PubSub::Event"; return; } writer->writeStartElement(QLatin1String("event")); writer->writeDefaultNamespace(NS_EVENT); writer->writeStartElement(QLatin1String("items")); writer->writeAttribute(QLatin1String("node"), node); for (int i = 0; i < items.size(); i++) { const Payload::Ptr &entity = items.at(i); if (entity->payloadType() != factory->payloadType()) continue; writer->writeStartElement(QLatin1String("item")); factory->serialize(entity.data(), writer); writer->writeEndElement(); } writer->writeEndElement(); writer->writeEndElement(); }
//----------------------------------------------------------------------- ObjectPtr ObjectFactoryManager::createInstance(const Ogre::String& type) const { Factory<Object>* factory = findFactory(type); Object* object = factory->createInstance(); assert(object->getType() == type); return ObjectPtr(object, Factory<Object>::Deleter(factory)); }
void rspfImageSourceFactoryRegistry::registerFactory(rspfImageSourceFactoryBase* factory) { if(factory&&!findFactory(factory)) { theFactoryList.push_back(factory); } }
shared_ptr<ComponentFactory> ComponentRegistry::getFactory(const std::string &type_name) { shared_ptr<ComponentFactory> factory = findFactory(type_name); if (!factory) { throw SimpleException("No factory for object type", type_name); } return factory; }
bool ossimFontFactoryRegistry::registerFactory(ossimFontFactoryBase* factory) { bool result = false; if(factory&&!findFactory(factory)) { theFactoryList.push_back(factory); result = true; } return result; }
// @mfunc Can a file of the encoding specified by <p encoding> be // created successfully as a named file and // accessed successfully in the mode specified by <p accessMode> ? // @parm The <t OMAccessMode> // @parm The <t OMStoredObjectEncoding> // @rdesc True if <p accessMode> and <p encoding> are compatible, // false otherwise. bool OMFile::compatibleNamedFile(const OMAccessMode accessMode, const OMStoredObjectEncoding& encoding) { TRACE("OMFile::compatibleNamedFile"); bool result = false; OMStoredObjectFactory* factory = findFactory(encoding); ASSERT("Recognized file encoding", factory != 0); result = factory->compatibleNamedFile(accessMode); return result; }
// @mfunc Open a new <c OMFile> for modify access, the // <c OMFile> is named <p fileName>, use the <c OMClassFactory> // <p factory> to create the objects. The file must not already // exist. The byte ordering on the newly created file is given // by <p byteOrder>. The client root <c OMStorable> in the newly // created file is given by <p clientRoot>. // @parm The name of the file to create. // @parm The factory to use for creating objects. // @parm TBS // @parm The byte order to use for the newly created file. // @parm The client root <c OMStorable> in the newly created file. // @parm TBS // @parm TBS // @rdesc The newly created <c OMFile>. OMFile* OMFile::openNewModify(const wchar_t* fileName, const OMClassFactory* factory, void* clientOnRestoreContext, const OMByteOrder byteOrder, OMStorable* clientRoot, const OMStoredObjectEncoding& encoding, OMDictionary* dictionary) { TRACE("OMFile::openNewModify"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid class factory", factory != 0); PRECONDITION("Valid byte order", ((byteOrder == littleEndian) || (byteOrder == bigEndian))); PRECONDITION("Valid client root", clientRoot != 0); PRECONDITION("Valid dictionary ", dictionary != 0); OMFile* newFile = 0; if (compatibleNamedFile(modifyMode, encoding)) { OMStoredObjectFactory* f = findFactory(encoding); ASSERT("Recognized file encoding", f != 0); OMStoredObject* store = f->createModify(fileName, byteOrder); OMRootStorable* root = new OMRootStorable(clientRoot, dictionary); ASSERT("Valid heap pointer", root != 0); newFile = new OMFile(fileName, clientOnRestoreContext, encoding, modifyMode, store, factory, dictionary, root); ASSERT("Valid heap pointer", newFile != 0); } else { OMRootStorable* root = new OMRootStorable(clientRoot, dictionary); ASSERT("Valid heap pointer", root != 0); OMRawStorage* store = OMCachedDiskRawStorage::openNewModify(fileName); ASSERT("Valid raw storage", store != 0); newFile = new OMFile(store, clientOnRestoreContext, encoding, modifyMode, factory, dictionary, root, byteOrder); ASSERT("Valid heap pointer", newFile != 0); newFile->open(); } POSTCONDITION("File is open", newFile->isOpen()); return newFile; }
void OMFile::createWrite(void) { TRACE("OMFile::createWrite"); OMStoredObjectFactory* factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); _rootStore = factory->createWrite(_rawStorage, _byteOrder); ASSERT("Valid root", _root != 0); ASSERT("Valid store", _rootStore != 0); _root->setStore(_rootStore); }
// @mfunc Open an existing <c OMFile> for read-only access, the // <c OMFile> is named <p fileName>, use the <c OMClassFactory> // <p factory> to create the objects. The file must already // exist. // @parm The name of the file to open. // @parm The factory to use for creating objects. // @parm Specifies the use of lazy or eager loading. // @rdesc The newly opened <c OMFile>. OMFile* OMFile::openExistingRead(const wchar_t* fileName, const OMClassFactory* factory, void* clientOnRestoreContext, const OMLoadMode loadMode, OMDictionary* dictionary) { TRACE("OMFile::openExistingRead"); PRECONDITION("Valid file name", validWideString(fileName)); PRECONDITION("Valid class factory", factory != 0); PRECONDITION("Valid dictionary", dictionary != 0); OMStoredObjectEncoding encoding; #if defined(OM_DEBUG) bool result = #endif isRecognized(fileName, encoding); ASSERT("Recognized file", result); // tjb - error OMStoredObjectFactory* f = findFactory(encoding); ASSERT("Recognized file encoding", f != 0); OMFile* newFile = 0; if (compatibleNamedFile(readOnlyMode, encoding)) { OMStoredObject* store = f->openRead(fileName); newFile = new OMFile(fileName, clientOnRestoreContext, encoding, readOnlyMode, store, factory, dictionary, loadMode); ASSERT("Valid heap pointer", newFile != 0); } else { OMRawStorage* store = OMCachedDiskRawStorage::openExistingRead(fileName); ASSERT("Valid raw storage", store != 0); newFile = new OMFile(store, clientOnRestoreContext, nullOMStoredObjectEncoding, // don't care readOnlyMode, factory, dictionary, loadMode); ASSERT("Valid heap pointer", newFile != 0); newFile->open(); } POSTCONDITION("File is open", newFile->isOpen()); return newFile; }
void EventFactory::handleStartElement(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes) { m_depth++; if (m_depth == 1) { m_event.reset(new Event); } if (m_depth == 2 && name == QLatin1String("items")) { m_factory = findFactory(attributes.value(QLatin1String("node"))); m_state = m_factory ? AtItems : AtNowhere; } else if (m_depth == 3 && m_state == AtItems && name == QLatin1String("item")) { m_state = AtItem; } else if (m_depth == 4 && m_state == AtItem && m_factory->canParse(name, uri, attributes)) { m_state = AtEntity; } if (m_state == AtEntity) m_factory->handleStartElement(name, uri, attributes); }
// @mfunc Close this <c OMFile>, any unsaved changes are discarded. // @precondition <f isOpen()> // @postcondition <f !isOpen()> // @postcondition <f isClosed()> void OMFile::close(void) { TRACE("OMFile::close"); PRECONDITION("Open", isOpen()); PRECONDITION("Valid root", _root != 0); _root->close(); _rootStore->close(); if (isValid()) { OMStoredObjectFactory* factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); factory->close(this); } _rootStore = 0; // We don't own _rootStore _root->detach(); delete _root; _root = 0; _isOpen = false; _isClosed = true; POSTCONDITION("Closed", isClosed()); POSTCONDITION("Closed", !isOpen()); }
bool ComponentRegistry::hasFactory(const std::string &type_name) { return bool(findFactory(type_name)); }