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 #ifndef INCLUDED_XMLOFF_INC_MULTIPROPERTYSETHELPER_HXX
20 #define INCLUDED_XMLOFF_INC_MULTIPROPERTYSETHELPER_HXX
21 
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <memory>
25 
26 namespace com::sun::star
27 {
28 namespace beans
29 {
30 class XMultiPropertySet;
31 }
32 namespace beans
33 {
34 class XPropertySet;
35 }
36 namespace beans
37 {
38 class XPropertySetInfo;
39 }
40 }
41 
64 {
66  std::unique_ptr<OUString[]> pPropertyNames;
67 
69  sal_Int16 nLength;
70 
73  css::uno::Sequence<OUString> aPropertySequence;
74 
77  std::unique_ptr<sal_Int16[]> pSequenceIndex;
78 
80  css::uno::Sequence<css::uno::Any> aValues;
81 
83  const css::uno::Any* pValues;
84 
86  css::uno::Any aEmptyAny;
87 
88 public:
89  MultiPropertySetHelper(const char** pNames);
90 
92 
97  void hasProperties(const css::uno::Reference<css::beans::XPropertySetInfo>&);
98 
103  bool checkedProperties();
104 
111  void getValues(const css::uno::Reference<css::beans::XMultiPropertySet>&);
112 
121  void getValues(const css::uno::Reference<css::beans::XPropertySet>&);
122 
128  inline const css::uno::Any& getValue(sal_Int16 nIndex);
129 
135  inline bool hasProperty(sal_Int16 nIndex);
136 
147  const css::uno::Any& getValue(sal_Int16 nIndex,
148  const css::uno::Reference<css::beans::XPropertySet>&,
149  bool bTryMulti = false);
150 
161  const css::uno::Any& getValue(sal_Int16 nIndex,
162  const css::uno::Reference<css::beans::XMultiPropertySet>&);
163 
164  void resetValues() { pValues = nullptr; }
165 };
166 
167 // inline implementations of the often-called methods getValue and hasProperty:
168 
169 const css::uno::Any& MultiPropertySetHelper::getValue(sal_Int16 nValueNo)
170 {
171  assert(pValues && "called getValue() without calling getValues()");
172  assert(pSequenceIndex && "called getValue() without calling hasProperties()");
173  assert(nValueNo < nLength);
174 
175  sal_Int16 nIndex = pSequenceIndex[nValueNo];
176  return (nIndex != -1) ? pValues[nIndex] : aEmptyAny;
177 }
178 
179 bool MultiPropertySetHelper::hasProperty(sal_Int16 nValueNo)
180 {
181  assert(pSequenceIndex && "called hasProperty() without calling hasProperties()");
182  assert(nValueNo < nLength);
183 
184  return pSequenceIndex[nValueNo] != -1;
185 }
186 
187 #endif
188 
189 /* 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 BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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