bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / inc / DisposeHelper.hxx
blobc05982b3b517c7f1c7750cf8fdb89d0d910bfa9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef CHART2_DISPOSEHELPER_HXX
20 #define CHART2_DISPOSEHELPER_HXX
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/lang/XComponent.hpp>
25 #include <functional>
26 #include <algorithm>
27 #include <utility>
29 namespace chart
31 namespace DisposeHelper
34 template< class T >
35 void Dispose( const T & xIntf )
37 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp(
38 xIntf, ::com::sun::star::uno::UNO_QUERY );
39 if( xComp.is())
40 xComp->dispose();
43 template< class Intf >
44 void DisposeAndClear( ::com::sun::star::uno::Reference< Intf > & rIntf )
46 Dispose< ::com::sun::star::uno::Reference< Intf > >( rIntf );
47 rIntf.set( 0 );
50 template< class T >
51 struct DisposeFunctor : public ::std::unary_function< T, void >
53 void operator() ( const T & xIntf )
55 Dispose< T >( xIntf );
59 template< typename T >
60 struct DisposeFirstOfPairFunctor : public ::std::unary_function< T, void >
62 void operator() ( const T & rElem )
64 Dispose< typename T::first_type >( rElem.first );
68 template< typename T >
69 struct DisposeSecondOfPairFunctor : public ::std::unary_function< T, void >
71 void operator() ( const T & rElem )
73 Dispose< typename T::second_type >( rElem.second );
77 template< class Container >
78 void DisposeAllElements( Container & rContainer )
80 ::std::for_each( rContainer.begin(), rContainer.end(), DisposeFunctor< typename Container::value_type >());
83 template< class Map >
84 void DisposeAllMapElements( Map & rContainer )
86 ::std::for_each( rContainer.begin(), rContainer.end(), DisposeSecondOfPairFunctor< typename Map::value_type >());
89 } // namespace DisposeHelper
90 } // namespace chart
92 // CHART2_DISPOSEHELPER_HXX
93 #endif
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */