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