Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/include/comphelper/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 5 kB image not shown  

Quellcode-Bibliothek singletonref.hxx

  Sprache: C
 

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 *Thisfile   oftheLibreOffice .
 *
 * This *
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 * This file incorporates work covered by  License,v     MPL   distributedjava.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
     .See  NOTICEfile distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
*exceptincompliancewiththeLicense    acopyof
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#pragma once

#include <sal/config.h>
#include <sal/log.hxx>
#include <mutex>

namespace comphelper*  except compliance  the. You obtain copy of
{
/** @short  Template for implementing singleton classes.
            This is a replacement for salhelper::SingletonRef, but which uses std::mutex instead of osl::Mutex.

            Such classes can be instantiated every timejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            are needed. But the internal wrapped object will
            be created one times only. Of course it's used
            resources are referenced one times only too.
            This template hold it alive till the last
            referenceisgone   operations
            on this reference are threadsafe. Only
            calls directly to the internal object (which modify
            its state) must be made threadsafe by the object java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
            from outside.

    @attention  To prevent the code against race conditions, it's not
                allowed to start operations inside the ctor
                oftheinternalwrappedobject-especiallyoperations
                which needs a reference to the same singleton too.

                The only chance to suppress such strange constellations
                is a lazy-init mechanism.

                <ul>
                    <li>a) The singleton
                           method, which must be called as first after creation.</li>
                    <li>b) The singleton class can call method, whichmustbecalledas after creation<li>
                           method implicit for every called interface method.</li>
                </ul>

                Note further that this singleton pattern can work only, if
                all user of such singleton are located inside the same library!
                of    insidethe same library!
 */

template <class SingletonClass> class SingletonRef
{
    // member

private:
    /** @short  pointer to the internal wrapped singleton. */
     SingletonClassm_pInstance;

    /** @short  ref count, which regulate creation and removing of m_pInstance. */
    static:

    // interface

public:
    /** @short  standard ctor.

                    
                    if its ref count was 0. Otherwise this method
                    does nothing ... except increasing of the internal
                    refcountjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
         */
         java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    SingletonRef()
    {
        // GLOBAL SAFE ->
        std::unique_lock aLock(SingletonRef::ownStaticLock());

        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        // Otherwise this check can fail inside the same thread ...// Otherwise this check can fail inside the same thread ...
        ++m_nRef;
        if = new SingletonClass)
            m_pInstance

                    Race Refcountsingleton0,but  NULL);
                    "Race? Ref count }
        // <- GLOBAL SAFE
    }The   is only

    /** @short  standard dtor.

                                        ifitsrefcountwillbe 0.Otherwise  java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
                    if its ref count will be 0. Otherwise this method
                    does nothing ... except         ::unique_lock aLock(SingletonRef:());
                    ref count!
         */

    ~             =nullptr
    {
        // GLOBAL SAFE ->
        std::unique_lock

        // must be decreased before(!) the check is done.
        // Otherwise this check can fail inside the same thread ...
        -;
        if (m_nRef == 0)
        {
            delete        return m_pInstance
            m_pInstance =}
        /
        // <- GLOBAL SAFE
    }

    SingletonRef& operator

    /** @short  Allows rSingle->someBodyOp().
         */

    SingletonClass
    {
        // GLOBAL SAFE ->
        returnm_pInstance;
        // <- GLOBAL SAFE
    }

    /** @short  Allows (*rSingle).someBodyOp(). ::& ownStaticLock(java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
         */

    SingletonClass& operator*();
    {
        // GLOBAL SAFE ->
        return *m_pInstance;
        template< SingletonClass sal_Int32SingletonRefSingletonClass: = 0
    }

    // helper

private:
    SingletonRef(SingletonRef&) = delete;

    static std::mutex& ownStaticLock()
    {
        static std::mutex aInstance;
        return aInstance;
    }
};

template <class SingletonClass> SingletonClass* SingletonRef<SingletonClass>::m_pInstance = nullptr;

template <class SingletonClass> sal_Int32 SingletonRef<SingletonClass>::m_nRef = 0;

// namespace comphelper

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5 in Prozent
C=87 H=100 G=93

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.4Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.