bump product version to 6.3.0.0.beta1
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blob258b6dad0495900912986ad90595497b0e59da66
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>
27 using namespace ::comphelper;
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::beans;
33 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
34 throw()
35 : mpMutex ( pMutex )
36 , mxInfo ( pInfo )
40 ChainablePropertySet::~ChainablePropertySet()
41 throw()
45 // XPropertySet
46 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
48 return mxInfo.get();
51 void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
53 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
54 std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
55 if (mpMutex)
56 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
58 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
60 if( aIter == mxInfo->maMap.end())
61 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
63 _preSetValues();
64 _setSingleValue( *((*aIter).second), rValue );
65 _postSetValues();
68 Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
70 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
71 std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
72 if (mpMutex)
73 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
75 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
77 if( aIter == mxInfo->maMap.end())
78 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
80 Any aAny;
81 _preGetValues ();
82 _getSingleValue( *((*aIter).second), aAny );
83 _postGetValues ();
85 return aAny;
88 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
90 // todo
93 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
95 // todo
98 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
100 // todo
103 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
105 // todo
108 // XMultiPropertySet
109 void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
111 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
112 std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
113 if (mpMutex)
114 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
116 const sal_Int32 nCount = rPropertyNames.getLength();
118 if( nCount != rValues.getLength() )
119 throw IllegalArgumentException();
121 if( nCount )
123 _preSetValues();
125 const Any * pAny = rValues.getConstArray();
126 const OUString * pString = rPropertyNames.getConstArray();
127 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
129 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
131 aIter = mxInfo->maMap.find ( *pString );
132 if ( aIter == aEnd )
133 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
135 _setSingleValue ( *((*aIter).second), *pAny );
138 _postSetValues();
142 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
144 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
145 std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
146 if (mpMutex)
147 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
149 const sal_Int32 nCount = rPropertyNames.getLength();
151 Sequence < Any > aValues ( nCount );
153 if( nCount )
155 _preGetValues();
157 Any * pAny = aValues.getArray();
158 const OUString * pString = rPropertyNames.getConstArray();
159 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
161 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
163 aIter = mxInfo->maMap.find ( *pString );
164 if ( aIter == aEnd )
165 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
167 _getSingleValue ( *((*aIter).second), *pAny );
170 _postGetValues();
172 return aValues;
175 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
177 // todo
180 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
182 // todo
185 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
187 // todo
190 // XPropertyState
191 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
193 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find( PropertyName );
194 if( aIter == mxInfo->maMap.end())
195 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
197 return PropertyState_AMBIGUOUS_VALUE;
200 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
202 const sal_Int32 nCount = rPropertyNames.getLength();
204 Sequence< PropertyState > aStates( nCount );
205 if( nCount )
207 PropertyState * pState = aStates.getArray();
208 const OUString * pString = rPropertyNames.getConstArray();
209 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
211 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
213 aIter = mxInfo->maMap.find ( *pString );
214 if ( aIter == aEnd )
215 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
218 return aStates;
221 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
223 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
225 if( aIter == mxInfo->maMap.end())
226 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
229 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
231 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
233 if( aIter == mxInfo->maMap.end())
234 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
235 return Any();
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */