/** * Checks whether a resource already exists and returns it or if no * resource was found creates one. * @param type Resource type name. * @param name Resource name. * @return Resource with the given name or 0 if no resource could be * created. * @note This function only does a static check of the pointer, so * take care that the factory produces instances of the correct * class. */ template<class T> typename T::Ptr getOrCreate(const std::string &type, const std::string &name) { // TODO: Dynamic checks in debug version? Resource::Ptr res = getOrCreate(type, name); typename T::Ptr derived = (T*)res.get(); return derived; }
PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::nextInlineTextBox() const { ASSERT(!m_inlineTextBox || !m_inlineTextBox->layoutObject().needsLayout()); if (!m_inlineTextBox) return nullptr; return getOrCreate(m_layoutText, m_inlineTextBox->nextTextBox()); }
void Variables::setGlobalVisible(const Symbol& _key, bool _bVisible, int _iLevel) { Variable* pVar = getOrCreate(_key); pVar->setGlobalVisible(_iLevel, _bVisible); if (_bVisible) { pVar->setGlobal(true); } }
void Variables::removeGlobal(const Symbol& _key, int _iLevel) { Variable* pVar = getOrCreate(_key); if (pVar->isGlobal()) { pVar->setGlobal(false); pVar->setGlobalValue(NULL); } remove(pVar, _iLevel); }
PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::previousOnLine() const { ASSERT(!m_inlineTextBox || !m_inlineTextBox->layoutObject().needsLayout()); if (!m_inlineTextBox) return nullptr; InlineBox* previous = m_inlineTextBox->prevOnLine(); if (previous && previous->isInlineTextBox()) return getOrCreate(&toInlineTextBox(previous)->layoutObject(), toInlineTextBox(previous)); return nullptr; }
PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::nextOnLine() const { ASSERT(!m_inlineTextBox || !m_inlineTextBox->layoutObject().needsLayout()); if (!m_inlineTextBox) return nullptr; InlineBox* next = m_inlineTextBox->nextOnLine(); if (next && next->isInlineTextBox()) return getOrCreate(&toInlineTextBox(next)->layoutObject(), toInlineTextBox(next)); return nullptr; }
void ProfilerUIImpl::addToTree(Lumix::Debug::Allocator::AllocationInfo* info) { Lumix::Debug::StackNode* nodes[1024]; int count = Lumix::Debug::StackTree::getPath(info->m_stack_leaf, nodes, Lumix::lengthOf(nodes)); auto node = m_allocation_root; for (int i = count - 1; i >= 0; --i) { node = getOrCreate(node, nodes[i], info->m_size); } node->m_allocations.push(info); }
MediaDownload * MediaDownloadManager::acquireMediaDownload(const QUrl &url) { if (!url.isValid()) return 0; QMutexLocker mapMutexLocker(&m_mapMutex); Q_UNUSED(mapMutexLocker); MediaDownload *mediaDownload = getOrCreate(url); mediaDownload->ref(); return mediaDownload; }
bool Libraries::putInPreviousScope(const Symbol& _keyLib, types::Library* _pLib, int _iLevel) { Library* lib = getOrCreate(_keyLib); if (lib->empty()) { lib->put(_pLib, _iLevel); } else if (lib->top()->m_iLevel > _iLevel) { ScopedLibrary* pLib = lib->top(); lib->pop(); putInPreviousScope(_keyLib, _pLib, _iLevel); lib->put(pLib); } else { lib->put(_pLib, _iLevel); } return true; }
types::InternalType* Variables::getGlobalValue(const Symbol& _key) { return getOrCreate(_key)->getGlobalValue(); }
bool Variables::isGlobal(const Symbol& _key, int /*_iLevel*/) { return getOrCreate(_key)->isGlobal(); }
bool Variables::isGlobalVisible(const Symbol& _key, int _iLevel) { return getOrCreate(_key)->isGlobalVisible(_iLevel); }
void Libraries::put(const Symbol& _keyLib, types::Library* _pLib, int _iLevel) { Library* lib = getOrCreate(_keyLib); lib->put(_pLib, _iLevel); }
void Variables::setGlobal(const Symbol& _key) { getOrCreate(_key)->setGlobal(true); }
void Variables::put(const Symbol& _key, types::InternalType* _pIT, int _iLevel) { Variable* var = getOrCreate(_key); var->put(_pIT, _iLevel); }
ServiceWorker* ServiceWorker::from(ExecutionContext* executionContext, WebServiceWorker* worker) { return getOrCreate(executionContext, worker); }
PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(JSContextRef, JSObjectRef object) { Node* node = toNode(toJS(object)); return getOrCreate(node); }
void mark(const Id& chunkId, std::size_t chunkNum) { getOrCreate(chunkId, chunkNum).exists = true; }
RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(JSContextRef, JSObjectRef object) { Node* node = JSNode::toWrapped(toJS(object)); return getOrCreate(node); }
Ref<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document() { return getOrCreate(m_node->document()); }
MOZ_MUST_USE mozilla::Maybe<SharedImmutableTwoByteString> SharedImmutableStringsCache::getOrCreate(const char16_t* chars, size_t length) { return getOrCreate(chars, length, [&]() { return DuplicateString(chars, length); }); }
PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(JSContextRef, JSObjectRef object) { Range* range = JSRange::toWrapped(toJS(object)); return getOrCreate(range); }