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 : #ifndef INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
20 : #define INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
21 :
22 : #include <com/sun/star/util/XCloneable.hpp>
23 :
24 : #include <map>
25 : #include <functional>
26 : #include <algorithm>
27 : #include <iterator>
28 :
29 : namespace chart
30 : {
31 : namespace CloneHelper
32 : {
33 :
34 : /// functor that clones a UNO-Reference
35 : template< class Interface >
36 : struct CreateRefClone : public ::std::unary_function< Interface, Interface >
37 : {
38 0 : Interface operator() ( const Interface & xOther )
39 : {
40 0 : Interface xResult;
41 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >
42 0 : xCloneable( xOther, ::com::sun::star::uno::UNO_QUERY );
43 0 : if( xCloneable.is())
44 0 : xResult.set( xCloneable->createClone(), ::com::sun::star::uno::UNO_QUERY );
45 :
46 0 : return xResult;
47 : }
48 : };
49 :
50 : /// functor that clones a map element with a UNO-Reference as value
51 : template< typename Key, class Interface >
52 : struct CreateRefWithKeyClone : public ::std::unary_function<
53 : ::std::pair< Key, Interface >,
54 : ::std::pair< Key, Interface > >
55 : {
56 : ::std::pair< Key, Interface > operator() (
57 : const ::std::pair< Key, Interface > & rOther )
58 : {
59 : Interface xResult;
60 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >
61 : xCloneable( rOther.second, ::com::sun::star::uno::UNO_QUERY );
62 : if( xCloneable.is())
63 : xResult.set( xCloneable->createClone(), ::com::sun::star::uno::UNO_QUERY );
64 :
65 : return ::std::make_pair< Key, Interface >( rOther.first, xResult );
66 : }
67 : };
68 :
69 : /// clones a vector of UNO-References
70 : template< class Interface >
71 0 : void CloneRefVector(
72 : const ::std::vector< Interface > & rSource,
73 : ::std::vector< Interface > & rDestination )
74 : {
75 0 : ::std::transform( rSource.begin(), rSource.end(),
76 : ::std::back_inserter( rDestination ),
77 0 : CreateRefClone< Interface >());
78 0 : }
79 :
80 : template< typename Key, class Interface >
81 : void CloneRefPairVector(
82 : const ::std::vector< ::std::pair< Key, Interface > > & rSource,
83 : ::std::vector< ::std::pair< Key, Interface > > & rDestination )
84 : {
85 : ::std::transform( rSource.begin(), rSource.end(),
86 : ::std::back_inserter( rDestination ),
87 : CreateRefWithKeyClone< Key, Interface >());
88 : }
89 :
90 : /// clones a map of elements with a UNO-Reference as value
91 : template< typename Key, class Interface >
92 : void CloneRefMap(
93 : const ::std::map< Key, Interface > & rSource,
94 : ::std::map< Key, Interface > & rDestination )
95 : {
96 : ::std::transform( rSource.begin(), rSource.end(),
97 : ::std::inserter( rDestination, rDestination.begin() ),
98 : CreateRefWithKeyClone< const Key, Interface >());
99 : }
100 :
101 : /// clones a UNO-sequence of UNO-References
102 : template< class Interface >
103 0 : void CloneRefSequence(
104 : const ::com::sun::star::uno::Sequence< Interface > & rSource,
105 : ::com::sun::star::uno::Sequence< Interface > & rDestination )
106 : {
107 0 : rDestination.realloc( rSource.getLength());
108 0 : ::std::transform( rSource.getConstArray(), rSource.getConstArray() + rSource.getLength(),
109 : rDestination.getArray(),
110 0 : CreateRefClone< Interface >());
111 0 : }
112 :
113 : } // namespace CloneHelper
114 : } // namespace chart
115 :
116 : // INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
117 : #endif
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|