1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9877b273SAndrew Rist  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9877b273SAndrew Rist  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19*9877b273SAndrew Rist  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _COMPHELPER_STLUNOITERATOR_HXX
25cdf0e10cSrcweir #define _COMPHELPER_STLUNOITERATOR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
28cdf0e10cSrcweir #include <sal/types.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace comphelper
32cdf0e10cSrcweir {
33cdf0e10cSrcweir     /**
34cdf0e10cSrcweir     @short stl-container-like access to an existing ::com::sun::star::uno::Sequence
35cdf0e10cSrcweir     @descr These template functions allows using an existing
36cdf0e10cSrcweir     ::com::sun::star::uno::Sequence using stl algorithms. They provides
37cdf0e10cSrcweir     standard-compliant mutable random access iterators. Because random access
38cdf0e10cSrcweir     iterators are the most generic iterators defined by the stl, any stl algorithm
39cdf0e10cSrcweir     can be applied to the Sequence (excluding algorithms requiring output
40cdf0e10cSrcweir     iterators).
41cdf0e10cSrcweir     <p>
42cdf0e10cSrcweir     Example: (creating a ::std::list from a ::com::sun::star::uno::Sequence)
43cdf0e10cSrcweir     <code>
44cdf0e10cSrcweir     ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10);
45cdf0e10cSrcweir     ::std::list stl_list(stl_begin(aSeq), stl_end(aSeq));
46cdf0e10cSrcweir     </code>
47cdf0e10cSrcweir     <p>
48cdf0e10cSrcweir     Example: (sorting ::com::sun::star::uno::Sequence inplace)
49cdf0e10cSrcweir     <code>
50cdf0e10cSrcweir     ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10);
51cdf0e10cSrcweir     ::std::sort(stl_begin(aSeq), stl_seq.end(aSeq));
52cdf0e10cSrcweir     </code>
53cdf0e10cSrcweir     <p>
54cdf0e10cSrcweir     Example: (counting occurrences of 4711 in a ::com::sun::star::uno::Sequence)
55cdf0e10cSrcweir     <code>
56cdf0e10cSrcweir     ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10);
57cdf0e10cSrcweir     sal_Int32 count = 0;
58cdf0e10cSrcweir     ::std::count(stl_begin(aSeq), stl_end(aSeq), 4711, count);
59cdf0e10cSrcweir     </code>
60cdf0e10cSrcweir     <p>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     @see http://www.sgi.com/tech/stl/Container.html
63cdf0e10cSrcweir     @see http://www.sgi.com/tech/stl/Sequence.html
64cdf0e10cSrcweir     @see http://www.sgi.com/tech/stl/RandomAccessIterator.html
65cdf0e10cSrcweir     */
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     template <typename V>
stl_begin(::com::sun::star::uno::Sequence<V> & rSeq)68cdf0e10cSrcweir     V* stl_begin(::com::sun::star::uno::Sequence<V>& rSeq)
69cdf0e10cSrcweir         { return rSeq.getArray(); }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     template <typename V>
stl_end(::com::sun::star::uno::Sequence<V> & rSeq)72cdf0e10cSrcweir     V* stl_end(::com::sun::star::uno::Sequence<V>& rSeq)
73cdf0e10cSrcweir         { return rSeq.getArray() + rSeq.getLength(); }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     template <typename V>
stl_begin(const::com::sun::star::uno::Sequence<V> & rSeq)76cdf0e10cSrcweir     const V* stl_begin(const ::com::sun::star::uno::Sequence<V>& rSeq)
77cdf0e10cSrcweir         { return rSeq.getConstArray(); }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     template <typename V>
stl_end(const::com::sun::star::uno::Sequence<V> & rSeq)80cdf0e10cSrcweir     const V* stl_end(const ::com::sun::star::uno::Sequence<V>& rSeq)
81cdf0e10cSrcweir         { return rSeq.getConstArray() + rSeq.getLength(); }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir #endif
84