1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 /************** class SotData_Impl *********************************************/
29 /*************************************************************************
30 |* SotData_Impl::SotData_Impl
33 *************************************************************************/
34 SotData_Impl::SotData_Impl()
36 , pFactoryList( NULL
)
37 , pSotObjectFactory( NULL
)
38 , pSotStorageStreamFactory( NULL
)
39 , pSotStorageFactory( NULL
)
40 , pDataFlavorList( NULL
)
44 SotData_Impl::~SotData_Impl()
48 for( tDataFlavorList::iterator aI
= pDataFlavorList
->begin(),
49 aEnd
= pDataFlavorList
->end(); aI
!= aEnd
; ++aI
)
53 delete pDataFlavorList
;
58 /*************************************************************************
62 *************************************************************************/
63 namespace { struct ImplData
: public rtl::Static
<SotData_Impl
, ImplData
> {}; }
64 SotData_Impl
* SOTDATA()
66 return &ImplData::get();
69 /************** class SotFactory *****************************************/
70 /*************************************************************************
71 |* SotFactory::SotFactory()
74 *************************************************************************/
75 TYPEINIT0(SotFactory
);
77 SotFactory::SotFactory( const SvGlobalName
& rName
,
78 const OUString
& rClassName
,
79 CreateInstanceType pCreateFuncP
)
80 : SvGlobalName ( rName
)
82 , pSuperClasses ( NULL
)
83 , pCreateFunc ( pCreateFuncP
)
84 , aClassName ( rClassName
)
87 SvGlobalName aEmptyName
;
88 if( aEmptyName
!= *this )
89 { // wegen Sfx-BasicFactories
90 DBG_ASSERT( aEmptyName
!= *this, "create factory without SvGlobalName" );
93 OSL_FAIL( "create factories with the same unique name" );
97 SotData_Impl
* pSotData
= SOTDATA();
98 if( !pSotData
->pFactoryList
)
99 pSotData
->pFactoryList
= new SotFactoryList();
100 // muss nach hinten, wegen Reihenfolge beim zerstoeren
101 pSotData
->pFactoryList
->push_back( this );
105 //=========================================================================
106 SotFactory::~SotFactory()
108 delete [] pSuperClasses
;
111 /*************************************************************************
112 |* SotFactory::Find()
115 *************************************************************************/
116 const SotFactory
* SotFactory::Find( const SvGlobalName
& rFactName
)
119 SotData_Impl
* pSotData
= SOTDATA();
120 if( rFactName
!= aEmpty
&& pSotData
->pFactoryList
)
122 for ( size_t i
= 0, n
= pSotData
->pFactoryList
->size(); i
< n
; ++i
) {
123 SotFactory
* pFact
= (*pSotData
->pFactoryList
)[ i
];
124 if( *pFact
== rFactName
)
132 /*************************************************************************
133 |* SotFactory::PutSuperClass()
136 *************************************************************************/
137 void SotFactory::PutSuperClass( const SotFactory
* pFact
)
141 pSuperClasses
= new const SotFactory
* [ nSuperCount
];
144 const SotFactory
** pTmp
= new const SotFactory
* [ nSuperCount
];
145 memcpy( (void *)pTmp
, (void *)pSuperClasses
,
146 sizeof( void * ) * (nSuperCount
-1) );
147 delete [] pSuperClasses
;
148 pSuperClasses
= pTmp
;
150 pSuperClasses
[ nSuperCount
-1 ] = pFact
;
154 /*************************************************************************
155 |* SotFactory::IncSvObjectCount()
158 *************************************************************************/
159 void SotFactory::IncSvObjectCount( SotObject
* pObj
)
161 SotData_Impl
* pSotData
= SOTDATA();
162 pSotData
->nSvObjCount
++;
165 pSotData
->aObjectList
.push_back( pObj
);
169 /*************************************************************************
170 |* SotFactory::DecSvObjectCount()
173 *************************************************************************/
174 void SotFactory::DecSvObjectCount( SotObject
* pObj
)
176 SotData_Impl
* pSotData
= SOTDATA();
177 pSotData
->nSvObjCount
--;
179 pSotData
->aObjectList
.remove( pObj
);
180 if( !pSotData
->nSvObjCount
)
182 //keine internen und externen Referenzen mehr
186 /*************************************************************************
187 |* SotFactory::CreateInstance()
190 *************************************************************************/
191 void * SotFactory::CreateInstance( SotObject
** ppObj
) const
193 DBG_ASSERT( pCreateFunc
, "SotFactory::CreateInstance: pCreateFunc == 0" );
194 return pCreateFunc( ppObj
);
197 /*************************************************************************
201 *************************************************************************/
202 bool SotFactory::Is( const SotFactory
* pSuperCl
) const
204 if( this == pSuperCl
)
207 for( sal_uInt16 i
= 0; i
< nSuperCount
; i
++ )
209 if( pSuperClasses
[ i
]->Is( pSuperCl
) )
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */