LCOV - code coverage report
Current view: top level - canvas/source/tools - propertysethelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 14 62 22.6 %
Date: 2014-11-03 Functions: 3 14 21.4 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : 
      21             : #include <canvas/propertysethelper.hxx>
      22             : 
      23             : using namespace ::com::sun::star;
      24             : 
      25             : namespace canvas
      26             : {
      27             :     namespace
      28             :     {
      29           0 :         void throwUnknown( const OUString& aPropertyName )
      30             :         {
      31             :             throw beans::UnknownPropertyException(
      32           0 :                 "PropertySetHelper: property " +
      33           0 :                 aPropertyName + " not found."
      34           0 :                 );
      35             :         }
      36             : 
      37           0 :         void throwVeto( const OUString& aPropertyName )
      38             :         {
      39             :             throw beans::PropertyVetoException(
      40           0 :                 "PropertySetHelper: property " +
      41           0 :                 aPropertyName + " access was vetoed." );
      42             :         }
      43             : 
      44             :         struct EntryComparator
      45             :         {
      46          14 :             bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
      47             :                              const PropertySetHelper::MapType::MapEntry& rRHS )
      48             :             {
      49             :                 return strcmp( rLHS.maKey,
      50          14 :                                rRHS.maKey ) < 0;
      51             :             }
      52             :         };
      53             :     }
      54             : 
      55           2 :     PropertySetHelper::PropertySetHelper() :
      56             :         mpMap(),
      57           2 :         maMapEntries()
      58             :     {
      59           2 :     }
      60             : 
      61           2 :     void PropertySetHelper::initProperties( const InputMap& rMap )
      62             :     {
      63           2 :         mpMap.reset();
      64           2 :         maMapEntries = rMap;
      65             : 
      66             :         std::sort( maMapEntries.begin(),
      67             :                    maMapEntries.end(),
      68           2 :                    EntryComparator() );
      69             : 
      70           2 :         if( !maMapEntries.empty() )
      71           2 :             mpMap.reset( new MapType(&maMapEntries[0],
      72           2 :                                      maMapEntries.size(),
      73           4 :                                      true) );
      74           2 :     }
      75             : 
      76           0 :     void PropertySetHelper::addProperties( const InputMap& rMap )
      77             :     {
      78           0 :         InputMap aMerged( getPropertyMap() );
      79             :         aMerged.insert( aMerged.end(),
      80             :                         rMap.begin(),
      81           0 :                         rMap.end() );
      82             : 
      83           0 :         initProperties( aMerged );
      84           0 :     }
      85             : 
      86           0 :     bool PropertySetHelper::isPropertyName( const OUString& aPropertyName ) const
      87             :     {
      88           0 :         if( !mpMap.get() )
      89           0 :             return false;
      90             : 
      91           0 :         Callbacks aDummy;
      92             :         return mpMap->lookup( aPropertyName,
      93           0 :                               aDummy );
      94             :     }
      95             : 
      96           0 :     uno::Reference< beans::XPropertySetInfo > PropertySetHelper::getPropertySetInfo() const
      97             :     {
      98             :         // we're a stealth property set
      99           0 :         return uno::Reference< beans::XPropertySetInfo >();
     100             :     }
     101             : 
     102           0 :     void PropertySetHelper::setPropertyValue( const OUString& aPropertyName,
     103             :                                               const uno::Any&        aValue )
     104             :     {
     105           0 :         Callbacks aCallbacks;
     106           0 :         if( !mpMap.get() ||
     107             :             !mpMap->lookup( aPropertyName,
     108           0 :                             aCallbacks ) )
     109             :         {
     110           0 :             throwUnknown( aPropertyName );
     111             :         }
     112             : 
     113           0 :         if( aCallbacks.setter.empty() )
     114           0 :             throwVeto( aPropertyName );
     115             : 
     116           0 :         aCallbacks.setter(aValue);
     117           0 :     }
     118             : 
     119           0 :     uno::Any PropertySetHelper::getPropertyValue( const OUString& aPropertyName ) const
     120             :     {
     121           0 :         Callbacks aCallbacks;
     122           0 :         if( !mpMap.get() ||
     123             :             !mpMap->lookup( aPropertyName,
     124           0 :                             aCallbacks ) )
     125             :         {
     126           0 :             throwUnknown( aPropertyName );
     127             :         }
     128             : 
     129           0 :         if( !aCallbacks.getter.empty() )
     130           0 :             return aCallbacks.getter();
     131             : 
     132             :         // TODO(Q1): subtlety, empty getter method silently returns
     133             :         // the empty any
     134           0 :         return uno::Any();
     135             :     }
     136             : 
     137           0 :     void PropertySetHelper::addPropertyChangeListener( const OUString&                                  aPropertyName,
     138             :                                                        const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
     139             :     {
     140             :         // check validity of property, but otherwise ignore the
     141             :         // request
     142           0 :         if( !isPropertyName( aPropertyName ) )
     143           0 :             throwUnknown( aPropertyName );
     144           0 :     }
     145             : 
     146           0 :     void PropertySetHelper::removePropertyChangeListener( const OUString&                                  /*aPropertyName*/,
     147             :                                                           const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
     148             :     {
     149             :         // ignore request, no listener added in the first place
     150           0 :     }
     151             : 
     152           0 :     void PropertySetHelper::addVetoableChangeListener( const OUString&                                  aPropertyName,
     153             :                                                        const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
     154             :     {
     155             :         // check validity of property, but otherwise ignore the
     156             :         // request
     157           0 :         if( !isPropertyName( aPropertyName ) )
     158           0 :             throwUnknown( aPropertyName );
     159           0 :     }
     160             : 
     161           0 :     void PropertySetHelper::removeVetoableChangeListener( const OUString&                                  /*aPropertyName*/,
     162             :                                                           const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
     163             :     {
     164             :         // ignore request, no listener added in the first place
     165           0 :     }
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10