fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / inc / ContainerHelper.hxx
blob139ddd6fd667b31c6d8d020bbdb9cf5a1eaeb694
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_CONTAINERHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_CONTAINERHELPER_HXX
22 #include <vector>
23 #include <set>
24 #include <map>
26 #include <algorithm>
27 #include <functional>
28 #include <o3tl/compat_functional.hxx>
30 namespace chart
32 namespace ContainerHelper
35 /** converts a standard container into a sequence of the same type
37 input: standard container
38 output: css::uno::Sequence< container::value_type >
40 example:
42 ::std::vector< sal_Int32 > aVector;
43 Sequence< sal_Int32 > aSequence( ContainerHelper::ContainerToSequence( aVector ));
45 template< class Container >
46 ::com::sun::star::uno::Sequence< typename Container::value_type >
47 ContainerToSequence( const Container & rCont )
49 ::com::sun::star::uno::Sequence< typename Container::value_type > aResult( rCont.size());
50 ::std::copy( rCont.begin(), rCont.end(), aResult.getArray());
51 return aResult;
54 /** converts a UNO sequence into a standard "Sequence" container. For
55 convenience see the methods SequenceToVector, etc. below.
57 input: uno::Sequence
58 output: a standard container of the same value type implementing the Concept
59 of a Sequence (vector, deque, list, slist)
61 example:
63 Sequence< sal_Int32 > aSequence;
64 ::std::vector< sal_Int32 > aVector(
65 ContainerToSequence::SequenceToSTLSequenceContainer< ::std::vector< sal_Int32 > >( aSequence );
67 template< class Container >
68 Container
69 SequenceToSTLSequenceContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
71 Container aResult( rSeq.getLength());
72 ::std::copy( rSeq.getConstArray(), rSeq.getConstArray() + rSeq.getLength(),
73 aResult.begin() );
74 return aResult;
77 /** converts a UNO sequence into a standard container. For convenience see the
78 methods SequenceToVector, etc. below. (In contrast to
79 SequenceToSTLSequenceContainer this works for all standard containers)
81 input: uno::Sequence
82 output: a standard container that has an insert( iterator, key ) method (all
83 standard containers)
84 note: for containers implementing the Concept of a Sequence (vector, deque,
85 list, slist) use SequenceToSTLSequenceContainer for better speed
87 example:
89 Sequence< sal_Int32 > aSequence;
90 ::std::set< sal_Int32 > aVector(
91 ContainerToSequence::SequenceToSTLContainer< ::std::set< sal_Int32 > >( aSequence );
93 template< class Container >
94 Container
95 SequenceToSTLContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
97 Container aResult;
98 ::std::copy( rSeq.getConstArray(), rSeq.getConstArray() + rSeq.getLength(),
99 ::std::inserter< Container >( aResult, aResult.begin()));
100 return aResult;
103 // concrete container methods for convenience
105 /** converts a UNO sequence into a standard vector of same value type
107 example:
109 Sequence< sal_Int32 > aSequence;
110 ::std::vector< sal_Int32 > aVector( ContainerHelper::SequenceToVector( aSequence ));
112 template< typename T >
113 ::std::vector< T >
114 SequenceToVector( const ::com::sun::star::uno::Sequence< T > & rSeq )
116 return SequenceToSTLSequenceContainer< ::std::vector< T > >( rSeq );
119 /** converts a UNO sequence into a standard set of same value type
121 example:
123 Sequence< sal_Int32 > aSequence;
124 ::std::set< sal_Int32 > aVector( ContainerHelper::SequenceToSet( aSequence ));
126 template< typename T >
127 ::std::set< T >
128 SequenceToSet( const ::com::sun::star::uno::Sequence< T > & rSeq )
130 return SequenceToSTLContainer< ::std::set< T > >( rSeq );
133 /** converts the keys of a Pair Associative Container into a UNO sequence
135 example:
137 ::std::multimap< sal_Int32, OUString > aMyMultiMap;
138 uno::Sequence< sal_Int32 > aMyKeys( ContainerHelper::MapKeysToSequence( aMyMultiMap ));
139 // note: aMyKeys may contain duplicate keys here
141 template< class Map >
142 ::com::sun::star::uno::Sequence< typename Map::key_type > MapKeysToSequence(
143 const Map & rCont )
145 ::com::sun::star::uno::Sequence< typename Map::key_type > aResult( rCont.size());
146 ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
147 ::o3tl::select1st< typename Map::value_type >());
148 return aResult;
151 /** converts the values of a Pair Associative Container into a UNO sequence
153 example:
155 ::std::map< sal_Int32, OUString > aMyMultiMap;
156 uno::Sequence< OUString > aMyValues( ContainerHelper::MapValuesToSequence( aMyMultiMap ));
158 template< class Map >
159 ::com::sun::star::uno::Sequence< typename Map::mapped_type > MapValuesToSequence(
160 const Map & rCont )
162 ::com::sun::star::uno::Sequence< typename Map::mapped_type > aResult( rCont.size());
163 ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
164 ::o3tl::select2nd< typename Map::value_type >());
165 return aResult;
168 } // namespace ContainerHelper
169 } // namespace chart
171 // INCLUDED_CHART2_SOURCE_INC_CONTAINERHELPER_HXX
172 #endif
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */