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