LCOV - code coverage report
Current view: top level - include/sfx2 - itemwrapper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 21 0.0 %
Date: 2014-11-03 Functions: 0 105 0.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             : #ifndef INCLUDED_SFX2_ITEMWRAPPER_HXX
      21             : #define INCLUDED_SFX2_ITEMWRAPPER_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : #include <sfx2/dllapi.h>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include <svl/intitem.hxx>
      28             : #include <svl/itemset.hxx>
      29             : 
      30             : 
      31             : 
      32             : namespace sfx {
      33             : 
      34             : 
      35             : // Helpers
      36             : 
      37             : 
      38             : class SFX2_DLLPUBLIC ItemWrapperHelper
      39             : {
      40             : public:
      41             :     /** Returns the WID of the passed SID in the item set. */
      42             :     static sal_uInt16       GetWhichId( const SfxItemSet& rItemSet, sal_uInt16 nSlot );
      43             : 
      44             :     /** Returns true, if the passed item set supports the SID. */
      45             :     static bool         IsKnownItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot );
      46             : 
      47             :     /** Returns an item from an item set, if it is not in "don't know" state.
      48             :         @return  Pointer to item, or 0 if it has "don't know" state. */
      49             :     static const SfxPoolItem* GetUniqueItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot );
      50             : 
      51             :     /** Returns the default item from the pool of the passed item set. */
      52             :     static const SfxPoolItem& GetDefaultItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot );
      53             : 
      54             :     /** Removes an item from rDestSet, if it is default in rOldSet. */
      55             :     static void         RemoveDefaultItem( SfxItemSet& rDestSet, const SfxItemSet& rOldSet, sal_uInt16 nSlot );
      56             : };
      57             : 
      58             : 
      59             : // Item wrappers
      60             : 
      61             : 
      62             : /** Base class wrapping a single item.
      63             : 
      64             :     Objects of this class store the SID of an item. Exchanging data with the
      65             :     item is done with the virtual functions GetItemValue() and SetItemValue().
      66             :     Derived classes implement these functions according to the item type they
      67             :     work on.
      68             : 
      69             :     The current tree of base classes/templates and standard item wrappers:
      70             : 
      71             :     SingleItemWrapper< ItemT, ValueT >
      72             :      |
      73             :      +- ValueItemWrapper< ItemT, ValueT >   [1]
      74             :      |   |
      75             :      |   +- BoolItemWrapper   [1]
      76             :      |   +- Int16ItemWrapper   [1]
      77             :      |   +- UInt16ItemWrapper   [1]
      78             :      |   +- Int32ItemWrapper   [1]
      79             :      |   +- UInt32ItemWrapper   [1]
      80             :      |   +- StringItemWrapper   [1]
      81             :      |
      82             :      +- IdentItemWrapper< ItemT >   [1]
      83             : 
      84             :     Notes:
      85             :     [1] Standard wrappers ready to use.
      86             : 
      87             :     See documentation of class ItemConnectionBase for more details.
      88             :  */
      89             : template< typename ItemT, typename ValueT >
      90             : class SingleItemWrapper
      91             : {
      92             : public:
      93             :     typedef ItemT                               ItemType;
      94             :     typedef ValueT                              ItemValueType;
      95             :     typedef SingleItemWrapper< ItemT, ValueT >  SingleItemWrapperType;
      96             : 
      97           0 :     inline explicit     SingleItemWrapper( sal_uInt16 nSlot ) : mnSlot( nSlot ) {}
      98             : 
      99           0 :     virtual             ~SingleItemWrapper() {}
     100             : 
     101             :     /** Returns the SID this wrapper works on. */
     102           0 :     inline sal_uInt16       GetSlotId() const { return mnSlot; }
     103             : 
     104             :     /** Returns the item from an item set, if it is not in "don't know" state.
     105             :         @descr  Similar to ItemWrapperHelper::GetUniqueItem(), but works always
     106             :         with the own SID and returns the correct item type.
     107             :         @return Pointer to item, or 0 if it has "don't know" state. */
     108             :     const ItemT*        GetUniqueItem( const SfxItemSet& rItemSet ) const;
     109             :     /** Returns the default item from the pool of the passed item set.
     110             :         @descr  Similar to ItemWrapperHelper::GetDefaultItem(), but works
     111             :         always with the own SID and returns the correct item type. */
     112             :     const ItemT&        GetDefaultItem( const SfxItemSet& rItemSet ) const;
     113             : 
     114             :     /** Derived classes return the value of the passed item. */
     115             :     virtual ValueT      GetItemValue( const ItemT& rItem ) const = 0;
     116             :     /** Derived classes set the value at the passed item. */
     117             :     virtual void        SetItemValue( ItemT& rItem, ValueT aValue ) const = 0;
     118             : 
     119             : private:
     120             :     sal_uInt16              mnSlot;     /// The SID of this item wrapper.
     121             : };
     122             : 
     123             : 
     124             : 
     125             : /** An item wrapper usable for most types of items.
     126             : 
     127             :     The item type must support the following functions:
     128             :     - ValueT ItemT::GetValue() const
     129             :     - void ItemT::SetValue( ValueT )
     130             : 
     131             :     The template parameter InternalValueT can be used to specify the internal
     132             :     value type of the item, if it differs from ValueT. This parameter has to be
     133             :     used to prevent compiler warnings.
     134             :  */
     135             : template< typename ItemT, typename ValueT, typename InternalValueT = ValueT >
     136             : class ValueItemWrapper : public SingleItemWrapper< ItemT, ValueT >
     137             : {
     138             : public:
     139           0 :     inline explicit     ValueItemWrapper( sal_uInt16 nSlot ) :
     140           0 :                             SingleItemWrapper< ItemT, ValueT >( nSlot ) {}
     141             : 
     142           0 :     virtual             ~ValueItemWrapper() {}
     143             : 
     144           0 :     virtual ValueT      GetItemValue( const ItemT& rItem ) const
     145           0 :                             { return static_cast< ValueT >( rItem.GetValue() ); }
     146           0 :     virtual void        SetItemValue( ItemT& rItem, ValueT aValue ) const
     147           0 :                             { rItem.SetValue( static_cast< InternalValueT >( aValue ) ); }
     148             : };
     149             : 
     150             : 
     151             : 
     152             : typedef ValueItemWrapper< SfxBoolItem,   sal_Bool >          BoolItemWrapper;
     153             : typedef ValueItemWrapper< SfxInt16Item,  sal_Int16 >         Int16ItemWrapper;
     154             : typedef ValueItemWrapper< SfxUInt16Item, sal_uInt16 >        UInt16ItemWrapper;
     155             : typedef ValueItemWrapper< SfxInt32Item,  sal_Int32 >         Int32ItemWrapper;
     156             : typedef ValueItemWrapper< SfxUInt32Item, sal_uInt32 >        UInt32ItemWrapper;
     157             : typedef ValueItemWrapper< SfxStringItem, const OUString& >   StringItemWrapper;
     158             : 
     159             : 
     160             : 
     161             : /** An item wrapper that uses the item itself as value. */
     162             : template< typename ItemT >
     163             : class IdentItemWrapper : public SingleItemWrapper< ItemT, const ItemT& >
     164             : {
     165             : public:
     166           0 :     inline explicit     IdentItemWrapper( sal_uInt16 nSlot ) :
     167           0 :                             SingleItemWrapper< ItemT, const ItemT& >( nSlot ) {}
     168             : 
     169           0 :     virtual             ~IdentItemWrapper() {}
     170             : 
     171           0 :     virtual const ItemT& GetItemValue( const ItemT& rItem ) const
     172           0 :                             { return rItem; }
     173           0 :     virtual void        SetItemValue( ItemT& rItem, const ItemT& rValue ) const
     174           0 :                             { rItem = rValue; }
     175             : };
     176             : 
     177             : 
     178             : 
     179             : 
     180             : 
     181             : //               ***  Implementation of template functions  ***
     182             : 
     183             : 
     184             : 
     185             : // Item wrappers
     186             : 
     187             : 
     188             : template< typename ItemT, typename ValueT >
     189           0 : const ItemT* SingleItemWrapper< ItemT, ValueT >::GetUniqueItem( const SfxItemSet& rItemSet ) const
     190             : {
     191           0 :     return static_cast< const ItemT* >( ItemWrapperHelper::GetUniqueItem( rItemSet, mnSlot ) );
     192             : }
     193             : 
     194             : template< typename ItemT, typename ValueT >
     195           0 : const ItemT& SingleItemWrapper< ItemT, ValueT >::GetDefaultItem( const SfxItemSet& rItemSet ) const
     196             : {
     197           0 :     return static_cast< const ItemT& >( ItemWrapperHelper::GetDefaultItem( rItemSet, mnSlot ) );
     198             : }
     199             : 
     200             : 
     201             : 
     202             : } // namespace sfx
     203             : 
     204             : #endif
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10