1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX
20 #define INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX
22 #include <com/sun/star/uno/Sequence.hxx>
31 /** Creates a UNO-Sequence which contains an arbitrary number of elements.
32 Notice, that every call of the operator() issues a realloc, so this is not
33 suitable to create very large sequences.
37 uno::Sequence< t >( MakeSequence< t >( t_1 )( t_2 )...( t_n ) );
39 template < typename T
>
40 class MakeSequence
: public ::com::sun::star::uno::Sequence
< T
>
43 explicit MakeSequence(const T
&a
)
44 : ::com::sun::star::uno::Sequence
< T
>( 1 )
46 this->operator[](0) = a
;
48 MakeSequence
& operator()(const T
&a
)
50 this->realloc( this->getLength() + 1 );
51 this->operator[]( this->getLength() - 1 ) = a
;
56 // ----------------------------------------
58 /** Creates a vector which contains an arbitrary number of elements.
62 vector< t > aVec( MakeVector< t >( t_1 )( t_2 )...( t_n ) );
64 template < typename T
>
65 class MakeVector
: public ::std::vector
< T
>
68 explicit MakeVector(const T
&a
)
69 : ::std::vector
< T
>(1, a
)
72 MakeVector
&operator()(const T
&a
)
79 // ----------------------------------------
81 /** Creates a set which contains an arbitrary number of elements.
85 set< t > aSet( MakeSet< t >( t_1 )( t_2 )...( t_n ) );
87 template < typename T
>
88 class MakeSet
: public ::std::set
< T
>
91 explicit MakeSet(const T
&a
)
94 this->insert(this->end(), a
);
96 MakeSet
&operator()(const T
&a
)
98 this->insert(this->end(), a
);
103 // ----------------------------------------
107 map< k, v > aMap( MakeMap< k, v >
115 template < typename Key
, typename Value
>
116 class MakeMap
: public ::std::map
< Key
, Value
>
119 typedef typename ::std::map
< Key
, Value
>::value_type value_type
;
121 explicit MakeMap( const Key
&k
, const Value
&v
)
123 this->insert( value_type( k
, v
) );
125 MakeMap
&operator()( const Key
&k
, const Value
&v
)
127 this->insert( value_type( k
, v
) );
131 MakeMap
&operator()( const MakeMap
& rSource
)
133 this->insert(rSource
.begin(),rSource
.end());
138 } // namespace comphelper
141 // INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */