LCOV - code coverage report
Current view: top level - libreoffice/sot/source/base - factory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 65 40.0 %
Date: 2012-12-27 Functions: 5 17 29.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sot/factory.hxx>
      21             : #include <tools/debug.hxx>
      22             : #include <tools/string.hxx>
      23             : #include <sot/object.hxx>
      24             : #include <sot/sotdata.hxx>
      25             : #include <sot/clsids.hxx>
      26             : #include <rtl/instance.hxx>
      27             : #include <rtl/strbuf.hxx>
      28             : 
      29             : /************** class SotData_Impl *********************************************/
      30             : /*************************************************************************
      31             : |*    SotData_Impl::SotData_Impl
      32             : |*
      33             : |*    Beschreibung
      34             : *************************************************************************/
      35          19 : SotData_Impl::SotData_Impl()
      36             :     : nSvObjCount( 0 )
      37             :     , pFactoryList( NULL )
      38             :     , pSotObjectFactory( NULL )
      39             :     , pSotStorageStreamFactory( NULL )
      40             :     , pSotStorageFactory( NULL )
      41          19 :     , pDataFlavorList( NULL )
      42             : {
      43          19 : }
      44             : 
      45          38 : SotData_Impl::~SotData_Impl()
      46             : {
      47          19 :     if (pDataFlavorList)
      48             :     {
      49          66 :         for( tDataFlavorList::iterator aI = pDataFlavorList->begin(),
      50           5 :              aEnd = pDataFlavorList->end(); aI != aEnd; ++aI)
      51             :         {
      52          56 :             delete *aI;
      53             :         }
      54           5 :         delete pDataFlavorList;
      55             :     }
      56          19 :     delete pFactoryList;
      57          19 : }
      58             : 
      59             : /*************************************************************************
      60             : |*    SOTDATA()
      61             : |*
      62             : |*    Beschreibung
      63             : *************************************************************************/
      64             : namespace { struct ImplData : public rtl::Static<SotData_Impl, ImplData> {}; }
      65        2513 : SotData_Impl * SOTDATA()
      66             : {
      67        2513 :     return &ImplData::get();
      68             : }
      69             : 
      70             : /************** class SotFactory *****************************************/
      71             : /*************************************************************************
      72             : |*    SotFactory::SotFactory()
      73             : |*
      74             : |*    Beschreibung
      75             : *************************************************************************/
      76           0 : TYPEINIT0(SotFactory);
      77             : 
      78           0 : SotFactory::SotFactory( const SvGlobalName & rName,
      79             :                       const String & rClassName,
      80             :                       CreateInstanceType pCreateFuncP )
      81             :     : SvGlobalName  ( rName )
      82             :     , nSuperCount   ( 0 )
      83             :     , pSuperClasses ( NULL )
      84             :     , pCreateFunc   ( pCreateFuncP )
      85           0 :     , aClassName    ( rClassName )
      86             : {
      87             : #ifdef DBG_UTIL
      88             :     SvGlobalName aEmptyName;
      89             :     if( aEmptyName != *this )
      90             :     { // wegen Sfx-BasicFactories
      91             :     DBG_ASSERT( aEmptyName != *this, "create factory without SvGlobalName" );
      92             :     if( Find( *this ) )
      93             :     {
      94             :         OSL_FAIL( "create factories with the same unique name" );
      95             :     }
      96             :     }
      97             : #endif
      98           0 :     SotData_Impl * pSotData = SOTDATA();
      99           0 :     if( !pSotData->pFactoryList )
     100           0 :         pSotData->pFactoryList = new SotFactoryList();
     101             :     // muss nach hinten, wegen Reihenfolge beim zerstoeren
     102           0 :     pSotData->pFactoryList->push_back( this );
     103           0 : }
     104             : 
     105             : 
     106             : //=========================================================================
     107           0 : SotFactory::~SotFactory()
     108             : {
     109           0 :     delete [] pSuperClasses;
     110           0 : }
     111             : 
     112             : /*************************************************************************
     113             : |*    SotFactory::Find()
     114             : |*
     115             : |*    Beschreibung
     116             : *************************************************************************/
     117           0 : const SotFactory* SotFactory::Find( const SvGlobalName & rFactName )
     118             : {
     119           0 :     SvGlobalName aEmpty;
     120           0 :     SotData_Impl * pSotData = SOTDATA();
     121           0 :     if( rFactName != aEmpty && pSotData->pFactoryList )
     122             :     {
     123           0 :         for ( size_t i = 0, n = pSotData->pFactoryList->size(); i < n; ++i ) {
     124           0 :             SotFactory* pFact = (*pSotData->pFactoryList)[ i ];
     125           0 :             if( *pFact == rFactName )
     126           0 :                 return pFact;
     127             :         }
     128             :     }
     129             : 
     130           0 :     return 0;
     131             : }
     132             : 
     133             : /*************************************************************************
     134             : |*    SotFactory::PutSuperClass()
     135             : |*
     136             : |*    Beschreibung
     137             : *************************************************************************/
     138           0 : void SotFactory::PutSuperClass( const SotFactory * pFact )
     139             : {
     140           0 :     nSuperCount++;
     141           0 :     if( !pSuperClasses )
     142           0 :         pSuperClasses = new const SotFactory * [ nSuperCount ];
     143             :     else
     144             :     {
     145           0 :         const SotFactory ** pTmp = new const SotFactory * [ nSuperCount ];
     146             :         memcpy( (void *)pTmp, (void *)pSuperClasses,
     147           0 :                 sizeof( void * ) * (nSuperCount -1) );
     148           0 :         delete [] pSuperClasses;
     149           0 :         pSuperClasses = pTmp;
     150             :     }
     151           0 :     pSuperClasses[ nSuperCount -1 ] = pFact;
     152           0 : }
     153             : 
     154             : 
     155             : /*************************************************************************
     156             : |*    SotFactory::IncSvObjectCount()
     157             : |*
     158             : |*    Beschreibung
     159             : *************************************************************************/
     160        1391 : void SotFactory::IncSvObjectCount( SotObject * pObj )
     161             : {
     162        1391 :     SotData_Impl * pSotData = SOTDATA();
     163        1391 :     pSotData->nSvObjCount++;
     164             : 
     165        1391 :     if( pObj )
     166        1391 :         pSotData->aObjectList.push_back( pObj );
     167        1391 : }
     168             : 
     169             : 
     170             : /*************************************************************************
     171             : |*    SotFactory::DecSvObjectCount()
     172             : |*
     173             : |*    Beschreibung
     174             : *************************************************************************/
     175        1064 : void SotFactory::DecSvObjectCount( SotObject * pObj )
     176             : {
     177        1064 :     SotData_Impl * pSotData = SOTDATA();
     178        1064 :     pSotData->nSvObjCount--;
     179        1064 :     if( pObj )
     180        1064 :         pSotData->aObjectList.remove( pObj );
     181        1064 :     if( !pSotData->nSvObjCount )
     182             :     {
     183             :         //keine internen und externen Referenzen mehr
     184             :     }
     185        1064 : }
     186             : 
     187             : /*************************************************************************
     188             : |*    SotFactory::CreateInstance()
     189             : |*
     190             : |*    Beschreibung
     191             : *************************************************************************/
     192           0 : void * SotFactory::CreateInstance( SotObject ** ppObj ) const
     193             : {
     194             :     DBG_ASSERT( pCreateFunc, "SotFactory::CreateInstance: pCreateFunc == 0" );
     195           0 :     return pCreateFunc( ppObj );
     196             : }
     197             : 
     198             : /*************************************************************************
     199             : |*    SotFactory::Is()
     200             : |*
     201             : |*    Beschreibung
     202             : *************************************************************************/
     203           0 : sal_Bool SotFactory::Is( const SotFactory * pSuperCl ) const
     204             : {
     205           0 :     if( this == pSuperCl )
     206           0 :         return sal_True;
     207             : 
     208           0 :     for( sal_uInt16 i = 0; i < nSuperCount; i++ )
     209             :     {
     210           0 :         if( pSuperClasses[ i ]->Is( pSuperCl ) )
     211           0 :             return sal_True;
     212             :     }
     213           0 :     return sal_False;
     214             : }
     215             : 
     216             : 
     217             : 
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10