当前位置: 首页>>代码示例>>C++>>正文


C++ WeakReference类代码示例

本文整理汇总了C++中WeakReference的典型用法代码示例。如果您正苦于以下问题:C++ WeakReference类的具体用法?C++ WeakReference怎么用?C++ WeakReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WeakReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkForExternalDrag

    void checkForExternalDrag (DragAndDropTarget::SourceDetails& details, const Point<int>& screenPos)
    {
        if (! hasCheckedForExternalDrag)
        {
            if (Desktop::getInstance().findComponentAt (screenPos) == nullptr)
            {
                hasCheckedForExternalDrag = true;
                StringArray files;
                bool canMoveFiles = false;

                if (owner.shouldDropFilesWhenDraggedExternally (details, files, canMoveFiles)
                     && files.size() > 0)
                {
                    WeakReference<Component> thisWeakRef (this);
                    setVisible (false);
                    isDoingExternalDrag = true;

                    if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
                        DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);

                    delete thisWeakRef.get();
                    return;
                }
            }
        }
    }
开发者ID:adscum,项目名称:MoogLadders,代码行数:26,代码来源:juce_DragAndDropContainer.cpp

示例2: useTimeslice

    bool useTimeslice (const int elapsed)
    {
        if (auto* c = proxy != nullptr ? static_cast<Component*> (proxy)
                                       : static_cast<Component*> (component))
        {
            msElapsed += elapsed;
            double newProgress = msElapsed / (double) msTotal;

            if (newProgress >= 0 && newProgress < 1.0)
            {
                const WeakReference<AnimationTask> weakRef (this);
                newProgress = timeToDistance (newProgress);
                const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
                jassert (newProgress >= lastProgress);
                lastProgress = newProgress;

                if (delta < 1.0)
                {
                    bool stillBusy = false;

                    if (isMoving)
                    {
                        left   += (destination.getX()      - left)   * delta;
                        top    += (destination.getY()      - top)    * delta;
                        right  += (destination.getRight()  - right)  * delta;
                        bottom += (destination.getBottom() - bottom) * delta;

                        const Rectangle<int> newBounds (roundToInt (left),
                                                        roundToInt (top),
                                                        roundToInt (right - left),
                                                        roundToInt (bottom - top));

                        if (newBounds != destination)
                        {
                            c->setBounds (newBounds);
                            stillBusy = true;
                        }
                    }

                    // Check whether the animation was cancelled/deleted during
                    // a callback during the setBounds method
                    if (weakRef.wasObjectDeleted())
                        return false;

                    if (isChangingAlpha)
                    {
                        alpha += (destAlpha - alpha) * delta;
                        c->setAlpha ((float) alpha);
                        stillBusy = true;
                    }

                    if (stillBusy)
                        return true;
                }
            }
        }

        moveToFinalDestination();
        return false;
    }
开发者ID:Neknail,项目名称:JUCE,代码行数:60,代码来源:juce_ComponentAnimator.cpp

示例3: jassert

int ModalComponentManager::runEventLoopForCurrentComponent()
{
    // This can only be run from the message thread!
    jassert (MessageManager::getInstance()->isThisTheMessageThread());

    Component* currentlyModal = getModalComponent (0);

    if (currentlyModal == nullptr)
        return 0;

    WeakReference<Component> prevFocused (Component::getCurrentlyFocusedComponent());

    int returnValue = 0;
    bool finished = false;
    attachCallback (currentlyModal, new ReturnValueRetriever (returnValue, finished));

    JUCE_TRY
    {
        while (! finished)
        {
            if  (! MessageManager::getInstance()->runDispatchLoopUntil (20))
                break;
        }
    }
    JUCE_CATCH_EXCEPTION

    if (prevFocused != nullptr)
        prevFocused->grabKeyboardFocus();

    return returnValue;
}
开发者ID:Amcut,项目名称:pizmidi,代码行数:31,代码来源:juce_ModalComponentManager.cpp

