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 .
19 #ifndef INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
22 #include <com/sun/star/util/XCloneable.hpp>
34 /// functor that clones a UNO-Reference
35 template< class Interface
>
36 struct CreateRefClone
: public ::std::unary_function
< Interface
, Interface
>
38 Interface
operator() ( const Interface
& xOther
)
41 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
42 xCloneable( xOther
, ::com::sun::star::uno::UNO_QUERY
);
44 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
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
> >
56 ::std::pair
< Key
, Interface
> operator() (
57 const ::std::pair
< Key
, Interface
> & rOther
)
60 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
61 xCloneable( rOther
.second
, ::com::sun::star::uno::UNO_QUERY
);
63 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
65 return ::std::make_pair
< Key
, Interface
>( rOther
.first
, xResult
);
69 /// clones a vector of UNO-References
70 template< class Interface
>
72 const ::std::vector
< Interface
> & rSource
,
73 ::std::vector
< Interface
> & rDestination
)
75 ::std::transform( rSource
.begin(), rSource
.end(),
76 ::std::back_inserter( rDestination
),
77 CreateRefClone
< Interface
>());
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
)
85 ::std::transform( rSource
.begin(), rSource
.end(),
86 ::std::back_inserter( rDestination
),
87 CreateRefWithKeyClone
< Key
, Interface
>());
90 /// clones a map of elements with a UNO-Reference as value
91 template< typename Key
, class Interface
>
93 const ::std::map
< Key
, Interface
> & rSource
,
94 ::std::map
< Key
, Interface
> & rDestination
)
96 ::std::transform( rSource
.begin(), rSource
.end(),
97 ::std::inserter( rDestination
, rDestination
.begin() ),
98 CreateRefWithKeyClone
< const Key
, Interface
>());
101 /// clones a UNO-sequence of UNO-References
102 template< class Interface
>
103 void CloneRefSequence(
104 const ::com::sun::star::uno::Sequence
< Interface
> & rSource
,
105 ::com::sun::star::uno::Sequence
< Interface
> & rDestination
)
107 rDestination
.realloc( rSource
.getLength());
108 ::std::transform( rSource
.getConstArray(), rSource
.getConstArray() + rSource
.getLength(),
109 rDestination
.getArray(),
110 CreateRefClone
< Interface
>());
113 } // namespace CloneHelper
116 // INCLUDED_CHART2_SOURCE_INC_CLONEHELPER_HXX
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */