LibreOffice Module xmloff (master)  1
MultiPropertySetHelper.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 #pragma once
20 
21 #include <rtl/ustring.hxx>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <memory>
24 
25 namespace com::sun::star
26 {
27 namespace beans
28 {
29 class XMultiPropertySet;
30 }
31 namespace beans
32 {
33 class XPropertySet;
34 }
35 namespace beans
36 {
37 class XPropertySetInfo;
38 }
39 }
40 
63 {
65  std::unique_ptr<OUString[]> pPropertyNames;
66 
68  sal_Int16 nLength;
69 
72  css::uno::Sequence<OUString> aPropertySequence;
73 
76  std::unique_ptr<sal_Int16[]> pSequenceIndex;
77 
79  css::uno::Sequence<css::uno::Any> aValues;
80 
82  const css::uno::Any* pValues;
83 
85  css::uno::Any aEmptyAny;
86 
87 public:
88  MultiPropertySetHelper(const char** pNames);
89 
91 
96  void hasProperties(const css::uno::Reference<css::beans::XPropertySetInfo>&);
97 
102  bool checkedProperties();
103 
110  void getValues(const css::uno::Reference<css::beans::XMultiPropertySet>&);
111 
120  void getValues(const css::uno::Reference<css::beans::XPropertySet>&);
121 
127  inline const css::uno::Any& getValue(sal_Int16 nIndex);
128 
134  inline bool hasProperty(sal_Int16 nIndex);
135 
146  const css::uno::Any& getValue(sal_Int16 nIndex,
147  const css::uno::Reference<css::beans::XPropertySet>&,
148  bool bTryMulti = false);
149 
160  const css::uno::Any& getValue(sal_Int16 nIndex,
161  const css::uno::Reference<css::beans::XMultiPropertySet>&);
162 
163  void resetValues() { pValues = nullptr; }
164 };
165 
166 // inline implementations of the often-called methods getValue and hasProperty:
167 
168 const css::uno::Any& MultiPropertySetHelper::getValue(sal_Int16 nValueNo)
169 {
170  assert(pValues && "called getValue() without calling getValues()");
171  assert(pSequenceIndex && "called getValue() without calling hasProperties()");
172  assert(nValueNo < nLength);
173 
174  sal_Int16 nIndex = pSequenceIndex[nValueNo];
175  return (nIndex != -1) ? pValues[nIndex] : aEmptyAny;
176 }
177 
178 bool MultiPropertySetHelper::hasProperty(sal_Int16 nValueNo)
179 {
180  assert(pSequenceIndex && "called hasProperty() without calling hasProperties()");
181  assert(nValueNo < nLength);
182 
183  return pSequenceIndex[nValueNo] != -1;
184 }
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int16 nLength
length of pPropertyNames array
sal_Int32 nIndex
bool checkedProperties()
Return whether hasProperties was called (i.e.
void getValues(const css::uno::Reference< css::beans::XMultiPropertySet > &)
Get values from the XMultiPropertySet.
const css::uno::Any & getValue(sal_Int16 nIndex)
Get a value from the values array.
css::uno::Any aEmptyAny
an empty Any
const css::uno::Any * pValues
result of aValues.getConstArray()
bool hasProperty(sal_Int16 nIndex)
Find out if this property is supported.
The MultiPropertySetHelper performs the following functions:
class SAL_NO_VTABLE XPropertySet
void hasProperties(const css::uno::Reference< css::beans::XPropertySetInfo > &)
Call hasPropertiesByName for the provided XPropertySetInfo and build list of allowed properties...
MultiPropertySetHelper(const char **pNames)
exports com.sun.star. beans
std::unique_ptr< OUString[]> pPropertyNames
names of all properties
std::unique_ptr< sal_Int16[]> pSequenceIndex
an array of indices that maps from pPropertyNames indices to aPropertySequence indices ...
css::uno::Sequence< OUString > aPropertySequence
the sequence of property names that the current (multi) property set implementation supports ...
css::uno::Sequence< css::uno::Any > aValues
the last set of values retrieved by getValues