示例4: moveToFinalDestination

    void moveToFinalDestination()
    {
        if (component != nullptr)
        {
            const WeakReference<AnimationTask> weakRef (this);
            component->setAlpha ((float) destAlpha);
            component->setBounds (destination);

            if (! weakRef.wasObjectDeleted())
                if (proxy != nullptr)
                    component->setVisible (destAlpha > 0);
        }
    }
开发者ID:Neknail,项目名称:JUCE,代码行数:13,代码来源:juce_ComponentAnimator.cpp

示例5:

    ConvexHullShape& ConvexHullShape::getDefault()
    {
        static WeakReference<ConvexHullShape> defShape;

        if (defShape.expired())
        {
            defShape = static_ref_cast<ConvexHullShape>(ResourceManager::getEmpty<ConvexHullShape>("jop_default_staticmeshshape").getReference());
            defShape->m_shape = std::make_unique<btCapsuleShape>(0.5f, 2.f);

            defShape->setPersistence(0);
        }

        return *defShape;
    }
开发者ID:Jopnal,项目名称:Jopnal,代码行数:14,代码来源:ConvexHullShape.cpp

示例6: setter

void DropShadower::updateShadows()
{
    if (reentrant)
        return;

    const ScopedValueSetter<bool> setter (reentrant, true, false);

    if (owner == nullptr)
    {
        shadowWindows.clear();
        return;
    }

    if (owner->isShowing()
         && owner->getWidth() > 0 && owner->getHeight() > 0
         && (Desktop::canUseSemiTransparentWindows() || owner->getParentComponent() != nullptr))
    {
        while (shadowWindows.size() < 4)
            shadowWindows.add (new ShadowWindow (owner, shadow));

        const int shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;
        const int x = owner->getX();
        const int y = owner->getY() - shadowEdge;
        const int w = owner->getWidth();
        const int h = owner->getHeight() + shadowEdge + shadowEdge;

        for (int i = 4; --i >= 0;)
        {
            // there seem to be rare situations where the dropshadower may be deleted by
            // callbacks during this loop, so use a weak ref to watch out for this..
            WeakReference<Component> sw (shadowWindows[i]);

            if (sw != nullptr)
            {
                sw->setAlwaysOnTop (owner->isAlwaysOnTop());

                if (sw == nullptr)
                    return;

                switch (i)
                {
                    case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
                    case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
                    case 2: sw->setBounds (x, y, w, shadowEdge); break;
                    case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
                    default: break;
                }

                if (sw == nullptr)
                    return;

                sw->toBehind (i == 3 ? owner : shadowWindows.getUnchecked (i + 1));
            }
        }
    }
    else
    {
        shadowWindows.clear();
    }
}
开发者ID:DISTRHO,项目名称:DISTRHO-Ports,代码行数:60,代码来源:juce_DropShadower.cpp

示例7: lock

/**
 * Retrieve a requires file that might be loaded for this
 * instance.
 *
 * @param name   The name used for the requires file.
 *
 * @return The loaded requires file, or OREF_NULL if this instance
 *         has not used the file yet.
 */
PackageClass *InterpreterInstance::getRequiresFile(RexxActivity *activity, RexxString *name)
{
    WeakReference *ref = (WeakReference *)requiresFiles->get(name);
    if (ref != OREF_NULL)
    {
        PackageClass *resolved = (PackageClass *)ref->get();
        if (resolved != OREF_NULL)
        {
            // get the guard lock on this...this will ensure that
            // the initializer is run before we grab this from the cache
            GuardLock lock(activity, resolved, ThePackageClass);
            return resolved;
        }
        // this was garbage collected, remove it from the table
        requiresFiles->remove(name);
    }
    return OREF_NULL;
}
开发者ID:jlfaucher,项目名称:executor,代码行数:27,代码来源:InterpreterInstance.cpp

示例8: testWeakRefs

static void testWeakRefs() {
	assertEquals( TestObject::count, 0 );

	Reference<TestObject> ref( new TestObject() );
	WeakReference<TestObject> wref = ref;

	assertEquals( TestObject::count, 1 );
	assertTrue( ref );
	assertTrue( wref );
	assertTrue( wref.lock() );

	ref = Reference<TestObject>();

	assertEquals( TestObject::count, 0 );
	assertFalse( ref );
	assertFalse( wref );
	assertFalse( wref.lock() );
}
开发者ID:alesapin,项目名称:lspl,代码行数:18,代码来源:RefCountObjectsTest.cpp

