1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CloneHelper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART2_CLONEHELPER_HXX
31 #define CHART2_CLONEHELPER_HXX
33 #include <com/sun/star/util/XCloneable.hpp>
43 /// functor that clones a UNO-Reference
44 template< class Interface
>
45 struct CreateRefClone
: public ::std::unary_function
< Interface
, Interface
>
47 Interface
operator() ( const Interface
& xOther
)
50 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
51 xCloneable( xOther
, ::com::sun::star::uno::UNO_QUERY
);
53 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
59 /// functor that clones a map element with a UNO-Reference as value
60 template< typename Key
, class Interface
>
61 struct CreateRefWithKeyClone
: public ::std::unary_function
<
62 ::std::pair
< Key
, Interface
>,
63 ::std::pair
< Key
, Interface
> >
65 ::std::pair
< Key
, Interface
> operator() (
66 const ::std::pair
< Key
, Interface
> & rOther
)
69 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
>
70 xCloneable( rOther
.second
, ::com::sun::star::uno::UNO_QUERY
);
72 xResult
.set( xCloneable
->createClone(), ::com::sun::star::uno::UNO_QUERY
);
74 return ::std::make_pair
< Key
, Interface
>( rOther
.first
, xResult
);
78 /// clones a vector of UNO-References
79 template< class Interface
>
81 const ::std::vector
< Interface
> & rSource
,
82 ::std::vector
< Interface
> & rDestination
)
84 ::std::transform( rSource
.begin(), rSource
.end(),
85 ::std::back_inserter( rDestination
),
86 CreateRefClone
< Interface
>());
89 template< typename Key
, class Interface
>
90 void CloneRefPairVector(
91 const ::std::vector
< ::std::pair
< Key
, Interface
> > & rSource
,
92 ::std::vector
< ::std::pair
< Key
, Interface
> > & rDestination
)
94 ::std::transform( rSource
.begin(), rSource
.end(),
95 ::std::back_inserter( rDestination
),
96 CreateRefWithKeyClone
< Key
, Interface
>());
99 /// clones a map of elements with a UNO-Reference as value
100 template< typename Key
, class Interface
>
102 const ::std::map
< Key
, Interface
> & rSource
,
103 ::std::map
< Key
, Interface
> & rDestination
)
105 ::std::transform( rSource
.begin(), rSource
.end(),
106 ::std::inserter( rDestination
, rDestination
.begin() ),
107 CreateRefWithKeyClone
< const Key
, Interface
>());
110 /// clones a UNO-sequence of UNO-References
111 template< class Interface
>
112 void CloneRefSequence(
113 const ::com::sun::star::uno::Sequence
< Interface
> & rSource
,
114 ::com::sun::star::uno::Sequence
< Interface
> & rDestination
)
116 rDestination
.realloc( rSource
.getLength());
117 ::std::transform( rSource
.getConstArray(), rSource
.getConstArray() + rSource
.getLength(),
118 rDestination
.getArray(),
119 CreateRefClone
< Interface
>());
122 } // namespace CloneHelper
125 // CHART2_CLONEHELPER_HXX