LCOV - code coverage report
Current view: top level - sot/source/base - factory.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 16 0.0 %
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 <sot/object.hxx>
      23             : #include <sot/sotdata.hxx>
      24             : #include <comphelper/classids.hxx>
      25             : #include <rtl/instance.hxx>
      26             : #include <rtl/strbuf.hxx>
      27             : 
      28             : /************** class SotData_Impl *********************************************/
      29             : /*************************************************************************
      30             : |*    SotData_Impl::SotData_Impl
      31             : |*
      32             : |*    Beschreibung
      33             : *************************************************************************/
      34           0 : SotData_Impl::SotData_Impl()
      35             :     : nSvObjCount( 0 )
      36             :     , pFactoryList( NULL )
      37             :     , pSotObjectFactory( NULL )
      38             :     , pSotStorageStreamFactory( NULL )
      39             :     , pSotStorageFactory( NULL )
      40           0 :     , pDataFlavorList( NULL )
      41             : {
      42           0 : }
      43             : 
      44           0 : SotData_Impl::~SotData_Impl()
      45             : {
      46           0 :     if (pDataFlavorList)
      47             :     {
      48           0 :         for( tDataFlavorList::iterator aI = pDataFlavorList->begin(),
      49           0 :              aEnd = pDataFlavorList->end(); aI != aEnd; ++aI)
      50             :         {
      51           0 :             delete *aI;
      52             :         }
      53           0 :         delete pDataFlavorList;
      54             :     }
      55           0 :     delete pFactoryList;
      56           0 : }
      57             : 
      58             : /*************************************************************************
      59             : |*    SOTDATA()
      60             : |*
      61             : |*    Beschreibung
      62             : *************************************************************************/
      63             : namespace { struct ImplData : public rtl::Static<SotData_Impl, ImplData> {}; }
      64           0 : SotData_Impl * SOTDATA()
      65             : {
      66           0 :     return &ImplData::get();
      67             : }
      68             : 
      69             : /************** class SotFactory *****************************************/
      70             : /*************************************************************************
      71             : |*    SotFactory::SotFactory()
      72             : |*
      73             : |*    Beschreibung
      74             : *************************************************************************/
      75           0 : TYPEINIT0(SotFactory);
      76             : 
      77           0 : SotFactory::SotFactory( const SvGlobalName & rName,
      78             :                         const OUString & rClassName,
      79             :                         CreateInstanceType pCreateFuncP )
      80             :     : SvGlobalName  ( rName )
      81             :     , nSuperCount   ( 0 )
      82             :     , pSuperClasses ( NULL )
      83             :     , pCreateFunc   ( pCreateFuncP )
      84           0 :     , aClassName    ( rClassName )
      85             : {
      86             : #ifdef DBG_UTIL
      87             :     SvGlobalName aEmptyName;
      88             :     if( aEmptyName != *this )
      89             :     { // wegen Sfx-BasicFactories
      90             :     DBG_ASSERT( aEmptyName != *this, "create factory without SvGlobalName" );
      91             :     if( Find( *this ) )
      92             :     {
      93             :         OSL_FAIL( "create factories with the same unique name" );
      94             :     }
      95             :     }
      96             : #endif
      97           0 :     SotData_Impl * pSotData = SOTDATA();
      98           0 :     if( !pSotData->pFactoryList )
      99           0 :         pSotData->pFactoryList = new SotFactoryList();
     100             :     // muss nach hinten, wegen Reihenfolge beim zerstoeren
     101           0 :     pSotData->pFactoryList->push_back( this );
     102           0 : }
     103             : 
     104             : 
     105             : 
     106           0 : SotFactory::~SotFactory()
     107             : {
     108           0 :     delete [] pSuperClasses;
     109           0 : }
     110             : 
     111             : /*************************************************************************
     112             : |*    SotFactory::Find()
     113             : |*
     114             : |*    Beschreibung
     115             : *************************************************************************/
     116             : #ifdef DBG_UTIL
     117             : const SotFactory* SotFactory::Find( const SvGlobalName & rFactName )
     118             : {
     119             :     SvGlobalName aEmpty;
     120             :     SotData_Impl * pSotData = SOTDATA();
     121             :     if( rFactName != aEmpty && pSotData->pFactoryList )
     122             :     {
     123             :         for ( size_t i = 0, n = pSotData->pFactoryList->size(); i < n; ++i ) {
     124             :             SotFactory* pFact = (*pSotData->pFactoryList)[ i ];
     125             :             if( *pFact == rFactName )
     126             :                 return pFact;
     127             :         }
     128             :     }
     129             : 
     130             :     return 0;
     131             : }
     132             : #endif
     133             : 
     134             : /*************************************************************************
     135             : |*    SotFactory::PutSuperClass()
     136             : |*
     137             : |*    Beschreibung
     138             : *************************************************************************/
     139           0 : void SotFactory::PutSuperClass( const SotFactory * pFact )
     140             : {
     141           0 :     nSuperCount++;
     142           0 :     if( !pSuperClasses )
     143           0 :         pSuperClasses = new const SotFactory * [ nSuperCount ];
     144             :     else
     145             :     {
     146           0 :         const SotFactory ** pTmp = new const SotFactory * [ nSuperCount ];
     147             :         memcpy( (void *)pTmp, (void *)pSuperClasses,
     148           0 :                 sizeof( void * ) * (nSuperCount -1) );
     149           0 :         delete [] pSuperClasses;
     150           0 :         pSuperClasses = pTmp;
     151             :     }
     152           0 :     pSuperClasses[ nSuperCount -1 ] = pFact;
     153           0 : }
     154             : 
     155             : 
     156             : /*************************************************************************
     157             : |*    SotFactory::IncSvObjectCount()
     158             : |*
     159             : |*    Beschreibung
     160             : *************************************************************************/
     161           0 : void SotFactory::IncSvObjectCount( SotObject * pObj )
     162             : {
     163           0 :     SotData_Impl * pSotData = SOTDATA();
     164           0 :     pSotData->nSvObjCount++;
     165             : 
     166           0 :     if( pObj )
     167           0 :         pSotData->aObjectList.push_back( pObj );
     168           0 : }
     169             : 
     170             : 
     171             : /*************************************************************************
     172             : |*    SotFactory::DecSvObjectCount()
     173             : |*
     174             : |*    Beschreibung
     175             : *************************************************************************/
     176           0 : void SotFactory::DecSvObjectCount( SotObject * pObj )
     177             : {
     178           0 :     SotData_Impl * pSotData = SOTDATA();
     179           0 :     pSotData->nSvObjCount--;
     180           0 :     if( pObj )
     181           0 :         pSotData->aObjectList.remove( pObj );
     182           0 :     if( !pSotData->nSvObjCount )
     183             :     {
     184             :         //keine internen und externen Referenzen mehr
     185             :     }
     186           0 : }
     187             : 
     188             : /*************************************************************************
     189             : |*    SotFactory::CreateInstance()
     190             : |*
     191             : |*    Beschreibung
     192             : *************************************************************************/
     193           0 : void * SotFactory::CreateInstance( SotObject ** ppObj ) const
     194             : {
     195             :     DBG_ASSERT( pCreateFunc, "SotFactory::CreateInstance: pCreateFunc == 0" );
     196           0 :     return pCreateFunc( ppObj );
     197             : }
     198             : 
     199             : /*************************************************************************
     200             : |*    SotFactory::Is()
     201             : |*
     202             : |*    Beschreibung
     203             : *************************************************************************/
     204           0 : bool SotFactory::Is( const SotFactory * pSuperCl ) const
     205             : {
     206           0 :     if( this == pSuperCl )
     207           0 :         return true;
     208             : 
     209           0 :     for( sal_uInt16 i = 0; i < nSuperCount; i++ )
     210             :     {
     211           0 :         if( pSuperClasses[ i ]->Is( pSuperCl ) )
     212           0 :             return true;
     213             :     }
     214           0 :     return false;
     215             : }
     216             : 
     217             : 
     218             : 
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10