LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - propertystorage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 31 6.5 %
Date: 2014-11-03 Functions: 1 8 12.5 %
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             : #include "propertystorage.hxx"
      21             : 
      22             : #include <svl/itemset.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include <svl/eitem.hxx>
      25             : 
      26             : #include <cassert>
      27             : #include <boost/scoped_ptr.hpp>
      28             : 
      29             : namespace dbaui
      30             : {
      31             : 
      32             :     using ::com::sun::star::uno::Reference;
      33             :     using ::com::sun::star::uno::XInterface;
      34             :     using ::com::sun::star::uno::UNO_QUERY;
      35             :     using ::com::sun::star::uno::Exception;
      36             :     using ::com::sun::star::uno::RuntimeException;
      37             :     using ::com::sun::star::uno::Any;
      38             :     using ::com::sun::star::uno::makeAny;
      39             : 
      40             :     // PropertyStorage
      41          12 :     PropertyStorage::~PropertyStorage()
      42             :     {
      43          12 :     }
      44             : 
      45             :     // helper
      46             :     namespace
      47             :     {
      48             :         #undef UNOTYPE
      49             :         template < class ITEMTYPE, class UNOTYPE >
      50             :         class ItemAdapter
      51             :         {
      52             :         public:
      53           0 :             static bool trySet( SfxItemSet& _rSet, ItemId _nItemId, const Any& _rValue )
      54             :             {
      55           0 :                 const SfxPoolItem& rItem( _rSet.Get( _nItemId ) );
      56           0 :                 const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &rItem );
      57           0 :                 if ( !pTypedItem )
      58           0 :                     return false;
      59             : 
      60           0 :                 UNOTYPE aValue( pTypedItem->GetValue() );
      61           0 :                 OSL_VERIFY( _rValue >>= aValue );
      62             :                 // TODO: one could throw an IllegalArgumentException here - finally, this method
      63             :                 // is (to be) used from within an XPropertySet::setPropertyValue implementation,
      64             :                 // where this would be the appropriate reaction on wrong value types
      65           0 :                 ITEMTYPE* pCloneItem = dynamic_cast< ITEMTYPE* >( pTypedItem->Clone() );
      66           0 :                 if(!pCloneItem)
      67             :                 {
      68           0 :                     return false;
      69             :                 }
      70           0 :                 boost::scoped_ptr< ITEMTYPE > pClone( pCloneItem);
      71             :                 assert(pClone.get());
      72           0 :                 pClone->SetValue( aValue );
      73           0 :                 _rSet.Put( *pClone );
      74           0 :                 return true;
      75             :             }
      76             : 
      77           0 :             static bool tryGet( const SfxPoolItem& _rItem, Any& _out_rValue )
      78             :             {
      79           0 :                 const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &_rItem );
      80           0 :                 if ( !pTypedItem )
      81           0 :                     return false;
      82             : 
      83           0 :                 _out_rValue <<= UNOTYPE( pTypedItem->GetValue() );
      84           0 :                 return true;
      85             :             }
      86             :         };
      87             :     }
      88             : 
      89             :     // SetItemPropertyStorage
      90           0 :     void SetItemPropertyStorage::getPropertyValue( Any& _out_rValue ) const
      91             :     {
      92           0 :         const SfxPoolItem& rItem( m_rItemSet.Get( m_nItemID ) );
      93             : 
      94             :         // try some known item types
      95           0 :         if  (   ItemAdapter< SfxBoolItem, sal_Bool >::tryGet( rItem, _out_rValue )
      96           0 :             ||  ItemAdapter< SfxStringItem, OUString >::tryGet( rItem, _out_rValue )
      97             :             )
      98           0 :             return;
      99             : 
     100             :         OSL_FAIL( "SetItemPropertyStorage::getPropertyValue: unsupported item type!" );
     101             :     }
     102             : 
     103           0 :     void SetItemPropertyStorage::setPropertyValue( const Any& _rValue )
     104             :     {
     105             :         // try some known item types
     106           0 :         if  (   ItemAdapter< SfxBoolItem, sal_Bool >::trySet( m_rItemSet, m_nItemID, _rValue )
     107           0 :             ||  ItemAdapter< SfxStringItem, OUString >::trySet( m_rItemSet, m_nItemID, _rValue )
     108             :             )
     109           0 :             return;
     110             : 
     111             :         OSL_FAIL( "SetItemPropertyStorage::setPropertyValue: unsupported item type!" );
     112             :     }
     113             : 
     114             : } // namespace dbaui
     115             : 
     116             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10