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 : : #ifndef LAZYDELETE_CXX
21 : : #define LAZYDELETE_CXX
22 : :
23 : : #include "vcl/window.hxx"
24 : : #include "vcl/menu.hxx"
25 : : #include "vcl/lazydelete.hxx"
26 : : #include "svdata.hxx"
27 : :
28 : : namespace vcl {
29 : :
30 : 1486 : LazyDeletorBase::LazyDeletorBase()
31 : : {
32 : 1486 : }
33 : :
34 : 1437 : LazyDeletorBase::~LazyDeletorBase()
35 : : {
36 [ - + ]: 1437 : }
37 : :
38 : : // instantiate instance pointers for LazyDeletor<Window,Menu>
39 : : template<> LazyDeletor<Window>* LazyDeletor<Window>::s_pOneInstance = NULL;
40 : : template<> LazyDeletor<Menu>* LazyDeletor<Menu>::s_pOneInstance = NULL;
41 : :
42 : : // a list for all LazyeDeletor<T> singletons
43 : 281 : static std::vector< LazyDeletorBase* > lcl_aDeletors;
44 : :
45 : 1486 : void LazyDelete::addDeletor( LazyDeletorBase* i_pDel )
46 : : {
47 : 1486 : lcl_aDeletors.push_back( i_pDel );
48 : 1486 : }
49 : :
50 : 220832 : void LazyDelete::flush()
51 : : {
52 : 220832 : unsigned int nCount = lcl_aDeletors.size();
53 [ + + ]: 222269 : for( unsigned int i = 0; i < nCount; i++ )
54 [ + - ]: 1437 : delete lcl_aDeletors[i];
55 : 220832 : lcl_aDeletors.clear();
56 : 220832 : }
57 : :
58 : : // specialized is_less function for Window
59 : 110 : template<> bool LazyDeletor<Window>::is_less( Window* left, Window* right )
60 : : {
61 [ + - ][ - + ]: 110 : return (left != right && right->IsChild( left, sal_True )) ? true : false;
62 : : }
63 : :
64 : : #ifndef LINUX
65 : : // specialized is_less function for Menu
66 : : template<> bool LazyDeletor<Menu>::is_less( Menu* left, Menu* right )
67 : : {
68 : : while( left && left != right )
69 : : left = left->ImplGetStartedFrom();
70 : : return left != NULL;
71 : : }
72 : : #endif
73 : :
74 : 684 : DeleteOnDeinitBase::~DeleteOnDeinitBase()
75 : : {
76 : 684 : ImplSVData* pSVData = ImplGetSVData();
77 [ + - ][ + + ]: 684 : if( pSVData && pSVData->mpDeinitDeleteList != NULL )
78 [ + - ]: 172 : pSVData->mpDeinitDeleteList->remove( this );
79 [ - + ]: 684 : }
80 : :
81 : 684 : void DeleteOnDeinitBase::addDeinitContainer( DeleteOnDeinitBase* i_pContainer )
82 : : {
83 : 684 : ImplSVData* pSVData = ImplGetSVData();
84 [ - + ]: 684 : if( ! pSVData )
85 : : {
86 : 0 : ImplInitSVData();
87 : 0 : pSVData = ImplGetSVData();
88 : : }
89 : :
90 : : DBG_ASSERT( ! pSVData->mbDeInit, "DeleteOnDeinit added after DeiInitVCL !" );
91 [ - + ]: 684 : if( pSVData->mbDeInit )
92 : 684 : return;
93 : :
94 [ + + ]: 684 : if( pSVData->mpDeinitDeleteList == NULL )
95 [ + - ]: 80 : pSVData->mpDeinitDeleteList = new std::list< DeleteOnDeinitBase* >();
96 : 684 : pSVData->mpDeinitDeleteList->push_back( i_pContainer );
97 : : }
98 : :
99 : 158 : void DeleteOnDeinitBase::ImplDeleteOnDeInit()
100 : : {
101 : 158 : ImplSVData* pSVData = ImplGetSVData();
102 [ + + ]: 158 : if( pSVData->mpDeinitDeleteList )
103 : : {
104 [ + - + - ]: 1144 : for( std::list< vcl::DeleteOnDeinitBase* >::iterator it = pSVData->mpDeinitDeleteList->begin();
[ + + ]
105 : 572 : it != pSVData->mpDeinitDeleteList->end(); ++it )
106 : : {
107 [ + - ][ + - ]: 512 : (*it)->doCleanup();
108 : : }
109 [ + - ]: 60 : delete pSVData->mpDeinitDeleteList;
110 : 60 : pSVData->mpDeinitDeleteList = NULL;
111 : : }
112 : 158 : }
113 : :
114 [ + - ][ + - ]: 843 : } // namespace vcl
115 : :
116 : : #endif
117 : :
118 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|