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 #if ! defined(COMPHELPER_MAKESEQUENCE_HXX_INCLUDED)
25 #define COMPHELPER_MAKESEQUENCE_HXX_INCLUDED
26 
27 #include "com/sun/star/uno/Sequence.hxx"
28 #include "boost/preprocessor/cat.hpp"
29 #include "boost/preprocessor/repetition.hpp"
30 #include "boost/preprocessor/arithmetic/add.hpp"
31 
32 namespace comphelper {
33 
34 /** Creates a uno::Sequence out of one parameter.
35 */
36 template <typename T>
makeSequence(T const & element)37 inline ::com::sun::star::uno::Sequence<T> makeSequence( T const& element )
38 {
39     return ::com::sun::star::uno::Sequence<T>( &element, 1 );
40 }
41 
42 #define COMPHELPER_MAKESEQUENCE_assign(z_, n_, unused_) \
43     p[n_] = BOOST_PP_CAT(element, n_);
44 
45 /** The following preprocessor repetitions generate functions like
46 
47     <pre>
48         template <typename T>
49         inline ::com::sun::star::uno::Sequence<T> makeSequence(
50             T const& element0, T const& element1, ... );
51     </pre>
52 
53     which make a sequence out of the passed elements.
54 
55     The maximum number of elements can be set by defining
56     COMPHELPER_MAKESEQUENCE_MAX_ARGS; its default is 12.
57 */
58 #define COMPHELPER_MAKESEQUENCE_make(z_, n_, unused_) \
59 template <typename T> \
60 inline ::com::sun::star::uno::Sequence<T> makeSequence( \
61     BOOST_PP_ENUM_PARAMS(n_, T const& element) ) \
62 { \
63     ::com::sun::star::uno::Sequence<T> seq( n_ ); \
64     T * p = seq.getArray(); \
65     BOOST_PP_REPEAT(n_, COMPHELPER_MAKESEQUENCE_assign, ~) \
66     return seq; \
67 }
68 
69 #if ! defined(COMPHELPER_MAKESEQUENCE_MAX_ARGS)
70 #define COMPHELPER_MAKESEQUENCE_MAX_ARGS 12
71 #endif
72 
73 BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_ADD(COMPHELPER_MAKESEQUENCE_MAX_ARGS, 1),
74                         COMPHELPER_MAKESEQUENCE_make, ~)
75 
76 #undef COMPHELPER_MAKESEQUENCE_MAX_ARGS
77 #undef COMPHELPER_MAKESEQUENCE_make
78 #undef COMPHELPER_MAKESEQUENCE_assign
79 
80 } // namespace comphelper
81 
82 #endif //  ! defined(COMPHELPER_MAKESEQUENCE_HXX_INCLUDED)
83 
84