Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef COMPHELPER_MAKESEQUENCE_HXX_INCLUDED
21 : #define COMPHELPER_MAKESEQUENCE_HXX_INCLUDED
22 :
23 : #include "com/sun/star/uno/Sequence.hxx"
24 : #include "boost/preprocessor/cat.hpp"
25 : #include "boost/preprocessor/repetition.hpp"
26 : #include "boost/preprocessor/arithmetic/add.hpp"
27 :
28 : namespace comphelper {
29 :
30 : /** Creates a uno::Sequence out of one parameter.
31 : */
32 : template <typename T>
33 2 : inline ::com::sun::star::uno::Sequence<T> makeSequence( T const& element )
34 : {
35 2 : return ::com::sun::star::uno::Sequence<T>( &element, 1 );
36 : }
37 :
38 : #define COMPHELPER_MAKESEQUENCE_assign(z_, n_, unused_) \
39 : p[n_] = BOOST_PP_CAT(element, n_);
40 :
41 : /** The following preprocessor repetitions generate functions like
42 :
43 : <pre>
44 : template <typename T>
45 : inline ::com::sun::star::uno::Sequence<T> makeSequence(
46 : T const& element0, T const& element1, ... );
47 : </pre>
48 :
49 : which make a sequence out of the passed elements.
50 :
51 : The maximum number of elements can be set by defining
52 : COMPHELPER_MAKESEQUENCE_MAX_ARGS; its default is 12.
53 : */
54 : #define COMPHELPER_MAKESEQUENCE_make(z_, n_, unused_) \
55 : template <typename T> \
56 : inline ::com::sun::star::uno::Sequence<T> makeSequence( \
57 : BOOST_PP_ENUM_PARAMS(n_, T const& element) ) \
58 : { \
59 : ::com::sun::star::uno::Sequence<T> seq( n_ ); \
60 : T * p = seq.getArray(); \
61 : BOOST_PP_REPEAT(n_, COMPHELPER_MAKESEQUENCE_assign, ~) \
62 : return seq; \
63 : }
64 :
65 : #ifndef COMPHELPER_MAKESEQUENCE_MAX_ARGS
66 : #define COMPHELPER_MAKESEQUENCE_MAX_ARGS 12
67 : #endif
68 :
69 58 : BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_ADD(COMPHELPER_MAKESEQUENCE_MAX_ARGS, 1),
70 : COMPHELPER_MAKESEQUENCE_make, ~)
71 :
72 : #undef COMPHELPER_MAKESEQUENCE_MAX_ARGS
73 : #undef COMPHELPER_MAKESEQUENCE_make
74 : #undef COMPHELPER_MAKESEQUENCE_assign
75 :
76 : } // namespace comphelper
77 :
78 : #endif // ! defined(COMPHELPER_MAKESEQUENCE_HXX_INCLUDED)
79 :
80 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|