LCOV - code coverage report
Current view: top level - canvas/source/tools - propertysethelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 58 24.1 %
Date: 2015-06-13 12:38:46 Functions: 3 12 25.0 %
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          21 :             bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
      47             :                              const PropertySetHelper::MapType::MapEntry& rRHS )
      48             :             {
      49             :                 return strcmp( rLHS.maKey,
      50          21 :                                rRHS.maKey ) < 0;
      51             :             }
      52             :         };
      53             :     }
      54             : 
      55           3 :     PropertySetHelper::PropertySetHelper() :
      56             :         mpMap(),
      57           3 :         maMapEntries()
      58             :     {
      59           3 :     }
      60             : 
      61           3 :     void PropertySetHelper::initProperties( const InputMap& rMap )
      62             :     {
      63           3 :         mpMap.reset();
      64           3 :         maMapEntries = rMap;
      65             : 
      66             :         std::sort( maMapEntries.begin(),
      67             :                    maMapEntries.end(),
      68           3 :                    EntryComparator() );
      69             : 
      70           3 :         if( !maMapEntries.empty() )
      71           3 :             mpMap.reset( new MapType(&maMapEntries[0],
      72           3 :                                      maMapEntries.size(),
      73           6 :                                      true) );
      74           3 :     }
      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::addVetoableChangeListener( const OUString&                                  aPropertyName,
     147             :                                                        const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
     148             :     {
     149             :         // check validity of property, but otherwise ignore the
     150             :         // request
     151           0 :         if( !isPropertyName( aPropertyName ) )
     152           0 :             throwUnknown( aPropertyName );
     153           0 :     }
     154             : 
     155             : }
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11