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

Generated by: LCOV version 1.10