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

Generated by: LCOV version 1.11