Fix GNU C++ version check
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blobdfb5c2b3f80d7e56986c901bcc56e6d707e23966
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(u"lengths do not match"_ustr, static_cast<cppu::OWeakObject*>(this), -1);
122 if( !nCount )
123 return;
125 _preSetValues();
127 for (sal_Int32 i = 0; i < nCount; ++i)
129 auto aIter = mxInfo->maMap.find(rPropertyNames[i]);
130 if (aIter == mxInfo->maMap.end())
131 throw RuntimeException(rPropertyNames[i], static_cast<XPropertySet*>(this));
133 _setSingleValue(*((*aIter).second), rValues[i]);
136 _postSetValues();
139 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
141 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
142 std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
143 if (mpMutex)
144 xMutexGuard.emplace( mpMutex );
146 const sal_Int32 nCount = rPropertyNames.getLength();
148 Sequence < Any > aValues ( nCount );
150 if( nCount )
152 _preGetValues();
154 Any * pAny = aValues.getArray();
155 for (sal_Int32 i = 0; i < nCount; ++i)
157 auto aIter = mxInfo->maMap.find(rPropertyNames[i]);
158 if (aIter == mxInfo->maMap.end())
159 throw RuntimeException(rPropertyNames[i], static_cast<XPropertySet*>(this));
161 _getSingleValue(*((*aIter).second), pAny[i]);
164 _postGetValues();
166 return aValues;
169 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
171 // todo
174 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
176 // todo
179 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
181 // todo
184 // XPropertyState
185 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
187 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find( PropertyName );
188 if( aIter == mxInfo->maMap.end())
189 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
191 return PropertyState_AMBIGUOUS_VALUE;
194 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
196 const sal_Int32 nCount = rPropertyNames.getLength();
198 Sequence< PropertyState > aStates( nCount );
199 if( nCount )
201 PropertyState * pState = aStates.getArray();
202 PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
204 for (sal_Int32 i = 0; i < nCount; ++i)
206 aIter = mxInfo->maMap.find(rPropertyNames[i]);
207 if ( aIter == aEnd )
208 throw UnknownPropertyException(rPropertyNames[i], static_cast<XPropertySet*>(this));
210 pState[i] = PropertyState_AMBIGUOUS_VALUE;
213 return aStates;
216 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
218 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
220 if( aIter == mxInfo->maMap.end())
221 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
224 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
226 PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
228 if( aIter == mxInfo->maMap.end())
229 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
230 return Any();
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */