update emoji autocorrect entries from po-files
[LibreOffice.git] / include / comphelper / sequenceasvector.hxx
blob6b85e7233438499f584701206f5dd73e65d7e145
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_COMPHELPER_SEQUENCEASVECTOR_HXX
21 #define INCLUDED_COMPHELPER_SEQUENCEASVECTOR_HXX
23 #include <vector>
24 #include <algorithm>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/beans/IllegalTypeException.hpp>
29 /** This should not be used. Use the functions in
30 * comphelper/vectortosequence.hxx
31 * @deprecated
34 namespace comphelper{
37 /** @short Implements a stl vector on top of any
38 uno sequence.
40 @descr That provides the possibility to modify
41 sequences very easy ...
42 Of course this can be useful only, if
43 count of modifications is high, so copying
44 of the sequence make sense!
46 template< class TElementType >
47 class SequenceAsVector : public ::std::vector< TElementType >
50 // types
52 public:
55 /** @short When inheriting from a template using typename is generally required when using
56 types from the base! */
57 typedef typename ::std::vector< TElementType >::const_iterator const_iterator;
60 /** @short When inheriting from a template using typename is generally required when using
61 types from the base! */
62 typedef typename ::std::vector< TElementType >::iterator iterator;
65 // interface
66 public:
69 /** @short default ctor, to create an empty list.
71 SequenceAsVector()
75 /** @short default dtor
77 ~SequenceAsVector()
81 /** @short creates a new vector with the given length.
83 @param nLength
84 the number of elements for the new vector.
86 explicit SequenceAsVector(sal_Int32 nLength) :
87 ::std::vector< TElementType >( static_cast< size_t >( nLength ) )
92 /** @short creates a new deque from the given uno sequence.
94 @param lSource
95 contains the new items for this deque.
97 SequenceAsVector(const ::com::sun::star::uno::Sequence< TElementType >& lSource)
99 (*this) << lSource;
103 /** @short creates a new instance from the given Any, which
104 of course must contain a valid sequence using the
105 right element type for every item.
107 @attention If the given Any is an empty one
108 (if its set to VOID), no exception
109 is thrown. In such case this instance will
110 be created as an empty one too!
112 @param aSource
113 this any must contain a suitable sequence. :-)
115 @throw A com::sun::star::beans::IllegalTypeException
116 if an unsupported element inside this Any
117 is given. An empty Any reset this instance!
119 SequenceAsVector(const ::com::sun::star::uno::Any& aSource)
121 (*this) << aSource;
125 /** @short fill this instance from the given uno sequence.
127 @param lSource
128 contains the new items for this deque.
130 void operator<<(const ::com::sun::star::uno::Sequence< TElementType >& lSource)
132 this->clear();
134 sal_Int32 c = lSource.getLength();
135 const TElementType* pSource = lSource.getConstArray();
137 for (sal_Int32 i=0; i<c; ++i)
138 this->push_back(pSource[i]);
142 /** @short fill this instance from the given Any, which
143 of course must contain a valid sequence using the
144 right element type for every item.
146 @attention If the given Any is an empty one
147 (if its set to VOID), no exception
148 is thrown. In such case this instance will
149 be created as an empty one too!
151 @param aSource
152 this any must contain a suitable sequence. :-)
154 @throw A com::sun::star::beans::IllegalTypeException
155 if an unsupported element inside this Any
156 is given. An empty Any reset this instance!
158 void operator<<(const ::com::sun::star::uno::Any& aSource)
160 // An empty Any reset this instance!
161 if (!aSource.hasValue())
163 this->clear();
164 return;
167 ::com::sun::star::uno::Sequence< TElementType > lSource;
168 if (!(aSource >>= lSource))
169 throw ::com::sun::star::beans::IllegalTypeException(
170 OUString("SequenceAsVector operator<<(Any) was called with an unsupported Any type."),
171 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
173 (*this) << lSource;
177 /** @short converts this instance to an uno sequence.
179 @param lDestination
180 target sequence for converting.
182 void operator>>(::com::sun::star::uno::Sequence< TElementType >& lDestination) const
184 sal_Int32 c = static_cast<sal_Int32>(this->size());
185 lDestination.realloc(c);
186 TElementType* pDestination = lDestination.getArray();
188 sal_Int32 i = 0;
189 for (typename std::vector<TElementType>::const_iterator pThis = this->begin();
190 pThis != this->end() ;
191 ++pThis )
193 pDestination[i] = *pThis;
194 ++i;
199 /** @short converts this instance to an uno any
200 which contains a suitable sequence
201 of items of this stl struct.
203 @param aDestination
204 target any for converting.
206 void operator>>(::com::sun::star::uno::Any& aDestination) const
208 sal_Int32 c = static_cast<sal_Int32>(this->size());
209 ::com::sun::star::uno::Sequence< TElementType > lDestination(c);
210 TElementType* pDestination = lDestination.getArray();
212 sal_Int32 i = 0;
213 for (typename std::vector<TElementType>::const_iterator pThis = this->begin();
214 pThis != this->end() ;
215 ++pThis )
217 pDestination[i] = *pThis;
218 ++i;
221 aDestination <<= lDestination;
225 /** @short converts this deque to a suitable uno
226 sequence which contains all items.
228 @attention It return a const sequence to prevent
229 the outside code against using of this
230 return value as [in/]out parameter for
231 direct function calls!
232 Of course it can be casted to non const
233 ... but then it's a problem of the outside
234 code :-)
236 @return A (const!) sequence, which contains all items of
237 this deque.
239 const ::com::sun::star::uno::Sequence< TElementType > getAsConstList() const
241 ::com::sun::star::uno::Sequence< TElementType > lDestination;
242 (*this) >> lDestination;
243 return lDestination;
247 } // namespace comphelper
249 #endif // INCLUDED_COMPHELPER_SEQUENCEASVECTOR_HXX
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */