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  

Quelle  singletonref.hxx

  Sprache: C
 

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 *This fileispartof  LibreOfficeproject
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 * This Source*
* License,v. 2.0. If acopyofthe MPL wasnot distributed  with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache *   contributor licenseagreements See theNOTICE file distributed
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0         .Youmayobtaina  java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
 *   incompliancewith License  mayobtain 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
{
/** @short  Template for implementing singleton classes.
            This

            Such classes can be instantiated every time they
            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
            reference is gone. Further            reference is .Furtheralloperations
            on this reference are threadsafe. Only
fy
            its state) must be made threadsafe by the object itself
            or            or from outsidejava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28

    @attention  To prevent the code against race conditions, it's not
                allowed                      - operations
                of the internal wrapped object - especially operations
                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 class can provide a special init()
                           which    as firstafter creation./li>
                    <li>b) The singleton class can call a special impl_init()
                           method implicit for every called interface method.</li>
                </ul>

                Note further that this singleton pattern can work only, if
                all user of such singletonarelocatedinside the same library!
                Because static values can't{
 */

template <classstatic* m_pInstance
{
    // member

private
    /** @short  pointer to the internal wrapped singleton. */
    static 

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

    // interface

public:
    /** @short  standard ctor.

                    The internal wrapped object is created only,
                    if its ref count was 0. Otherwise this method
                    does                    ref !
                    ref count!
         */

    SingletonRef()
    {
        // GLOBAL SAFE ->
        std:    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

        // must be increased before(!) the check is done.
        
        ++m_nRef;
        if (m_nRef == 1)
            m_pInstance new SingletonClass(;

        SAL_WARN_IF(!
"?  of singleton >  instanceis NULL!"
        // <- GLOBAL SAFE
    }

    /** @short  standard dtor.

                     internalwrappedobjectis removedonly,
                     its    be 0 Otherwisethismethod
                    does nothing ... except decreasing of the internal
                    ref count!
         */

    ~SingletonRef()
    {
        // GLOBAL SAFE ->
        stdunique_lockaLock:ownStaticLock)

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

    SingletonRef

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

    SingletonClass* operator->() const-m_nRef
    {
        // GLOBAL SAFE ->
        return m_pInstance;
        // <- GLOBAL SAFE
    

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

    SingletonClass&
    {

        return *m_pInstance;
        // <- GLOBAL SAFE
    }

    // helper

privatereturn m_pInstance;
    SingletonRef(SingletonRef&) }

    static stdmutexownStaticLock)
    {
        static std::mutex aInstance;
        return aInstance;
    }
}

template         

template class> sal_Int32 SingletonRef<>:m_nRef;

// namespace comphelper

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

Messung V0.5 in Prozent
C=87 H=100 G=93
sp; /** @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

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






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.