1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <MultiPropertySetHelper.hxx>
22 #include <com/sun/star/beans/XPropertySetInfo.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/XMultiPropertySet.hpp>
26 #include <sal/log.hxx>
28 using ::com::sun::star::beans::XMultiPropertySet
;
29 using ::com::sun::star::beans::XPropertySet
;
30 using ::com::sun::star::beans::XPropertySetInfo
;
31 using ::com::sun::star::uno::Any
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::UNO_QUERY
;
36 MultiPropertySetHelper::MultiPropertySetHelper(
37 std::span
<const OUString
> pNames
) :
38 pPropertyNames( pNames
),
44 MultiPropertySetHelper::~MultiPropertySetHelper()
46 pValues
= nullptr; // memory 'owned' by aValues
50 void MultiPropertySetHelper::hasProperties(
51 const Reference
<XPropertySetInfo
> & rInfo
)
53 SAL_WARN_IF( !rInfo
.is(), "xmloff", "I'd really like an XPropertySetInfo here." );
55 // allocate sequence index
56 if ( !pSequenceIndex
)
57 pSequenceIndex
.reset( new sal_Int16
[pPropertyNames
.size()] );
59 // construct pSequenceIndex
60 sal_Int16 nNumberOfProperties
= 0;
62 for( size_t i
= 0; i
< pPropertyNames
.size(); i
++ )
66 rInfo
->hasPropertyByName( pPropertyNames
[i
] );
68 // set index and increment (if appropriate)
69 pSequenceIndex
[i
]= bHasProperty
? nNumberOfProperties
: -1;
71 nNumberOfProperties
++;
74 // construct property sequence from index array
75 if ( aPropertySequence
.getLength() != nNumberOfProperties
)
76 aPropertySequence
.realloc( nNumberOfProperties
);
77 OUString
* pPropertySequence
= aPropertySequence
.getArray();
78 for( size_t i
= 0; i
< pPropertyNames
.size(); i
++ )
80 sal_Int16 nIndex
= pSequenceIndex
[i
];
82 pPropertySequence
[nIndex
] = pPropertyNames
[i
];
86 bool MultiPropertySetHelper::checkedProperties()
88 return (nullptr != pSequenceIndex
);
92 void MultiPropertySetHelper::getValues(
93 const Reference
<XMultiPropertySet
> & rMultiPropertySet
)
95 SAL_WARN_IF( !rMultiPropertySet
.is(), "xmloff", "We need an XMultiPropertySet." );
97 aValues
= rMultiPropertySet
->getPropertyValues( aPropertySequence
);
98 pValues
= aValues
.getConstArray();
101 void MultiPropertySetHelper::getValues(
102 const Reference
<XPropertySet
> & rPropertySet
)
104 SAL_WARN_IF( !rPropertySet
.is(), "xmloff", "We need an XPropertySet." );
106 // re-alloc aValues (if necessary) and fill with values from XPropertySet
107 sal_Int16 nSupportedPropertiesCount
=
108 static_cast<sal_Int16
>(aPropertySequence
.getLength());
109 if ( aValues
.getLength() != nSupportedPropertiesCount
)
110 aValues
.realloc( nSupportedPropertiesCount
);
111 Any
* pMutableArray
= aValues
.getArray();
112 for( sal_Int16 i
= 0; i
< nSupportedPropertiesCount
; i
++ )
114 pMutableArray
[i
] = rPropertySet
->getPropertyValue(
115 pPropertyNames
[ pSequenceIndex
[ i
] ] );
118 // re-establish pValues pointer
119 pValues
= aValues
.getConstArray();
123 const Any
& MultiPropertySetHelper::getValue( sal_Int16 nIndex
,
124 const Reference
< XPropertySet
> & rPropSet
,
131 Reference
< XMultiPropertySet
> xMultiPropSet( rPropSet
,
133 if( xMultiPropSet
.is() )
134 getValues( xMultiPropSet
);
136 getValues( rPropSet
);
140 getValues( rPropSet
);
144 return getValue( nIndex
);
147 const Any
& MultiPropertySetHelper::getValue( sal_Int16 nIndex
,
148 const Reference
< XMultiPropertySet
> & rMultiPropSet
)
151 getValues( rMultiPropSet
);
153 return getValue( nIndex
);
156 // inline methods defined in header:
157 // inline Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex )
158 // inline sal_Bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo )
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */