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_CONTAINERHELPER_HXX
28 #define CHART2_CONTAINERHELPER_HXX
39 namespace ContainerHelper
42 /** converts a standard container into a sequence of the same type
44 input: standard container
45 output: css::uno::Sequence< container::value_type >
49 ::std::vector< sal_Int32 > aVector;
50 Sequence< sal_Int32 > aSequence( ContainerHelper::ContainerToSequence( aVector ));
52 template< class Container
>
53 ::com::sun::star::uno::Sequence
< typename
Container::value_type
>
54 ContainerToSequence( const Container
& rCont
)
56 ::com::sun::star::uno::Sequence
< typename
Container::value_type
> aResult( rCont
.size());
57 ::std::copy( rCont
.begin(), rCont
.end(), aResult
.getArray());
61 /** converts a UNO sequence into a standard "Sequence" container. For
62 convenience see the methods SequenceToVector, etc. below.
65 output: a standard container of the same value type implementing the Concept
66 of a Sequence (vector, deque, list, slist)
70 Sequence< sal_Int32 > aSequence;
71 ::std::vector< sal_Int32 > aVector(
72 ContainerToSequence::SequenceToSTLSequenceContainer< ::std::vector< sal_Int32 > >( aSequence );
74 template< class Container
>
76 SequenceToSTLSequenceContainer( const ::com::sun::star::uno::Sequence
< typename
Container::value_type
> & rSeq
)
78 Container
aResult( rSeq
.getLength());
79 ::std::copy( rSeq
.getConstArray(), rSeq
.getConstArray() + rSeq
.getLength(),
84 /** converts a UNO sequence into a standard container. For convenience see the
85 methods SequenceToVector, etc. below. (In contrast to
86 SequenceToSTLSequenceContainer this works for all standard containers)
89 output: a standard container that has an insert( iterator, key ) method (all
91 note: for containers implementing the Concept of a Sequence (vector, deque,
92 list, slist) use SequenceToSTLSequenceContainer for better speed
96 Sequence< sal_Int32 > aSequence;
97 ::std::set< sal_Int32 > aVector(
98 ContainerToSequence::SequenceToSTLContainer< ::std::set< sal_Int32 > >( aSequence );
100 template< class Container
>
102 SequenceToSTLContainer( const ::com::sun::star::uno::Sequence
< typename
Container::value_type
> & rSeq
)
105 ::std::copy( rSeq
.getConstArray(), rSeq
.getConstArray() + rSeq
.getLength(),
106 ::std::inserter
< Container
>( aResult
, aResult
.begin()));
110 // concrete container methods for convenience
112 /** converts a UNO sequence into a standard vector of same value type
116 Sequence< sal_Int32 > aSequence;
117 ::std::vector< sal_Int32 > aVector( ContainerHelper::SequenceToVector( aSequence ));
119 template< typename T
>
121 SequenceToVector( const ::com::sun::star::uno::Sequence
< T
> & rSeq
)
123 return SequenceToSTLSequenceContainer
< ::std::vector
< T
> >( rSeq
);
126 /** converts a UNO sequence into a standard set of same value type
130 Sequence< sal_Int32 > aSequence;
131 ::std::set< sal_Int32 > aVector( ContainerHelper::SequenceToSet( aSequence ));
133 template< typename T
>
135 SequenceToSet( const ::com::sun::star::uno::Sequence
< T
> & rSeq
)
137 return SequenceToSTLContainer
< ::std::set
< T
> >( rSeq
);
140 // ----------------------------------------
142 /** converts the keys of a Pair Associative Container into a UNO sequence
146 ::std::multimap< sal_Int32, ::rtl::OUString > aMyMultiMap;
147 uno::Sequence< sal_Int32 > aMyKeys( ContainerHelper::MapKeysToSequence( aMyMultiMap ));
148 // note: aMyKeys may contain duplicate keys here
150 template< class Map
>
151 ::com::sun::star::uno::Sequence
< typename
Map::key_type
> MapKeysToSequence(
154 ::com::sun::star::uno::Sequence
< typename
Map::key_type
> aResult( rCont
.size());
155 ::std::transform( rCont
.begin(), rCont
.end(), aResult
.getArray(),
156 ::std::select1st
< typename
Map::value_type
>());
160 /** converts the values of a Pair Associative Container into a UNO sequence
164 ::std::map< sal_Int32, ::rtl::OUString > aMyMultiMap;
165 uno::Sequence< ::rtl::OUString > aMyValues( ContainerHelper::MapValuesToSequence( aMyMultiMap ));
167 template< class Map
>
168 ::com::sun::star::uno::Sequence
< typename
Map::mapped_type
> MapValuesToSequence(
171 ::com::sun::star::uno::Sequence
< typename
Map::mapped_type
> aResult( rCont
.size());
172 ::std::transform( rCont
.begin(), rCont
.end(), aResult
.getArray(),
173 ::std::select2nd
< typename
Map::value_type
>());
177 } // namespace ContainerHelper
180 // CHART2_CONTAINERHELPER_HXX