示例9:

/**
 * Check for a package already in the requires cache.
 *
 * @param name   The name of the target.
 *
 * @return The PackageClass instance, if any.
 */
RoutineClass *PackageManager::checkRequiresCache(RexxString *name, ProtectedObject &result)
{
    // first check this using the specified name.  Since we need to perform checks in the
    // macro space, it's possible this will be loaded under the simple name.  We'll need to check
    // table again using the fully resolved name afterward.
    WeakReference *requiresRef = (WeakReference *)loadedRequires->get(name);
    if (requiresRef != OREF_NULL)
    {
        RoutineClass *resolved = (RoutineClass *)requiresRef->get();
        if (resolved != OREF_NULL)
        {
            result = resolved;
            return resolved;
        }
        // this was garbage collected, remove it from the table
        loadedRequires->remove(name);
    }
    return OREF_NULL;
}
开发者ID:jlfaucher,项目名称:executor,代码行数:26,代码来源:PackageManager.cpp

示例10: previousFrontWindow

bool MainWindowList::openFile (const File& file, bool openInBackground)
{
    for (auto* w : windows)
    {
        if (w->getProject() != nullptr && w->getProject()->getFile() == file)
        {
            w->toFront (true);
            return true;
        }
    }

    if (file.hasFileExtension (Project::projectFileExtension))
    {
        WeakReference<Component> previousFrontWindow (getFrontmostWindow());

        auto* w = getOrCreateEmptyWindow();
        bool ok = w->openFile (file);

        if (ok)
        {
            w->makeVisible();
            avoidSuperimposedWindows (w);
        }
        else
        {
            closeWindow (w);
        }

        if (openInBackground && previousFrontWindow != nullptr)
            previousFrontWindow->toFront (true);

        return ok;
    }

    if (getFrontmostWindow()->tryToOpenPIP (file))
        return true;

    if (! isPIPFile (file) && file.exists())
        return getFrontmostWindow()->openFile (file);

    return false;
}
开发者ID:julianstorer,项目名称:JUCE,代码行数:42,代码来源:jucer_MainWindow.cpp

示例11: dump_socket

static int
dump_socket(int argc, char** argv)
{
	if (argc < 2) {
		kprintf("usage: %s [address]\n", argv[0]);
		return 0;
	}

	net_socket_private* socket = (net_socket_private*)parse_expression(argv[1]);

	kprintf("SOCKET %p\n", socket);
	kprintf("  family.type.protocol: %d.%d.%d\n",
		socket->family, socket->type, socket->protocol);
	WeakReference<net_socket_private> parent = socket->parent;
	kprintf("  parent:               %p (%p)\n", parent.Get(), socket->parent);
	kprintf("  first protocol:       %p\n", socket->first_protocol);
	kprintf("  first module_info:    %p\n", socket->first_info);
	kprintf("  options:              %x\n", socket->options);
	kprintf("  linger:               %d\n", socket->linger);
	kprintf("  bound to device:      %d\n", socket->bound_to_device);
	kprintf("  owner:                %ld\n", socket->owner);
	kprintf("  max backlog:          %ld\n", socket->max_backlog);
	kprintf("  is connected:         %d\n", socket->is_connected);
	kprintf("  child_count:          %lu\n", socket->child_count);

	if (socket->child_count == 0)
		return 0;

	kprintf("    pending children:\n");
	SocketList::Iterator iterator = socket->pending_children.GetIterator();
	while (net_socket_private* child = iterator.Next()) {
		print_socket_line(child, "      ");
	}

	kprintf("    connected children:\n");
	iterator = socket->connected_children.GetIterator();
	while (net_socket_private* child = iterator.Next()) {
		print_socket_line(child, "      ");
	}

	return 0;
}
开发者ID:mmanley,项目名称:Antares,代码行数:42,代码来源:net_socket.cpp

示例12: socket_connected

