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