LibreOffice Module comphelper (master) 1
ChainablePropertySet.cxx
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
23
24
25#include <memory>
26#include <optional>
27
28using namespace ::comphelper;
29using namespace ::com::sun::star;
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::beans;
33
34ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
35 noexcept
36: mpMutex ( pMutex )
37, mxInfo ( pInfo )
38{
39}
40
41ChainablePropertySet::~ChainablePropertySet()
42 noexcept
43{
44}
45
46// XPropertySet
47Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
48{
49 return mxInfo;
50}
51
52void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
53{
54 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
55 std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
56 if (mpMutex)
57 xMutexGuard.emplace( mpMutex );
58
59 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
60
61 if( aIter == mxInfo->maMap.end())
62 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
63
64 _preSetValues();
65 _setSingleValue( *((*aIter).second), rValue );
66 _postSetValues();
67}
68
69Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
70{
71 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
72 std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
73 if (mpMutex)
74 xMutexGuard.emplace( mpMutex );
75
76 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
77
78 if( aIter == mxInfo->maMap.end())
79 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
80
81 Any aAny;
82 _preGetValues ();
83 _getSingleValue( *((*aIter).second), aAny );
84 _postGetValues ();
85
86 return aAny;
87}
88
89void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
90{
91 // todo
92}
93
94void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
95{
96 // todo
97}
98
99void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
100{
101 // todo
102}
103
104void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
105{
106 // todo
107}
108
109// XMultiPropertySet
110void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
111{
112 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
113 std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
114 if (mpMutex)
115 xMutexGuard.emplace( mpMutex );
116
117 const sal_Int32 nCount = rPropertyNames.getLength();
118
119 if( nCount != rValues.getLength() )
120 throw IllegalArgumentException("lengths do not match", static_cast<cppu::OWeakObject*>(this), -1);
121
122 if( !nCount )
123 return;
124
125 _preSetValues();
126
127 const Any * pAny = rValues.getConstArray();
128 const OUString * pString = rPropertyNames.getConstArray();
129 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
130
131 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
132 {
133 aIter = mxInfo->maMap.find ( *pString );
134 if ( aIter == aEnd )
135 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
136
137 _setSingleValue ( *((*aIter).second), *pAny );
138 }
139
140 _postSetValues();
141}
142
143Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
144{
145 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
146 std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
147 if (mpMutex)
148 xMutexGuard.emplace( mpMutex );
149
150 const sal_Int32 nCount = rPropertyNames.getLength();
151
152 Sequence < Any > aValues ( nCount );
153
154 if( nCount )
155 {
156 _preGetValues();
157
158 Any * pAny = aValues.getArray();
159 const OUString * pString = rPropertyNames.getConstArray();
160 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
161
162 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
163 {
164 aIter = mxInfo->maMap.find ( *pString );
165 if ( aIter == aEnd )
166 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
167
168 _getSingleValue ( *((*aIter).second), *pAny );
169 }
170
171 _postGetValues();
172 }
173 return aValues;
174}
175
176void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
177{
178 // todo
179}
180
181void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
182{
183 // todo
184}
185
186void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
187{
188 // todo
189}
190
191// XPropertyState
192PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
193{
194 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find( PropertyName );
195 if( aIter == mxInfo->maMap.end())
196 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
197
198 return PropertyState_AMBIGUOUS_VALUE;
199}
200
201Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
202{
203 const sal_Int32 nCount = rPropertyNames.getLength();
204
205 Sequence< PropertyState > aStates( nCount );
206 if( nCount )
207 {
208 PropertyState * pState = aStates.getArray();
209 const OUString * pString = rPropertyNames.getConstArray();
210 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
211
212 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
213 {
214 aIter = mxInfo->maMap.find ( *pString );
215 if ( aIter == aEnd )
216 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
217 }
218 }
219 return aStates;
220}
221
222void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
223{
224 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
225
226 if( aIter == mxInfo->maMap.end())
227 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
228}
229
230Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
231{
232 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
233
234 if( aIter == mxInfo->maMap.end())
235 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
236 return Any();
237}
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SolarMutex, needed for VCL's Application::GetSolarMutex().
Definition: solarmutex.hxx:46
int nCount
class SAL_NO_VTABLE XPropertySet
int i