LibreOffice Module comphelper (master)  1
namedvaluecollection.hxx
Go to the documentation of this file.
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 INCLUDED_COMPHELPER_NAMEDVALUECOLLECTION_HXX
21 #define INCLUDED_COMPHELPER_NAMEDVALUECOLLECTION_HXX
22 
24 
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/beans/NamedValue.hpp>
29 
30 #include <memory>
31 #include <vector>
32 
33 namespace comphelper
34 {
35 
36 
37  // = NamedValueCollection
38 
39  struct NamedValueCollection_Impl;
43  {
44  private:
45  ::std::unique_ptr< NamedValueCollection_Impl > m_pImpl;
46 
47  public:
49 
50  NamedValueCollection( const NamedValueCollection& _rCopySource );
51  NamedValueCollection(NamedValueCollection&& _rCopySource) noexcept;
52 
53  NamedValueCollection& operator=( const NamedValueCollection& i_rCopySource );
54  NamedValueCollection& operator=(NamedValueCollection&& i_rCopySource) noexcept;
55 
62  NamedValueCollection( const css::uno::Any& _rElements );
63 
68  NamedValueCollection( const css::uno::Sequence< css::uno::Any >& _rArguments );
69 
74  NamedValueCollection( const css::uno::Sequence< css::beans::PropertyValue >& _rArguments );
75 
80  NamedValueCollection( const css::uno::Sequence< css::beans::NamedValue >& _rArguments );
81 
83 
84  void assign( const css::uno::Sequence< css::uno::Any >& _rArguments )
85  {
86  impl_assign( _rArguments );
87  }
88 
89  void clear()
90  {
91  impl_assign( css::uno::Sequence< css::beans::NamedValue >() );
92  }
93 
100  static bool canExtractFrom( css::uno::Any const & i_value );
101 
103  size_t size() const;
104 
106  bool empty() const;
107 
110  ::std::vector< OUString >
111  getNames() const;
112 
122  merge(
123  const NamedValueCollection& _rAdditionalValues,
124  bool _bOverwriteExisting
125  );
126 
148  template < typename VALUE_TYPE >
149  bool get_ensureType( const char* _pAsciiValueName, VALUE_TYPE& _out_rValue ) const
150  {
151  return get_ensureType( OUString::createFromAscii( _pAsciiValueName ), &_out_rValue, ::cppu::UnoType< VALUE_TYPE >::get() );
152  }
153 
154  template < typename VALUE_TYPE >
155  void get_ensureType( const OUString& _rValueName, VALUE_TYPE& _out_rValue ) const
156  {
157  get_ensureType( _rValueName, &_out_rValue, ::cppu::UnoType< VALUE_TYPE >::get() );
158  }
159 
163  template < typename VALUE_TYPE >
164  VALUE_TYPE getOrDefault( const char* _pAsciiValueName, const VALUE_TYPE& _rDefault ) const
165  {
166  return getOrDefault( OUString::createFromAscii( _pAsciiValueName ), _rDefault );
167  }
168 
169  template < typename VALUE_TYPE >
170  VALUE_TYPE getOrDefault( const OUString& _rValueName, const VALUE_TYPE& _rDefault ) const
171  {
172  VALUE_TYPE retVal( _rDefault );
173  get_ensureType( _rValueName, retVal );
174  return retVal;
175  }
176 
182  const css::uno::Any& get( const char* _pAsciiValueName ) const
183  {
184  return get( OUString::createFromAscii( _pAsciiValueName ) );
185  }
186 
192  const css::uno::Any& get( const OUString& _rValueName ) const
193  {
194  return impl_get( _rValueName );
195  }
196 
198  bool has( const char* _pAsciiValueName ) const
199  {
200  return impl_has( OUString::createFromAscii( _pAsciiValueName ) );
201  }
202 
204  bool has( const OUString& _rValueName ) const
205  {
206  return impl_has( _rValueName );
207  }
208 
214  template < typename VALUE_TYPE >
215  bool put( const char* _pAsciiValueName, const VALUE_TYPE& _rValue )
216  {
217  return impl_put( OUString::createFromAscii( _pAsciiValueName ), css::uno::makeAny( _rValue ) );
218  }
219 
225  template < typename VALUE_TYPE >
226  bool put( const OUString& _rValueName, const VALUE_TYPE& _rValue )
227  {
228  return impl_put( _rValueName, css::uno::makeAny( _rValue ) );
229  }
230 
231  bool put( const char* _pAsciiValueName, const css::uno::Any& _rValue )
232  {
233  return impl_put( OUString::createFromAscii( _pAsciiValueName ), _rValue );
234  }
235 
236  bool put( const OUString& _rValueName, const css::uno::Any& _rValue )
237  {
238  return impl_put( _rValueName, _rValue );
239  }
240 
245  bool remove( const char* _pAsciiValueName )
246  {
247  return impl_remove( OUString::createFromAscii( _pAsciiValueName ) );
248  }
249 
254  bool remove( const OUString& _rValueName )
255  {
256  return impl_remove( _rValueName );
257  }
258 
264  sal_Int32 operator >>= ( css::uno::Sequence< css::beans::PropertyValue >& _out_rValues ) const;
265 
271  sal_Int32 operator >>= ( css::uno::Sequence< css::beans::NamedValue >& _out_rValues ) const;
272 
275  css::uno::Sequence< css::beans::PropertyValue >
277  {
278  css::uno::Sequence< css::beans::PropertyValue > aValues;
279  *this >>= aValues;
280  return aValues;
281  }
282 
285  css::uno::Sequence< css::uno::Any >
287  {
288  return impl_wrap< css::beans::PropertyValue >();
289  }
290 
293  css::uno::Sequence< css::uno::Any >
295  {
296  return impl_wrap< css::beans::NamedValue >();
297  }
298 
301  css::uno::Sequence< css::beans::NamedValue >
303  {
304  css::uno::Sequence< css::beans::NamedValue > aValues;
305  *this >>= aValues;
306  return aValues;
307  }
308 
309  private:
310  void impl_assign( const css::uno::Any& i_rWrappedElements );
311  void impl_assign( const css::uno::Sequence< css::uno::Any >& _rArguments );
312  void impl_assign( const css::uno::Sequence< css::beans::PropertyValue >& _rArguments );
313  void impl_assign( const css::uno::Sequence< css::beans::NamedValue >& _rArguments );
314 
315  bool get_ensureType(
316  const OUString& _rValueName,
317  void* _pValueLocation,
318  const css::uno::Type& _rExpectedValueType
319  ) const;
320 
321  const css::uno::Any&
322  impl_get( const OUString& _rValueName ) const;
323 
324  bool impl_has( const OUString& _rValueName ) const;
325 
326  bool impl_put( const OUString& _rValueName, const css::uno::Any& _rValue );
327 
328  bool impl_remove( const OUString& _rValueName );
329 
330  template< class VALUE_TYPE >
331  css::uno::Sequence< css::uno::Any > impl_wrap() const
332  {
333  css::uno::Sequence< VALUE_TYPE > aValues;
334  *this >>= aValues;
335  css::uno::Sequence< css::uno::Any > aWrappedValues( aValues.getLength() );
336 
337  css::uno::Any* pO = aWrappedValues.getArray();
338  const VALUE_TYPE* pV = aValues.getConstArray();
339  const sal_Int32 nLen = aValues.getLength();
340  for( sal_Int32 i = 0; i < nLen; ++i )
341  *(pO++) = css::uno::makeAny<VALUE_TYPE>( *(pV++) );
342 
343  return aWrappedValues;
344  }
345  };
346 
347 
348 } // namespace comphelper
349 
350 
351 #endif // INCLUDED_COMPHELPER_NAMEDVALUECOLLECTION_HXX
352 
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::beans::NamedValue > getNamedValues() const
transforms the collection into a sequence of NamedValues
css::uno::Sequence< css::uno::Any > getWrappedPropertyValues() const
returns a Sequence< Any >, containing PropertyValues
VALUE_TYPE getOrDefault(const char *_pAsciiValueName, const VALUE_TYPE &_rDefault) const
retrieves a value with a given name, or defaults it to a given value, if it's not present in the coll...
a collection of named values, packed in various formats.
css::uno::Sequence< css::uno::Any > impl_wrap() const
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
bool put(const char *_pAsciiValueName, const css::uno::Any &_rValue)
bool put(const OUString &_rValueName, const css::uno::Any &_rValue)
int i
css::uno::Sequence< css::uno::Any > getWrappedNamedValues() const
returns a Sequence< Any >, containing NamedValues
bool get_ensureType(const char *_pAsciiValueName, VALUE_TYPE &_out_rValue) const
retrieves a value with a given name from the collection, if it is present
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
transforms the collection into a sequence of PropertyValues
size
void get_ensureType(const OUString &_rValueName, VALUE_TYPE &_out_rValue) const
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
puts a value into the collection
::std::unique_ptr< NamedValueCollection_Impl > m_pImpl
bool put(const char *_pAsciiValueName, const VALUE_TYPE &_rValue)
puts a value into the collection
bool has(const OUString &_rValueName) const
determines whether a value with a given name is present in the collection
bool has(const char *_pAsciiValueName) const
determines whether a value with a given name is present in the collection
#define COMPHELPER_DLLPUBLIC