LibreOffice Module comphelper (master)  1
sequenceashashmap.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_SEQUENCEASHASHMAP_HXX
21 #define INCLUDED_COMPHELPER_SEQUENCEASHASHMAP_HXX
22 
23 #include <unordered_map>
24 #include <com/sun/star/uno/Sequence.hxx>
25 
27 
28 namespace com { namespace sun { namespace star { namespace beans { struct NamedValue; } } } }
29 namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } }
30 
31 namespace comphelper{
32 
33 
42 using SequenceAsHashMapBase = std::unordered_map<OUString, css::uno::Any>;
43 
45 {
46 
47  public:
48 
49 
53 
54 
57  SequenceAsHashMap(const css::uno::Any& aSource);
58 
59 
62  SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource);
63 
64 
67  SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource);
68 
69 
72  SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource);
73 
74 
92  void operator<<(const css::uno::Any& aSource);
93 
94 
107  void operator<<(const css::uno::Sequence< css::uno::Any >& lSource);
108 
109 
116  void operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource);
117 
118 
125  void operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource);
126 
127 
134  void operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const;
135 
136 
143  void operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const;
144 
145 
161  css::uno::Any getAsConstAny(bool bAsPropertyValue) const;
162 
163 
175  css::uno::Sequence< css::beans::NamedValue > getAsConstNamedValueList() const;
176 
177 
189  css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const;
190 
191 
214  template< class TValueType >
215  TValueType getUnpackedValueOrDefault(const OUString& sKey ,
216  const TValueType& aDefault) const
217  {
218  auto pIt = m_aMap.find(sKey);
219  if (pIt == m_aMap.end())
220  return aDefault;
221 
222  TValueType aValue = TValueType();
223  if (!(pIt->second >>= aValue))
224  return aDefault;
225 
226  return aValue;
227  }
228 
244  css::uno::Any getValue(const OUString& sKey) const
245  {
246  auto pIt = m_aMap.find(sKey);
247  if (pIt == m_aMap.end())
248  return css::uno::Any();
249 
250  return pIt->second;
251  }
252 
253 
274  template< class TValueType >
275  bool createItemIfMissing(const OUString& sKey ,
276  const TValueType& aValue)
277  {
278  if (m_aMap.find(sKey) == m_aMap.end())
279  {
280  (*this)[sKey] = css::uno::toAny(aValue);
281  return true;
282  }
283 
284  return false;
285  }
286 
287 
303  bool match(const SequenceAsHashMap& rCheck) const;
304 
305 
316  void update(const SequenceAsHashMap& rSource);
317 
318  css::uno::Any& operator[](const OUString& rKey)
319  {
320  return m_aMap[rKey];
321  }
322 
323  using iterator = SequenceAsHashMapBase::iterator;
324  using const_iterator = SequenceAsHashMapBase::const_iterator;
325 
326  void clear()
327  {
328  m_aMap.clear();
329  }
330 
331  size_t size() const
332  {
333  return m_aMap.size();
334  }
335 
336  bool empty() const
337  {
338  return m_aMap.empty();
339  }
340 
342  {
343  return m_aMap.begin();
344  }
345 
347  {
348  return m_aMap.begin();
349  }
350 
352  {
353  return m_aMap.end();
354  }
355 
357  {
358  return m_aMap.end();
359  }
360 
361  iterator find(const OUString& rKey)
362  {
363  return m_aMap.find(rKey);
364  }
365 
366  const_iterator find(const OUString& rKey) const
367  {
368  return m_aMap.find(rKey);
369  }
370 
372  {
373  return m_aMap.erase(it);
374  }
375 
376  size_t erase(const OUString& rKey)
377  {
378  return m_aMap.erase(rKey);
379  }
380 
381 private:
383 };
384 
385 } // namespace comphelper
386 
387 #endif // INCLUDED_COMPHELPER_SEQUENCEASHASHMAP_HXX
388 
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SequenceAsHashMapBase::const_iterator const_iterator
css::uno::Any & operator[](const OUString &rKey)
bool update()
std::unordered_map< OUString, css::uno::Any > SequenceAsHashMapBase
Implements a stl hash map on top of some specialized sequence from type PropertyValue or NamedValue...
const_iterator begin() const
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)
const css::uno::Reference< css::io::XObjectOutputStream > & operator<<(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream, const css::awt::FontDescriptor &_rFont)
Definition: basicio.cxx:27
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
check if the specified item exists and return its (unpacked!) value or it returns the specified defau...
const_iterator find(const OUString &rKey) const
css::uno::Any getValue(const OUString &sKey) const
check if the specified item exists and return its value or it returns an empty css::uno::Any.
bool createItemIfMissing(const OUString &sKey, const TValueType &aValue)
creates a new item with the specified name and value only in case such item name does not already exi...
#define SAL_WARN_UNUSED
const css::uno::Reference< css::io::XObjectInputStream > & operator>>(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream, css::awt::FontDescriptor &_rFont)
Definition: basicio.cxx:52
iterator find(const OUString &rKey)
SequenceAsHashMapBase::iterator iterator
#define COMPHELPER_DLLPUBLIC
size_t erase(const OUString &rKey)