Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / canvas / source / tools / propertysethelper.cxx
blob24a07cb7dc25db437fe12ea775220cc2fa32ab72
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 <sal/config.h>
22 #include <string_view>
24 #include <propertysethelper.hxx>
25 #include <com/sun/star/beans/PropertyVetoException.hpp>
26 #include <com/sun/star/beans/UnknownPropertyException.hpp>
28 using namespace ::com::sun::star;
30 namespace canvas
32 namespace
34 void throwUnknown( std::u16string_view aPropertyName )
36 throw beans::UnknownPropertyException(
37 OUString::Concat("PropertySetHelper: property ") +
38 aPropertyName + " not found."
42 void throwVeto( std::u16string_view aPropertyName )
44 throw beans::PropertyVetoException(
45 OUString::Concat("PropertySetHelper: property ") +
46 aPropertyName + " access was vetoed." );
49 struct EntryComparator
51 bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
52 const PropertySetHelper::MapType::MapEntry& rRHS )
54 return strcmp( rLHS.maKey,
55 rRHS.maKey ) < 0;
60 PropertySetHelper::PropertySetHelper()
64 void PropertySetHelper::initProperties( InputMap&& rMap )
66 mpMap.reset();
67 maMapEntries = std::move(rMap);
69 std::sort( maMapEntries.begin(),
70 maMapEntries.end(),
71 EntryComparator() );
73 if( !maMapEntries.empty() )
74 mpMap.reset( new MapType(maMapEntries.data(),
75 maMapEntries.size(),
76 true) );
79 void PropertySetHelper::addProperties( const InputMap& rMap )
81 InputMap aMerged( maMapEntries );
82 aMerged.insert( aMerged.end(),
83 rMap.begin(),
84 rMap.end() );
86 initProperties( std::move(aMerged) );
89 bool PropertySetHelper::isPropertyName( const OUString& aPropertyName ) const
91 if (!mpMap)
92 return false;
94 Callbacks aDummy;
95 return mpMap->lookup( aPropertyName,
96 aDummy );
99 uno::Reference< beans::XPropertySetInfo > PropertySetHelper::getPropertySetInfo() const
101 // we're a stealth property set
102 return uno::Reference< beans::XPropertySetInfo >();
105 void PropertySetHelper::setPropertyValue( const OUString& aPropertyName,
106 const uno::Any& aValue )
108 Callbacks aCallbacks;
109 if (!mpMap || !mpMap->lookup(aPropertyName, aCallbacks))
111 throwUnknown( aPropertyName );
114 if (!aCallbacks.setter)
115 throwVeto( aPropertyName );
117 aCallbacks.setter(aValue);
120 uno::Any PropertySetHelper::getPropertyValue( const OUString& aPropertyName ) const
122 Callbacks aCallbacks;
123 if (!mpMap || !mpMap->lookup(aPropertyName, aCallbacks))
125 throwUnknown( aPropertyName );
128 if (aCallbacks.getter)
129 return aCallbacks.getter();
131 // TODO(Q1): subtlety, empty getter method silently returns
132 // the empty any
133 return uno::Any();
136 void PropertySetHelper::addPropertyChangeListener( const OUString& aPropertyName,
137 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
139 // check validity of property, but otherwise ignore the
140 // request
141 if( !isPropertyName( aPropertyName ) )
142 throwUnknown( aPropertyName );
145 void PropertySetHelper::addVetoableChangeListener( const OUString& aPropertyName,
146 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
148 // check validity of property, but otherwise ignore the
149 // request
150 if( !isPropertyName( aPropertyName ) )
151 throwUnknown( aPropertyName );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */