Branch data 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 : 171 : SotData_Impl::SotData_Impl()
36 : : : nSvObjCount( 0 )
37 : : , pFactoryList( NULL )
38 : : , pSotObjectFactory( NULL )
39 : : , pSotStorageStreamFactory( NULL )
40 : : , pSotStorageFactory( NULL )
41 : 171 : , pDataFlavorList( NULL )
42 : : {
43 : 171 : }
44 : :
45 : 171 : SotData_Impl::~SotData_Impl()
46 : : {
47 [ + + ]: 171 : if (pDataFlavorList)
48 : : {
49 [ + - ][ + + ]: 568 : for( tDataFlavorList::iterator aI = pDataFlavorList->begin(),
50 : 44 : aEnd = pDataFlavorList->end(); aI != aEnd; ++aI)
51 : : {
52 [ + - ]: 480 : delete *aI;
53 : : }
54 [ + - ]: 44 : delete pDataFlavorList;
55 : : }
56 [ - + ]: 171 : delete pFactoryList;
57 : 171 : }
58 : :
59 : : /*************************************************************************
60 : : |* SOTDATA()
61 : : |*
62 : : |* Beschreibung
63 : : *************************************************************************/
64 : : namespace { struct ImplData : public rtl::Static<SotData_Impl, ImplData> {}; }
65 : 12832 : SotData_Impl * SOTDATA()
66 : : {
67 : 12832 : 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 : 6417 : void SotFactory::IncSvObjectCount( SotObject * pObj )
161 : : {
162 : 6417 : SotData_Impl * pSotData = SOTDATA();
163 : 6417 : pSotData->nSvObjCount++;
164 : :
165 [ + - ]: 6417 : if( pObj )
166 : 6417 : pSotData->aObjectList.push_back( pObj );
167 : 6417 : }
168 : :
169 : :
170 : : /*************************************************************************
171 : : |* SotFactory::DecSvObjectCount()
172 : : |*
173 : : |* Beschreibung
174 : : *************************************************************************/
175 : 5874 : void SotFactory::DecSvObjectCount( SotObject * pObj )
176 : : {
177 : 5874 : SotData_Impl * pSotData = SOTDATA();
178 : 5874 : pSotData->nSvObjCount--;
179 [ + - ]: 5874 : if( pObj )
180 : 5874 : pSotData->aObjectList.remove( pObj );
181 : 5874 : if( !pSotData->nSvObjCount )
182 : : {
183 : : //keine internen und externen Referenzen mehr
184 : : }
185 : 5874 : }
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 : 0 : void * SotFactory::CastAndAddRef
200 : : (
201 : : SotObject * pObj /* Das Objekt von dem der Typ gepr"uft wird. */
202 : : ) const
203 : : /* [Beschreibung]
204 : :
205 : : Ist eine Optimierung, damit die Ref-Klassen k"urzer implementiert
206 : : werden k"onnen. pObj wird auf den Typ der Factory gecastet.
207 : : In c++ (wenn es immer erlaubt w"are) w"urde der void * wie im
208 : : Beispiel gebildet.
209 : : Factory der Klasse SvPersist.
210 : : void * p = (void *)(SvPersist *)pObj;
211 : :
212 : : [R"uckgabewert]
213 : :
214 : : void *, NULL, pObj war NULL oder das Objekt war nicht vom Typ
215 : : der Factory.
216 : : Ansonsten wird pObj zuerst auf den Typ der Factory
217 : : gecastet und dann auf void *.
218 : :
219 : : [Querverweise]
220 : :
221 : : <SotObject::CastAndAddRef>
222 : : */
223 : : {
224 [ # # ]: 0 : return pObj ? pObj->CastAndAddRef( this ) : NULL;
225 : : }
226 : :
227 : : /*************************************************************************
228 : : |* SotFactory::Is()
229 : : |*
230 : : |* Beschreibung
231 : : *************************************************************************/
232 : 0 : sal_Bool SotFactory::Is( const SotFactory * pSuperCl ) const
233 : : {
234 [ # # ]: 0 : if( this == pSuperCl )
235 : 0 : return sal_True;
236 : :
237 [ # # ]: 0 : for( sal_uInt16 i = 0; i < nSuperCount; i++ )
238 : : {
239 [ # # ]: 0 : if( pSuperClasses[ i ]->Is( pSuperCl ) )
240 : 0 : return sal_True;
241 : : }
242 : 0 : return sal_False;
243 : : }
244 : :
245 : :
246 : :
247 : :
248 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|