/*!	The socket has been connected. It will be moved to the connected queue
	of its parent socket.
*/
status_t
socket_connected(net_socket* _socket)
{
	net_socket_private* socket = (net_socket_private*)_socket;

	WeakReference<net_socket_private> parent = socket->parent;
	if (parent.Get() == NULL)
		return B_BAD_VALUE;

	MutexLocker _(parent->lock);

	parent->pending_children.Remove(socket);
	parent->connected_children.Add(socket);
	socket->is_connected = true;

	// notify parent
	if (parent->select_pool)
		notify_select_event_pool(parent->select_pool, B_SELECT_READ);

	return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:24,代码来源:net_socket.cpp

示例13: socket_aborted

/*!	The socket has been aborted. Steals the parent's reference, and releases
	it.
*/
status_t
socket_aborted(net_socket* _socket)
{
	net_socket_private* socket = (net_socket_private*)_socket;

	WeakReference<net_socket_private> parent = socket->parent;
	if (parent.Get() == NULL)
		return B_BAD_VALUE;

	MutexLocker _(parent->lock);

	if (socket->is_connected)
		parent->connected_children.Remove(socket);
	else
		parent->pending_children.Remove(socket);

	parent->child_count--;
	socket->RemoveFromParent();

	return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:24,代码来源:net_socket.cpp

示例14: setter

void DropShadower::updateShadows()
{
    if (reentrant || owner == nullptr)
        return;

    ComponentPeer* const peer = owner->getPeer();
    const bool isOwnerVisible = owner->isVisible() && (peer == nullptr || ! peer->isMinimised());

    const bool createShadowWindows  = shadowWindows.size() == 0
                                         && owner->getWidth() > 0
                                         && owner->getHeight() > 0
                                         && isOwnerVisible
                                         && (Desktop::canUseSemiTransparentWindows()
                                              || owner->getParentComponent() != nullptr);

    {
        const ScopedValueSetter<bool> setter (reentrant, true, false);

        const int shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;

        if (createShadowWindows)
        {
            const int shadowEdge2 = shadowEdge * 2;
            const int imageSize = shadowEdge * 5;

            // keep a cached version of the image to save doing the gaussian too often
            int64 hash = shadow.radius ^ 0x2342dfa7;
            hash = hash * 101 + shadow.offset.x;
            hash = hash * 101 + shadow.offset.y;
            hash = hash * 65537 + shadow.colour.getARGB();

            Image bigIm (ImageCache::getFromHashCode (hash));

            if (bigIm.isNull())
            {
                bigIm = Image (Image::ARGB, imageSize, imageSize, true);
                Graphics g (bigIm);

                Path p;
                p.addRectangle ((float) (shadowEdge + shadow.offset.x),
                                (float) (shadowEdge + shadow.offset.y),
                                (float) (imageSize - shadowEdge2),
                                (float) (imageSize - shadowEdge2));

                shadow.drawForPath (g, p);

                ImageCache::addImageToCache (bigIm, hash);
            }

            jassert (imageSize == bigIm.getWidth() && imageSize == bigIm.getHeight());

            setShadowImage (bigIm, 0,  shadowEdge, shadowEdge2, 0, 0);
            setShadowImage (bigIm, 1,  shadowEdge, shadowEdge2, 0, imageSize - shadowEdge2);
            setShadowImage (bigIm, 2,  shadowEdge, shadowEdge,  0, shadowEdge2);
            setShadowImage (bigIm, 3,  shadowEdge, shadowEdge2, imageSize - shadowEdge, 0);
            setShadowImage (bigIm, 4,  shadowEdge, shadowEdge2, imageSize - shadowEdge, imageSize - shadowEdge2);
            setShadowImage (bigIm, 5,  shadowEdge, shadowEdge,  imageSize - shadowEdge, shadowEdge2);
            setShadowImage (bigIm, 6,  shadowEdge, shadowEdge,  shadowEdge, 0);
            setShadowImage (bigIm, 7,  shadowEdge, shadowEdge,  imageSize - shadowEdge2, 0);
            setShadowImage (bigIm, 8,  shadowEdge, shadowEdge,  shadowEdge2, 0);
            setShadowImage (bigIm, 9,  shadowEdge, shadowEdge,  shadowEdge, imageSize - shadowEdge);
            setShadowImage (bigIm, 10, shadowEdge, shadowEdge,  imageSize - shadowEdge2, imageSize - shadowEdge);
            setShadowImage (bigIm, 11, shadowEdge, shadowEdge,  shadowEdge2, imageSize - shadowEdge);

            for (int i = 0; i < 4; ++i)
                shadowWindows.add (new ShadowWindow (*owner, i, shadowImageSections));
        }

        if (shadowWindows.size() >= 4)
        {
            const int x = owner->getX();
            const int y = owner->getY() - shadowEdge;
            const int w = owner->getWidth();
            const int h = owner->getHeight() + shadowEdge + shadowEdge;

            for (int i = shadowWindows.size(); --i >= 0;)
            {
                // there seem to be rare situations where the dropshadower may be deleted by
                // callbacks during this loop, so use a weak ref to watch out for this..
                WeakReference<Component> sw (shadowWindows[i]);

                if (sw != nullptr)
                    sw->setAlwaysOnTop (owner->isAlwaysOnTop());

                if (sw != nullptr)
                    sw->setVisible (isOwnerVisible);

                if (sw != nullptr)
                {
                    switch (i)
                    {
                        case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
                        case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
                        case 2: sw->setBounds (x, y, w, shadowEdge); break;
                        case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
                        default: break;
                    }
                }

                if (sw == nullptr)
//.........这里部分代码省略.........
开发者ID:Amcut,项目名称:pizmidi,代码行数:101,代码来源:juce_DropShadower.cpp

示例15: updateLocation

    void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
    {
        // (note: use a local copy of this in case a callback runs a modal loop and deletes
        // this object before it returns)
        DragAndDropTarget::SourceDetails details (sourceDetails);

        Point<int> newPos (screenPos + imageOffset);

        if (getParentComponent() != nullptr)
            newPos = getParentComponent()->getLocalPoint (nullptr, newPos);

        //if (newX != getX() || newY != getY())
        {
            setTopLeftPosition (newPos.getX(), newPos.getY());

            Point<int> relPos;
            DragAndDropTarget* const newTarget = findTarget (screenPos, relPos);
            Component* newTargetComp = dynamic_cast <Component*> (newTarget);

            drawImage = (newTarget == nullptr) || newTarget->shouldDrawDragImageWhenOver();

            if (newTargetComp != currentlyOverComp)
            {
                DragAndDropTarget* const lastTarget = getCurrentlyOver();

                if (lastTarget != nullptr && details.sourceComponent != nullptr
                      && lastTarget->isInterestedInDragSource (details))
                    lastTarget->itemDragExit (details);

                currentlyOverComp = newTargetComp;

                if (newTarget != nullptr)
                {
                    details.localPosition = relPos;

                    if (newTarget->isInterestedInDragSource (details))
                        newTarget->itemDragEnter (details);
                }
            }

            {
                DragAndDropTarget* const target = getCurrentlyOver();
                if (target != nullptr)
                {
                    details.localPosition = relPos;

                    if (target->isInterestedInDragSource (details))
                        target->itemDragMove (details);
                }
            }

            if (getCurrentlyOver() == nullptr && canDoExternalDrag && ! hasCheckedForExternalDrag)
            {
                if (Desktop::getInstance().findComponentAt (screenPos) == nullptr)
                {
                    hasCheckedForExternalDrag = true;
                    StringArray files;
                    bool canMoveFiles = false;

                    if (owner->shouldDropFilesWhenDraggedExternally (details, files, canMoveFiles)
                         && files.size() > 0)
                    {
                        WeakReference<Component> thisWeakRef (this);
                        setVisible (false);

                        if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
                            DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);

                        delete thisWeakRef.get();
                        return;
                    }
                }
            }
        }
    }
开发者ID:baeksanchang,项目名称:juce,代码行数:75,代码来源:juce_DragAndDropContainer.cpp


注:本文中的WeakReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。