Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blob0805afe72bcf21c60e12797b1562bf57094277d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <comphelper/ChainablePropertySet.hxx>
21 #include <comphelper/ChainablePropertySetInfo.hxx>
22 #include <comphelper/solarmutex.hxx>
25 #include <memory>
26 #include <optional>
28 using namespace ::comphelper;
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::beans;
34 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
35 noexcept
36 : mpMutex ( pMutex )
37 , mxInfo ( pInfo )
41 ChainablePropertySet::~ChainablePropertySet()
42 noexcept
46 // XPropertySet
47 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
49 return mxInfo;
52 void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
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 );
59 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
61 if( aIter == mxInfo->maMap.end())
62 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
64 _preSetValues();
65 _setSingleValue( *((*aIter).second), rValue );
66 _postSetValues();
69 Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
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 );
76 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
78 if( aIter == mxInfo->maMap.end())
79 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
81 Any aAny;
82 _preGetValues ();
83 _getSingleValue( *((*aIter).second), aAny );
84 _postGetValues ();
86 return aAny;
89 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
91 // todo
94 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
96 // todo
99 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
101 // todo
104 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
106 // todo
109 // XMultiPropertySet
110 void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
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 );
117 const sal_Int32 nCount = rPropertyNames.getLength();
119 if( nCount != rValues.getLength() )
120 throw IllegalArgumentException("lengths do not match", static_cast<cppu::OWeakObject*>(this), -1);
122 if( !nCount )
123 return;
125 _preSetValues();
127 const Any * pAny = rValues.getConstArray();
128 const OUString * pString = rPropertyNames.getConstArray();
129 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
131 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
133 aIter = mxInfo->maMap.find ( *pString );
134 if ( aIter == aEnd )
135 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
137 _setSingleValue ( *((*aIter).second), *pAny );
140 _postSetValues();
143 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
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 );
150 const sal_Int32 nCount = rPropertyNames.getLength();
152 Sequence < Any > aValues ( nCount );
154 if( nCount )
156 _preGetValues();
158 Any * pAny = aValues.getArray();
159 const OUString * pString = rPropertyNames.getConstArray();
160 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
162 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
164 aIter = mxInfo->maMap.find ( *pString );
165 if ( aIter == aEnd )
166 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
168 _getSingleValue ( *((*aIter).second), *pAny );
171 _postGetValues();
173 return aValues;
176 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
178 // todo
181 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
183 // todo
186 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
188 // todo
191 // XPropertyState
192 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
194 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find( PropertyName );
195 if( aIter == mxInfo->maMap.end())
196 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
198 return PropertyState_AMBIGUOUS_VALUE;
201 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
203 const sal_Int32 nCount = rPropertyNames.getLength();
205 Sequence< PropertyState > aStates( nCount );
206 if( nCount )
208 PropertyState * pState = aStates.getArray();
209 const OUString * pString = rPropertyNames.getConstArray();
210 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
212 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
214 aIter = mxInfo->maMap.find ( *pString );
215 if ( aIter == aEnd )
216 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
219 return aStates;
222 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
224 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
226 if( aIter == mxInfo->maMap.end())
227 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
230 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
232 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
234 if( aIter == mxInfo->maMap.end())
235 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
236 return Any();
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */