1*e3508121SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e3508121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e3508121SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e3508121SAndrew Rist * distributed with this work for additional information
6*e3508121SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e3508121SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e3508121SAndrew Rist * "License"); you may not use this file except in compliance
9*e3508121SAndrew Rist * with the License. You may obtain a copy of the License at
10*e3508121SAndrew Rist *
11*e3508121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e3508121SAndrew Rist *
13*e3508121SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e3508121SAndrew Rist * software distributed under the License is distributed on an
15*e3508121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e3508121SAndrew Rist * KIND, either express or implied. See the License for the
17*e3508121SAndrew Rist * specific language governing permissions and limitations
18*e3508121SAndrew Rist * under the License.
19*e3508121SAndrew Rist *
20*e3508121SAndrew Rist *************************************************************/
21*e3508121SAndrew Rist
22*e3508121SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef OOX_HELPER_CONTAINERHELPER_HXX
25cdf0e10cSrcweir #define OOX_HELPER_CONTAINERHELPER_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir #include <vector>
29cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h>
31cdf0e10cSrcweir
32cdf0e10cSrcweir namespace rtl { class OUString; }
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace com { namespace sun { namespace star {
35cdf0e10cSrcweir namespace container { class XIndexAccess; }
36cdf0e10cSrcweir namespace container { class XIndexContainer; }
37cdf0e10cSrcweir namespace container { class XNameAccess; }
38cdf0e10cSrcweir namespace container { class XNameContainer; }
39cdf0e10cSrcweir namespace uno { class XComponentContext; }
40cdf0e10cSrcweir } } }
41cdf0e10cSrcweir
42cdf0e10cSrcweir namespace oox {
43cdf0e10cSrcweir
44cdf0e10cSrcweir // ============================================================================
45cdf0e10cSrcweir
46cdf0e10cSrcweir /** A range of signed 32-bit integer values. */
47cdf0e10cSrcweir struct ValueRange
48cdf0e10cSrcweir {
49cdf0e10cSrcweir sal_Int32 mnFirst;
50cdf0e10cSrcweir sal_Int32 mnLast;
51cdf0e10cSrcweir
ValueRangeoox::ValueRange52cdf0e10cSrcweir inline explicit ValueRange( sal_Int32 nValue = 0 ) : mnFirst( nValue ), mnLast( nValue ) {}
ValueRangeoox::ValueRange53cdf0e10cSrcweir inline explicit ValueRange( sal_Int32 nFirst, sal_Int32 nLast ) : mnFirst( nFirst ), mnLast( nLast ) {}
54cdf0e10cSrcweir
operator ==oox::ValueRange55cdf0e10cSrcweir inline bool operator==( const ValueRange& rRange ) const { return (mnFirst == rRange.mnFirst) && (mnLast == rRange.mnLast); }
operator !=oox::ValueRange56cdf0e10cSrcweir inline bool operator!=( const ValueRange& rRange ) const { return !(*this == rRange); }
containsoox::ValueRange57cdf0e10cSrcweir inline bool contains( sal_Int32 nValue ) const { return (mnFirst <= nValue) && (nValue <= mnLast); }
containsoox::ValueRange58cdf0e10cSrcweir inline bool contains( const ValueRange& rRange ) const { return (mnFirst <= rRange.mnFirst) && (rRange.mnLast <= mnLast); }
intersectsoox::ValueRange59cdf0e10cSrcweir inline bool intersects( const ValueRange& rRange ) const { return (mnFirst <= rRange.mnLast) && (rRange.mnFirst <= mnLast); }
60cdf0e10cSrcweir };
61cdf0e10cSrcweir
62cdf0e10cSrcweir // ----------------------------------------------------------------------------
63cdf0e10cSrcweir
64cdf0e10cSrcweir typedef ::std::vector< ValueRange > ValueRangeVector;
65cdf0e10cSrcweir
66cdf0e10cSrcweir // ----------------------------------------------------------------------------
67cdf0e10cSrcweir
68cdf0e10cSrcweir /** An ordered list of value ranges. The insertion operation will merge
69cdf0e10cSrcweir consecutive value ranges.
70cdf0e10cSrcweir */
71cdf0e10cSrcweir class ValueRangeSet
72cdf0e10cSrcweir {
73cdf0e10cSrcweir public:
ValueRangeSet()74cdf0e10cSrcweir inline explicit ValueRangeSet() {}
75cdf0e10cSrcweir
76cdf0e10cSrcweir /** Inserts the passed value into the range list. */
insert(sal_Int32 nValue)77cdf0e10cSrcweir inline void insert( sal_Int32 nValue ) { insert( ValueRange( nValue ) ); }
78cdf0e10cSrcweir /** Inserts the passed value range into the range list. */
79cdf0e10cSrcweir void insert( const ValueRange& rRange );
80cdf0e10cSrcweir
81cdf0e10cSrcweir /** Returns the ordered list of all value ranges. */
getRanges() const82cdf0e10cSrcweir inline const ValueRangeVector& getRanges() const { return maRanges; }
83cdf0e10cSrcweir /** Returns an intersection of the range list and the passed range. */
84cdf0e10cSrcweir ValueRangeVector getIntersection( const ValueRange& rRange ) const;
85cdf0e10cSrcweir
86cdf0e10cSrcweir private:
87cdf0e10cSrcweir ValueRangeVector maRanges;
88cdf0e10cSrcweir };
89cdf0e10cSrcweir
90cdf0e10cSrcweir // ============================================================================
91cdf0e10cSrcweir
92cdf0e10cSrcweir /** Template for a 2-dimensional array of objects.
93cdf0e10cSrcweir
94cdf0e10cSrcweir This class template provides a similar interface to the ::std::vector
95cdf0e10cSrcweir template.
96cdf0e10cSrcweir */
97cdf0e10cSrcweir template< typename Type >
98cdf0e10cSrcweir class Matrix
99cdf0e10cSrcweir {
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir typedef ::std::vector< Type > container_type;
102cdf0e10cSrcweir typedef typename container_type::value_type value_type;
103cdf0e10cSrcweir typedef typename container_type::pointer pointer;
104cdf0e10cSrcweir typedef typename container_type::reference reference;
105cdf0e10cSrcweir typedef typename container_type::const_reference const_reference;
106cdf0e10cSrcweir typedef typename container_type::size_type size_type;
107cdf0e10cSrcweir typedef typename container_type::iterator iterator;
108cdf0e10cSrcweir typedef typename container_type::const_iterator const_iterator;
109cdf0e10cSrcweir
Matrix()110cdf0e10cSrcweir inline explicit Matrix() : mnWidth( 0 ) {}
Matrix(size_type nWidth,size_type nHeight)111cdf0e10cSrcweir inline explicit Matrix( size_type nWidth, size_type nHeight ) { this->resize( nWidth, nHeight ); }
Matrix(size_type nWidth,size_type nHeight,const_reference rData)112cdf0e10cSrcweir inline explicit Matrix( size_type nWidth, size_type nHeight, const_reference rData ) { this->resize( nWidth, nHeight, rData ); }
113cdf0e10cSrcweir
capacity() const114cdf0e10cSrcweir inline size_type capacity() const { return maData.capacity(); }
empty() const115cdf0e10cSrcweir inline bool empty() const { return maData.empty(); }
size() const116cdf0e10cSrcweir inline size_type size() const { return maData.size(); }
width() const117cdf0e10cSrcweir inline size_type width() const { return mnWidth; }
height() const118cdf0e10cSrcweir inline size_type height() const { return this->empty() ? 0 : (this->size() / this->width()); }
has(size_type nX,size_type nY) const119cdf0e10cSrcweir inline bool has( size_type nX, size_type nY ) const { return (nX < this->width()) && (nY < this->height()); }
120cdf0e10cSrcweir
reserve(size_type nWidth,size_type nHeight)121cdf0e10cSrcweir inline void reserve( size_type nWidth, size_type nHeight ) { maData.reserve( nWidth * nHeight ); }
clear()122cdf0e10cSrcweir inline void clear() { this->resize( 0, 0 ); }
resize(size_type nWidth,size_type nHeight)123cdf0e10cSrcweir inline void resize( size_type nWidth, size_type nHeight ) { mnWidth = nWidth; maData.resize( nWidth * nHeight ); }
resize(size_type nWidth,size_type nHeight,const_reference rData)124cdf0e10cSrcweir inline void resize( size_type nWidth, size_type nHeight, const_reference rData ) { mnWidth = nWidth; maData.resize( nWidth * nHeight, rData ); }
125cdf0e10cSrcweir
at(size_type nX,size_type nY)126cdf0e10cSrcweir inline iterator at( size_type nX, size_type nY ) { return maData.begin() + mnWidth * nY + nX; }
at(size_type nX,size_type nY) const127cdf0e10cSrcweir inline const_iterator at( size_type nX, size_type nY ) const { return maData.begin() + mnWidth * nY + nX; }
128cdf0e10cSrcweir
operator ()(size_type nX,size_type nY)129cdf0e10cSrcweir inline reference operator()( size_type nX, size_type nY ) { return *this->at( nX, nY ); }
operator ()(size_type nX,size_type nY) const130cdf0e10cSrcweir inline const_reference operator()( size_type nX, size_type nY ) const { return *this->at( nX, nY ); }
131cdf0e10cSrcweir
begin()132cdf0e10cSrcweir inline iterator begin() { return maData.begin(); }
begin() const133cdf0e10cSrcweir inline const_iterator begin() const { return maData.begin(); }
end()134cdf0e10cSrcweir inline iterator end() { return maData.end(); }
end() const135cdf0e10cSrcweir inline const_iterator end() const { return maData.end(); }
136cdf0e10cSrcweir
front()137cdf0e10cSrcweir inline reference front() { return maData.front(); }
front() const138cdf0e10cSrcweir inline const_reference front() const { return maData.front(); }
back()139cdf0e10cSrcweir inline reference back() { return maData.back(); }
back() const140cdf0e10cSrcweir inline const_reference back() const { return maData.back(); }
141cdf0e10cSrcweir
row_begin(size_type nY)142cdf0e10cSrcweir inline iterator row_begin( size_type nY ) { return this->at( 0, nY ); }
row_begin(size_type nY) const143cdf0e10cSrcweir inline const_iterator row_begin( size_type nY ) const { return this->at( 0, nY ); }
row_end(size_type nY)144cdf0e10cSrcweir inline iterator row_end( size_type nY ) { return this->at( mnWidth, nY ); }
row_end(size_type nY) const145cdf0e10cSrcweir inline const_iterator row_end( size_type nY ) const { return this->at( mnWidth, nY ); }
146cdf0e10cSrcweir
row_front(size_type nY)147cdf0e10cSrcweir inline reference row_front( size_type nY ) { return (*this)( 0, nY ); }
row_front(size_type nY) const148cdf0e10cSrcweir inline const_reference row_front( size_type nY ) const { return (*this)( 0, nY ); }
row_back(size_type nY)149cdf0e10cSrcweir inline reference row_back( size_type nY ) { return (*this)( mnWidth - 1, nY ); }
row_back(size_type nY) const150cdf0e10cSrcweir inline const_reference row_back( size_type nY ) const { return (*this)( mnWidth - 1, nY ); }
151cdf0e10cSrcweir
swap(Matrix & rMatrix)152cdf0e10cSrcweir inline void swap( Matrix& rMatrix ) { maData.swap( rMatrix.maData ); }
153cdf0e10cSrcweir
154cdf0e10cSrcweir private:
155cdf0e10cSrcweir container_type maData;
156cdf0e10cSrcweir size_type mnWidth;
157cdf0e10cSrcweir };
158cdf0e10cSrcweir
159cdf0e10cSrcweir // ============================================================================
160cdf0e10cSrcweir
161cdf0e10cSrcweir /** Static helper functions for improved API container handling. */
162cdf0e10cSrcweir class ContainerHelper
163cdf0e10cSrcweir {
164cdf0e10cSrcweir public:
165cdf0e10cSrcweir // com.sun.star.container.XIndexContainer ---------------------------------
166cdf0e10cSrcweir
167cdf0e10cSrcweir /** Creates a new index container object from scratch. */
168cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
169cdf0e10cSrcweir createIndexContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
170cdf0e10cSrcweir
171cdf0e10cSrcweir /** Inserts an object into an indexed container.
172cdf0e10cSrcweir
173cdf0e10cSrcweir @param rxIndexContainer com.sun.star.container.XIndexContainer
174cdf0e10cSrcweir interface of the indexed container.
175cdf0e10cSrcweir
176cdf0e10cSrcweir @param nIndex Insertion index for the object.
177cdf0e10cSrcweir
178cdf0e10cSrcweir @param rObject The object to be inserted.
179cdf0e10cSrcweir
180cdf0e10cSrcweir @return True = object successfully inserted.
181cdf0e10cSrcweir */
182cdf0e10cSrcweir static bool insertByIndex(
183cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rxIndexContainer,
184cdf0e10cSrcweir sal_Int32 nIndex,
185cdf0e10cSrcweir const ::com::sun::star::uno::Any& rObject );
186cdf0e10cSrcweir
187cdf0e10cSrcweir // com.sun.star.container.XNameContainer ----------------------------------
188cdf0e10cSrcweir
189cdf0e10cSrcweir /** Creates a new name container object from scratch. */
190cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
191cdf0e10cSrcweir createNameContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
192cdf0e10cSrcweir
193cdf0e10cSrcweir /** Returns a name that is not used in the passed name container.
194cdf0e10cSrcweir
195cdf0e10cSrcweir @param rxNameAccess com.sun.star.container.XNameAccess interface of
196cdf0e10cSrcweir the name container.
197cdf0e10cSrcweir
198cdf0e10cSrcweir @param rSuggestedName Suggested name for the object.
199cdf0e10cSrcweir
200cdf0e10cSrcweir @return An unused name. Will be equal to the suggested name, if not
201cdf0e10cSrcweir contained, otherwise a numerical index will be appended.
202cdf0e10cSrcweir */
203cdf0e10cSrcweir static ::rtl::OUString getUnusedName(
204cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxNameAccess,
205cdf0e10cSrcweir const ::rtl::OUString& rSuggestedName,
206cdf0e10cSrcweir sal_Unicode cSeparator,
207cdf0e10cSrcweir sal_Int32 nFirstIndexToAppend = 1 );
208cdf0e10cSrcweir
209cdf0e10cSrcweir /** Inserts an object into a name container.
210cdf0e10cSrcweir
211cdf0e10cSrcweir @param rxNameContainer com.sun.star.container.XNameContainer interface
212cdf0e10cSrcweir of the name container.
213cdf0e10cSrcweir
214cdf0e10cSrcweir @param rName Exact name for the object.
215cdf0e10cSrcweir
216cdf0e10cSrcweir @param rObject The object to be inserted.
217cdf0e10cSrcweir
218cdf0e10cSrcweir @return True = object successfully inserted.
219cdf0e10cSrcweir */
220cdf0e10cSrcweir static bool insertByName(
221cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxNameContainer,
222cdf0e10cSrcweir const ::rtl::OUString& rName,
223cdf0e10cSrcweir const ::com::sun::star::uno::Any& rObject,
224cdf0e10cSrcweir bool bReplaceOldExisting = true );
225cdf0e10cSrcweir
226cdf0e10cSrcweir /** Inserts an object into a name container.
227cdf0e10cSrcweir
228cdf0e10cSrcweir The function will use an unused name to insert the object, based on the
229cdf0e10cSrcweir suggested object name. It is possible to specify whether the existing
230cdf0e10cSrcweir object or the new inserted object will be renamed, if the container
231cdf0e10cSrcweir already has an object with the name suggested for the new object.
232cdf0e10cSrcweir
233cdf0e10cSrcweir @param rxNameContainer com.sun.star.container.XNameContainer interface
234cdf0e10cSrcweir of the name container.
235cdf0e10cSrcweir
236cdf0e10cSrcweir @param rSuggestedName Suggested name for the object.
237cdf0e10cSrcweir
238cdf0e10cSrcweir @param rObject The object to be inserted.
239cdf0e10cSrcweir
240cdf0e10cSrcweir @param bRenameOldExisting Specifies behaviour if an object with the
241cdf0e10cSrcweir suggested name already exists. If false (default), the new object
242cdf0e10cSrcweir will be inserted with a name not yet extant in the container (this
243cdf0e10cSrcweir is done by appending a numerical index to the suggested name). If
244cdf0e10cSrcweir true, the existing object will be removed and inserted with an
245cdf0e10cSrcweir unused name, and the new object will be inserted with the suggested
246cdf0e10cSrcweir name.
247cdf0e10cSrcweir
248cdf0e10cSrcweir @return The final name the object is inserted with. Will always be
249cdf0e10cSrcweir equal to the suggested name, if parameter bRenameOldExisting is
250cdf0e10cSrcweir true.
251cdf0e10cSrcweir */
252cdf0e10cSrcweir static ::rtl::OUString insertByUnusedName(
253cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxNameContainer,
254cdf0e10cSrcweir const ::rtl::OUString& rSuggestedName,
255cdf0e10cSrcweir sal_Unicode cSeparator,
256cdf0e10cSrcweir const ::com::sun::star::uno::Any& rObject,
257cdf0e10cSrcweir bool bRenameOldExisting = false );
258cdf0e10cSrcweir
259cdf0e10cSrcweir // std::vector and std::map element access --------------------------------
260cdf0e10cSrcweir
261cdf0e10cSrcweir /** Returns the pointer to an existing element of the passed vector, or a
262cdf0e10cSrcweir null pointer, if the passed index is out of bounds. */
263cdf0e10cSrcweir template< typename VectorType >
264cdf0e10cSrcweir static const typename VectorType::value_type*
265cdf0e10cSrcweir getVectorElement( const VectorType& rVector, sal_Int32 nIndex );
266cdf0e10cSrcweir
267cdf0e10cSrcweir /** Returns the pointer to an existing element of the passed vector, or a
268cdf0e10cSrcweir null pointer, if the passed index is out of bounds. */
269cdf0e10cSrcweir template< typename VectorType >
270cdf0e10cSrcweir static typename VectorType::value_type*
271cdf0e10cSrcweir getVectorElementAccess( VectorType& rVector, sal_Int32 nIndex );
272cdf0e10cSrcweir
273cdf0e10cSrcweir /** Returns the reference to an existing element of the passed vector, or
274cdf0e10cSrcweir the passed default value, if the passed index is out of bounds. */
275cdf0e10cSrcweir template< typename VectorType >
276cdf0e10cSrcweir static const typename VectorType::value_type&
277cdf0e10cSrcweir getVectorElement( const VectorType& rVector, sal_Int32 nIndex, const typename VectorType::value_type& rDefault );
278cdf0e10cSrcweir
279cdf0e10cSrcweir /** Returns the reference to an existing element of the passed vector, or
280cdf0e10cSrcweir the passed default value, if the passed index is out of bounds. */
281cdf0e10cSrcweir template< typename VectorType >
282cdf0e10cSrcweir static typename VectorType::value_type&
283cdf0e10cSrcweir getVectorElementAccess( VectorType& rVector, sal_Int32 nIndex, typename VectorType::value_type& rDefault );
284cdf0e10cSrcweir
285cdf0e10cSrcweir /** Returns the pointer to an existing element of the passed map, or a null
286cdf0e10cSrcweir pointer, if an element with the passed key does not exist. */
287cdf0e10cSrcweir template< typename MapType >
288cdf0e10cSrcweir static const typename MapType::mapped_type*
289cdf0e10cSrcweir getMapElement( const MapType& rMap, const typename MapType::key_type& rKey );
290cdf0e10cSrcweir
291cdf0e10cSrcweir /** Returns the pointer to an existing element of the passed map, or a null
292cdf0e10cSrcweir pointer, if an element with the passed key does not exist. */
293cdf0e10cSrcweir template< typename MapType >
294cdf0e10cSrcweir static typename MapType::mapped_type*
295cdf0e10cSrcweir getMapElementAccess( MapType& rMap, const typename MapType::key_type& rKey );
296cdf0e10cSrcweir
297cdf0e10cSrcweir /** Returns the reference to an existing element of the passed map, or the
298cdf0e10cSrcweir passed default value, if an element with the passed key does not exist. */
299cdf0e10cSrcweir template< typename MapType >
300cdf0e10cSrcweir static const typename MapType::mapped_type&
301cdf0e10cSrcweir getMapElement( const MapType& rMap, const typename MapType::key_type& rKey, const typename MapType::mapped_type& rDefault );
302cdf0e10cSrcweir
303cdf0e10cSrcweir /** Returns the reference to an existing element of the passed map, or the
304cdf0e10cSrcweir passed default value, if an element with the passed key does not exist. */
305cdf0e10cSrcweir template< typename MapType >
306cdf0e10cSrcweir static typename MapType::mapped_type&
307cdf0e10cSrcweir getMapElementAccess( MapType& rMap, const typename MapType::key_type& rKey, typename MapType::mapped_type& rDefault );
308cdf0e10cSrcweir
309cdf0e10cSrcweir // vector/map/matrix to UNO sequence --------------------------------------
310cdf0e10cSrcweir
311cdf0e10cSrcweir /** Creates a UNO sequence from a std::vector with copies of all elements.
312cdf0e10cSrcweir
313cdf0e10cSrcweir @param rVector The vector to be converted to a sequence.
314cdf0e10cSrcweir
315cdf0e10cSrcweir @return A com.sun.star.uno.Sequence object with copies of all objects
316cdf0e10cSrcweir contained in the passed vector.
317cdf0e10cSrcweir */
318cdf0e10cSrcweir template< typename VectorType >
319cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< typename VectorType::value_type >
320cdf0e10cSrcweir vectorToSequence( const VectorType& rVector );
321cdf0e10cSrcweir
322cdf0e10cSrcweir /** Creates a UNO sequence from a std::map with copies of all elements.
323cdf0e10cSrcweir
324cdf0e10cSrcweir @param rMap The map to be converted to a sequence.
325cdf0e10cSrcweir
326cdf0e10cSrcweir @return A com.sun.star.uno.Sequence object with copies of all objects
327cdf0e10cSrcweir contained in the passed map.
328cdf0e10cSrcweir */
329cdf0e10cSrcweir template< typename MapType >
330cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< typename MapType::mapped_type >
331cdf0e10cSrcweir mapToSequence( const MapType& rMap );
332cdf0e10cSrcweir
333cdf0e10cSrcweir /** Creates a UNO sequence of sequences from a matrix with copies of all elements.
334cdf0e10cSrcweir
335cdf0e10cSrcweir @param rMatrix The matrix to be converted to a sequence of sequences.
336cdf0e10cSrcweir
337cdf0e10cSrcweir @return A com.sun.star.uno.Sequence object containing
338cdf0e10cSrcweir com.sun.star.uno.Sequence objects with copies of all objects
339cdf0e10cSrcweir contained in the passed matrix.
340cdf0e10cSrcweir */
341cdf0e10cSrcweir template< typename MatrixType >
342cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< typename MatrixType::value_type > >
343cdf0e10cSrcweir matrixToSequenceSequence( const MatrixType& rMatrix );
344cdf0e10cSrcweir };
345cdf0e10cSrcweir
346cdf0e10cSrcweir // ----------------------------------------------------------------------------
347cdf0e10cSrcweir
348cdf0e10cSrcweir template< typename VectorType >
getVectorElement(const VectorType & rVector,sal_Int32 nIndex)349cdf0e10cSrcweir /*static*/ const typename VectorType::value_type* ContainerHelper::getVectorElement( const VectorType& rVector, sal_Int32 nIndex )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir return ((0 <= nIndex) && (static_cast< size_t >( nIndex ) < rVector.size())) ? &rVector[ static_cast< size_t >( nIndex ) ] : 0;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir template< typename VectorType >
getVectorElementAccess(VectorType & rVector,sal_Int32 nIndex)355cdf0e10cSrcweir /*static*/ typename VectorType::value_type* ContainerHelper::getVectorElementAccess( VectorType& rVector, sal_Int32 nIndex )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir return ((0 <= nIndex) && (static_cast< size_t >( nIndex ) < rVector.size())) ? &rVector[ static_cast< size_t >( nIndex ) ] : 0;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir template< typename VectorType >
getVectorElement(const VectorType & rVector,sal_Int32 nIndex,const typename VectorType::value_type & rDefault)361cdf0e10cSrcweir /*static*/ const typename VectorType::value_type& ContainerHelper::getVectorElement( const VectorType& rVector, sal_Int32 nIndex, const typename VectorType::value_type& rDefault )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir return ((0 <= nIndex) && (static_cast< size_t >( nIndex ) < rVector.size())) ? rVector[ static_cast< size_t >( nIndex ) ] : rDefault;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir
366cdf0e10cSrcweir template< typename VectorType >
getVectorElementAccess(VectorType & rVector,sal_Int32 nIndex,typename VectorType::value_type & rDefault)367cdf0e10cSrcweir /*static*/ typename VectorType::value_type& ContainerHelper::getVectorElementAccess( VectorType& rVector, sal_Int32 nIndex, typename VectorType::value_type& rDefault )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir return ((0 <= nIndex) && (static_cast< size_t >( nIndex ) < rVector.size())) ? rVector[ static_cast< size_t >( nIndex ) ] : rDefault;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir
372cdf0e10cSrcweir template< typename MapType >
getMapElement(const MapType & rMap,const typename MapType::key_type & rKey)373cdf0e10cSrcweir /*static*/ const typename MapType::mapped_type* ContainerHelper::getMapElement( const MapType& rMap, const typename MapType::key_type& rKey )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir typename MapType::const_iterator aIt = rMap.find( rKey );
376cdf0e10cSrcweir return (aIt == rMap.end()) ? 0 : &aIt->second;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir template< typename MapType >
getMapElementAccess(MapType & rMap,const typename MapType::key_type & rKey)380cdf0e10cSrcweir /*static*/ typename MapType::mapped_type* ContainerHelper::getMapElementAccess( MapType& rMap, const typename MapType::key_type& rKey )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir typename MapType::iterator aIt = rMap.find( rKey );
383cdf0e10cSrcweir return (aIt == rMap.end()) ? 0 : &aIt->second;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
386cdf0e10cSrcweir template< typename MapType >
getMapElement(const MapType & rMap,const typename MapType::key_type & rKey,const typename MapType::mapped_type & rDefault)387cdf0e10cSrcweir /*static*/ const typename MapType::mapped_type& ContainerHelper::getMapElement( const MapType& rMap, const typename MapType::key_type& rKey, const typename MapType::mapped_type& rDefault )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir typename MapType::const_iterator aIt = rMap.find( rKey );
390cdf0e10cSrcweir return (aIt == rMap.end()) ? rDefault : aIt->second;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir template< typename MapType >
getMapElementAccess(MapType & rMap,const typename MapType::key_type & rKey,typename MapType::mapped_type & rDefault)394cdf0e10cSrcweir /*static*/ typename MapType::mapped_type& ContainerHelper::getMapElementAccess( MapType& rMap, const typename MapType::key_type& rKey, typename MapType::mapped_type& rDefault )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir typename MapType::iterator aIt = rMap.find( rKey );
397cdf0e10cSrcweir return (aIt == rMap.end()) ? rDefault : aIt->second;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir template< typename VectorType >
vectorToSequence(const VectorType & rVector)401cdf0e10cSrcweir /*static*/ ::com::sun::star::uno::Sequence< typename VectorType::value_type > ContainerHelper::vectorToSequence( const VectorType& rVector )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir typedef typename VectorType::value_type ValueType;
404cdf0e10cSrcweir if( rVector.empty() )
405cdf0e10cSrcweir return ::com::sun::star::uno::Sequence< ValueType >();
406cdf0e10cSrcweir return ::com::sun::star::uno::Sequence< ValueType >( &rVector.front(), static_cast< sal_Int32 >( rVector.size() ) );
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
409cdf0e10cSrcweir template< typename MapType >
mapToSequence(const MapType & rMap)410cdf0e10cSrcweir /*static*/ ::com::sun::star::uno::Sequence< typename MapType::mapped_type > ContainerHelper::mapToSequence( const MapType& rMap )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir typedef typename MapType::mapped_type ValueType;
413cdf0e10cSrcweir if( rMap.empty() )
414cdf0e10cSrcweir return ::com::sun::star::uno::Sequence< ValueType >();
415cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ValueType > aSeq( static_cast< sal_Int32 >( rMap.size() ) );
416cdf0e10cSrcweir sal_Int32 nIndex = 0;
417cdf0e10cSrcweir for( typename MapType::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt, ++nIndex )
418cdf0e10cSrcweir aSeq[ nIndex ] = *aIt;
419cdf0e10cSrcweir return aSeq;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir
422cdf0e10cSrcweir template< typename MatrixType >
matrixToSequenceSequence(const MatrixType & rMatrix)423cdf0e10cSrcweir /*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< typename MatrixType::value_type > > ContainerHelper::matrixToSequenceSequence( const MatrixType& rMatrix )
424cdf0e10cSrcweir {
425cdf0e10cSrcweir typedef typename MatrixType::value_type ValueType;
426cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ValueType > > aSeq;
427cdf0e10cSrcweir if( !rMatrix.empty() )
428cdf0e10cSrcweir {
429cdf0e10cSrcweir aSeq.realloc( static_cast< sal_Int32 >( rMatrix.height() ) );
430cdf0e10cSrcweir for( size_t nRow = 0, nHeight = rMatrix.height(); nRow < nHeight; ++nRow )
431cdf0e10cSrcweir aSeq[ static_cast< sal_Int32 >( nRow ) ] =
432cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ValueType >( &rMatrix.row_front( nRow ), static_cast< sal_Int32 >( rMatrix.width() ) );
433cdf0e10cSrcweir }
434cdf0e10cSrcweir return aSeq;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
437cdf0e10cSrcweir // ============================================================================
438cdf0e10cSrcweir
439cdf0e10cSrcweir } // namespace oox
440cdf0e10cSrcweir
441cdf0e10cSrcweir #endif
442