1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef CHART2_CLONEHELPER_HXX
28 #define CHART2_CLONEHELPER_HXX
30 #include <com/sun/star/util/XCloneable.hpp>
41 /// functor that clones a UNO-Reference
42 template< class Interface
>
43 struct CreateRefClone
: public ::std::unary_function
< Interface
, Interface
>
45 Interface
operator() ( const Interface
& xOther
)
48 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
49 xCloneable( xOther
, ::com::sun::star::uno::UNO_QUERY
);
51 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
57 /// functor that clones a map element with a UNO-Reference as value
58 template< typename Key
, class Interface
>
59 struct CreateRefWithKeyClone
: public ::std::unary_function
<
60 ::std::pair
< Key
, Interface
>,
61 ::std::pair
< Key
, Interface
> >
63 ::std::pair
< Key
, Interface
> operator() (
64 const ::std::pair
< Key
, Interface
> & rOther
)
67 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
68 xCloneable( rOther
.second
, ::com::sun::star::uno::UNO_QUERY
);
70 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
72 return ::std::make_pair
< Key
, Interface
>( rOther
.first
, xResult
);
76 /// clones a vector of UNO-References
77 template< class Interface
>
79 const ::std::vector
< Interface
> & rSource
,
80 ::std::vector
< Interface
> & rDestination
)
82 ::std::transform( rSource
.begin(), rSource
.end(),
83 ::std::back_inserter( rDestination
),
84 CreateRefClone
< Interface
>());
87 template< typename Key
, class Interface
>
88 void CloneRefPairVector(
89 const ::std::vector
< ::std::pair
< Key
, Interface
> > & rSource
,
90 ::std::vector
< ::std::pair
< Key
, Interface
> > & rDestination
)
92 ::std::transform( rSource
.begin(), rSource
.end(),
93 ::std::back_inserter( rDestination
),
94 CreateRefWithKeyClone
< Key
, Interface
>());
97 /// clones a map of elements with a UNO-Reference as value
98 template< typename Key
, class Interface
>
100 const ::std::map
< Key
, Interface
> & rSource
,
101 ::std::map
< Key
, Interface
> & rDestination
)
103 ::std::transform( rSource
.begin(), rSource
.end(),
104 ::std::inserter( rDestination
, rDestination
.begin() ),
105 CreateRefWithKeyClone
< const Key
, Interface
>());
108 /// clones a UNO-sequence of UNO-References
109 template< class Interface
>
110 void CloneRefSequence(
111 const ::com::sun::star::uno::Sequence
< Interface
> & rSource
,
112 ::com::sun::star::uno::Sequence
< Interface
> & rDestination
)
114 rDestination
.realloc( rSource
.getLength());
115 ::std::transform( rSource
.getConstArray(), rSource
.getConstArray() + rSource
.getLength(),
116 rDestination
.getArray(),
117 CreateRefClone
< Interface
>());
120 } // namespace CloneHelper
123 // CHART2_CLONEHELPER_HXX