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 <osl/diagnose.h>
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 134 : SotData_Impl::SotData_Impl()
36 : : nSvObjCount( 0 )
37 : , pFactoryList( NULL )
38 : , pSotObjectFactory( NULL )
39 : , pSotStorageStreamFactory( NULL )
40 : , pSotStorageFactory( NULL )
41 134 : , pDataFlavorList( NULL )
42 : {
43 134 : }
44 :
45 268 : SotData_Impl::~SotData_Impl()
46 : {
47 134 : if (pDataFlavorList)
48 : {
49 83 : for( tDataFlavorList::iterator aI = pDataFlavorList->begin(),
50 27 : aEnd = pDataFlavorList->end(); aI != aEnd; ++aI)
51 : {
52 29 : delete *aI;
53 : }
54 27 : delete pDataFlavorList;
55 : }
56 134 : delete pFactoryList;
57 134 : }
58 :
59 : /*************************************************************************
60 : |* SOTDATA()
61 : |*
62 : |* Beschreibung
63 : *************************************************************************/
64 : namespace { struct ImplData : public rtl::Static<SotData_Impl, ImplData> {}; }
65 21223 : SotData_Impl * SOTDATA()
66 : {
67 21223 : 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 OUString & 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 : #ifdef DBG_UTIL
118 : const SotFactory* SotFactory::Find( const SvGlobalName & rFactName )
119 : {
120 : SvGlobalName aEmpty;
121 : SotData_Impl * pSotData = SOTDATA();
122 : if( rFactName != aEmpty && pSotData->pFactoryList )
123 : {
124 : for ( size_t i = 0, n = pSotData->pFactoryList->size(); i < n; ++i ) {
125 : SotFactory* pFact = (*pSotData->pFactoryList)[ i ];
126 : if( *pFact == rFactName )
127 : return pFact;
128 : }
129 : }
130 :
131 : return 0;
132 : }
133 : #endif
134 :
135 : /*************************************************************************
136 : |* SotFactory::PutSuperClass()
137 : |*
138 : |* Beschreibung
139 : *************************************************************************/
140 0 : void SotFactory::PutSuperClass( const SotFactory * pFact )
141 : {
142 0 : nSuperCount++;
143 0 : if( !pSuperClasses )
144 0 : pSuperClasses = new const SotFactory * [ nSuperCount ];
145 : else
146 : {
147 0 : const SotFactory ** pTmp = new const SotFactory * [ nSuperCount ];
148 : memcpy( static_cast<void *>(pTmp), static_cast<void *>(pSuperClasses),
149 0 : sizeof( void * ) * (nSuperCount -1) );
150 0 : delete [] pSuperClasses;
151 0 : pSuperClasses = pTmp;
152 : }
153 0 : pSuperClasses[ nSuperCount -1 ] = pFact;
154 0 : }
155 :
156 :
157 : /*************************************************************************
158 : |* SotFactory::IncSvObjectCount()
159 : |*
160 : |* Beschreibung
161 : *************************************************************************/
162 10564 : void SotFactory::IncSvObjectCount( SotObject * pObj )
163 : {
164 10564 : SotData_Impl * pSotData = SOTDATA();
165 10564 : pSotData->nSvObjCount++;
166 :
167 10564 : if( pObj )
168 10564 : pSotData->aObjectList.push_back( pObj );
169 10564 : }
170 :
171 :
172 : /*************************************************************************
173 : |* SotFactory::DecSvObjectCount()
174 : |*
175 : |* Beschreibung
176 : *************************************************************************/
177 10504 : void SotFactory::DecSvObjectCount( SotObject * pObj )
178 : {
179 10504 : SotData_Impl * pSotData = SOTDATA();
180 10504 : pSotData->nSvObjCount--;
181 10504 : if( pObj )
182 10504 : pSotData->aObjectList.remove( pObj );
183 10504 : if( !pSotData->nSvObjCount )
184 : {
185 : //keine internen und externen Referenzen mehr
186 : }
187 10504 : }
188 :
189 : /*************************************************************************
190 : |* SotFactory::Is()
191 : |*
192 : |* Beschreibung
193 : *************************************************************************/
194 0 : bool SotFactory::Is( const SotFactory * pSuperCl ) const
195 : {
196 0 : if( this == pSuperCl )
197 0 : return true;
198 :
199 0 : for( sal_uInt16 i = 0; i < nSuperCount; i++ )
200 : {
201 0 : if( pSuperClasses[ i ]->Is( pSuperCl ) )
202 0 : return true;
203 : }
204 0 : return false;
205 : }
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|