LCOV - code coverage report
Current view: top level - include/comphelper - proparrhlp.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 26 100.0 %
Date: 2014-11-03 Functions: 264 764 34.6 %
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_COMPHELPER_PROPARRHLP_HXX
      21             : #define INCLUDED_COMPHELPER_PROPARRHLP_HXX
      22             : 
      23             : #include <comphelper/propagg.hxx>
      24             : #include <cppuhelper/propshlp.hxx>
      25             : #include <osl/mutex.hxx>
      26             : #include <osl/diagnose.h>
      27             : #include <rtl/instance.hxx>
      28             : 
      29             : namespace cppu {
      30             :     class IPropertyArrayHelper;
      31             : }
      32             : 
      33             : //... namespace comphelper ................................................
      34             : namespace comphelper
      35             : {
      36             : 
      37             : template <typename TYPE> struct OPropertyArrayUsageHelperMutex
      38             :     : public rtl::Static< ::osl::Mutex, OPropertyArrayUsageHelperMutex<TYPE> > {};
      39             : 
      40             : 
      41             : template <class TYPE>
      42             : class OPropertyArrayUsageHelper
      43             : {
      44             : protected:
      45             :     static sal_Int32                        s_nRefCount;
      46             :     static ::cppu::IPropertyArrayHelper*    s_pProps;
      47             : 
      48             : public:
      49             :     OPropertyArrayUsageHelper();
      50      180608 :     virtual ~OPropertyArrayUsageHelper()
      51             :     {   // ARGHHHHHHH ..... would like to implement this after the class
      52             :         // definition (as we do with all other methods) but SUNPRO 5 compiler
      53             :         // (linker) doesn't like this
      54      180608 :         ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
      55             :         OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
      56      180608 :         if (!--s_nRefCount)
      57             :         {
      58        7817 :             delete s_pProps;
      59        7817 :             s_pProps = NULL;
      60      180608 :         }
      61      361216 :     }
      62             : 
      63             :     /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
      64             :         class, which is created if necessary.
      65             :     */
      66             :     ::cppu::IPropertyArrayHelper*   getArrayHelper();
      67             : 
      68             : protected:
      69             :     /** used to implement the creation of the array helper which is shared amongst all instances of the class.
      70             :         This method needs to be implemented in derived classes.
      71             :         <BR>
      72             :         The method gets called with Mutex acquired.
      73             :         <BR>
      74             :         as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
      75             :         assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
      76             :         @return                         an pointer to the newly created array helper. Must not be NULL.
      77             :     */
      78             :     virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
      79             : };
      80             : 
      81             : 
      82             : /** a OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper
      83             : */
      84             : template <class TYPE>
      85         688 : class OAggregationArrayUsageHelper: public OPropertyArrayUsageHelper<TYPE>
      86             : {
      87             : protected:
      88             :     /** overwrite this in your derived class. initialize the two sequences with your and your aggregate's
      89             :         properties.
      90             :         <BR>
      91             :         The method gets called with Mutex acquired.
      92             :         @param      _rProps             out parameter to be filled with the property descriptions of your own class
      93             :         @param      _rAggregateProps    out parameter to be filled with the properties of your aggregate.
      94             :     */
      95             :     virtual void fillProperties(
      96             :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps,
      97             :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
      98             :         ) const = 0;
      99             : 
     100             :     /** creates an OPropertyArrayAggregationHelper filled with properties for which's initialization
     101             :         fillProperties is called. getInfoService and getFirstAggregateId may be overwritten to determine
     102             :         the additional parameters of the OPropertyArrayAggregationHelper.
     103             :     */
     104             :     virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
     105             : 
     106             :     /** the return value is used for the construction of the OPropertyArrayAggregationHelper.
     107             :         Beware of the lifetime of the returned object, as it has to exist 'til the last instance
     108             :         of this class dies.
     109             :     */
     110          36 :     virtual IPropertyInfoService* getInfoService() const { return NULL; }
     111             : 
     112             :     /** the return value is used for the construction of the OPropertyArrayAggregationHelper.
     113             :     */
     114          36 :     virtual sal_Int32 getFirstAggregateId() const { return DEFAULT_AGGREGATE_PROPERTY_ID; }
     115             : };
     116             : 
     117             : 
     118             : template<class TYPE>
     119             : sal_Int32                       OPropertyArrayUsageHelper< TYPE >::s_nRefCount  = 0;
     120             : 
     121             : template<class TYPE>
     122             : ::cppu::IPropertyArrayHelper*   OPropertyArrayUsageHelper< TYPE >::s_pProps = NULL;
     123             : 
     124             : 
     125             : template <class TYPE>
     126      180893 : OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
     127             : {
     128      180893 :     ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
     129      180893 :     ++s_nRefCount;
     130      180893 : }
     131             : 
     132             : 
     133             : template <class TYPE>
     134     1200538 : ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
     135             : {
     136             :     OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
     137     1200538 :     if (!s_pProps)
     138             :     {
     139        2370 :         ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
     140        2370 :         if (!s_pProps)
     141             :         {
     142        2370 :             s_pProps = createArrayHelper();
     143             :             OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
     144        2370 :         }
     145             :     }
     146     1200538 :     return s_pProps;
     147             : }
     148             : 
     149             : 
     150             : template <class TYPE> inline
     151          36 : ::cppu::IPropertyArrayHelper* OAggregationArrayUsageHelper<TYPE>::createArrayHelper() const
     152             : {
     153          36 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps;
     154          72 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aAggregateProps;
     155          36 :     fillProperties(aProps, aAggregateProps);
     156             :     OSL_ENSURE(aProps.getLength(), "OAggregationArrayUsageHelper::createArrayHelper : fillProperties returned nonsense !");
     157          72 :     return new OPropertyArrayAggregationHelper(aProps, aAggregateProps, getInfoService(), getFirstAggregateId());
     158             : }
     159             : 
     160             : 
     161             : }
     162             : //... namespace comphelper ................................................
     163             : 
     164             : #endif // INCLUDED_COMPHELPER_PROPARRHLP_HXX
     165             : 
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10