LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/uno - environment.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 50 94.0 %
Date: 2012-08-25 Functions: 11 12 91.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 22 59.1 %

           Branch data     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                 :            : #ifndef _UNO_ENVIRONMENT_HXX_
      20                 :            : #define _UNO_ENVIRONMENT_HXX_
      21                 :            : 
      22                 :            : #include <rtl/alloc.h>
      23                 :            : #include <rtl/ustring.hxx>
      24                 :            : #include <uno/environment.h>
      25                 :            : 
      26                 :            : #include "uno/lbnames.h"
      27                 :            : 
      28                 :            : /** */ //for docpp
      29                 :            : namespace com
      30                 :            : {
      31                 :            : /** */ //for docpp
      32                 :            : namespace sun
      33                 :            : {
      34                 :            : /** */ //for docpp
      35                 :            : namespace star
      36                 :            : {
      37                 :            : /** */ //for docpp
      38                 :            : namespace uno
      39                 :            : {
      40                 :            : 
      41                 :            : /** C++ wrapper for binary C uno_Environment.
      42                 :            : 
      43                 :            :     @see uno_Environment
      44                 :            : */
      45                 :            : class Environment
      46                 :            : {
      47                 :            :     /** binary C uno_Environment
      48                 :            :     */
      49                 :            :     uno_Environment * _pEnv;
      50                 :            : 
      51                 :            : public:
      52                 :            :     /** Returns the current Environment.
      53                 :            : 
      54                 :            :         @param typeName   the optional type of the Environment, falls back to "uno" in case being empty,
      55                 :            :                           respectively to current C++ Environment.
      56                 :            :         @since UDK 3.2.7
      57                 :            :     */
      58                 :            :     inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)))) SAL_THROW(());
      59                 :            : 
      60                 :            :     /// @cond INTERNAL
      61                 :            :     // these are here to force memory de/allocation to sal lib.
      62                 :            :     inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
      63                 :            :         { return ::rtl_allocateMemory( nSize ); }
      64                 :            :     inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
      65                 :            :         { ::rtl_freeMemory( pMem ); }
      66                 :            :     inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
      67                 :            :         { return pMem; }
      68                 :            :     inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
      69                 :            :         {}
      70                 :            :     /// @endcond
      71                 :            : 
      72                 :            :     /** Constructor: acquires given environment
      73                 :            : 
      74                 :            :         @param pEnv environment
      75                 :            :     */
      76                 :            :     inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
      77                 :            : 
      78                 :            :     /** Gets a specific environment. If the specified environment does not exist, then a default one
      79                 :            :         is created and registered.
      80                 :            : 
      81                 :            :         @param envDcp           descriptor of the environment
      82                 :            :         @param pContext         context pointer
      83                 :            :     */
      84                 :            :     inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
      85                 :            : 
      86                 :            : 
      87                 :            :     /** Copy constructor: acquires given environment
      88                 :            : 
      89                 :            :         @param rEnv another environment
      90                 :            :     */
      91                 :            :     inline Environment( const Environment & rEnv ) SAL_THROW(());
      92                 :            : 
      93                 :            :     /** Destructor: releases a set environment.
      94                 :            :     */
      95                 :            :     inline ~Environment() SAL_THROW(());
      96                 :            : 
      97                 :            :     /** Sets a given environment, i.e. acquires given one and releases a set one.
      98                 :            : 
      99                 :            :         @param pEnv another environment
     100                 :            :         @return this environment
     101                 :            :     */
     102                 :            :     inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW(());
     103                 :            :     /** Sets a given environment, i.e. acquires given one and releases a set one.
     104                 :            : 
     105                 :            :         @param rEnv another environment
     106                 :            :         @return this environment
     107                 :            :     */
     108                 :      31616 :     inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
     109                 :      31616 :         { return operator = ( rEnv._pEnv ); }
     110                 :            : 
     111                 :            :     /** Provides UNacquired pointer to the set C environment.
     112                 :            : 
     113                 :            :         @return UNacquired pointer to the C environment struct
     114                 :            :     */
     115                 :    1475850 :     inline uno_Environment * SAL_CALL get() const SAL_THROW(())
     116                 :    1475850 :         { return _pEnv; }
     117                 :            : 
     118                 :            :     /** Gets type name of set environment.
     119                 :            : 
     120                 :            :         @return type name of set environment
     121                 :            :     */
     122                 :     283620 :     inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
     123                 :     283620 :         { return _pEnv->pTypeName; }
     124                 :            : 
     125                 :            :     /** Gets free context pointer of set environment.
     126                 :            : 
     127                 :            :         @return free context pointer of set environment
     128                 :            :     */
     129                 :            :     inline void * SAL_CALL getContext() const SAL_THROW(())
     130                 :            :         { return _pEnv->pContext; }
     131                 :            : 
     132                 :            :     /** Tests if a environment is set.
     133                 :            : 
     134                 :            :         @return true, if a environment is set, false otherwise
     135                 :            :     */
     136                 :     138784 :     inline sal_Bool SAL_CALL is() const SAL_THROW(())
     137                 :     138784 :         { return (_pEnv != 0); }
     138                 :            : 
     139                 :            :     /** Releases a set environment.
     140                 :            :     */
     141                 :            :     inline void SAL_CALL clear() SAL_THROW(());
     142                 :            : 
     143                 :            :     /** Invoke the passed function in this environment.
     144                 :            : 
     145                 :            :         @param pCallee  the function to call
     146                 :            :         @param pParam   the parameter pointer to be passed to the function
     147                 :            :         @since UDK 3.2.7
     148                 :            :     */
     149                 :            :     inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
     150                 :            : 
     151                 :            :     /** Invoke the passed function in this environment.
     152                 :            : 
     153                 :            :         @param pCallee  the function to call
     154                 :            :         @param ...      the parameters to be passed to the function
     155                 :            :         @since UDK 3.2.7
     156                 :            :     */
     157                 :            :     inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
     158                 :            : 
     159                 :            :     /** Enter this environment explicitly.
     160                 :            : 
     161                 :            :         @since UDK 3.2.7
     162                 :            :     */
     163                 :            :     inline void SAL_CALL enter() const SAL_THROW(());
     164                 :            : 
     165                 :            :     /** Checks, if it is valid to currently call objects
     166                 :            :         belonging to this environment.
     167                 :            : 
     168                 :            :         @since UDK 3.2.7
     169                 :            :     */
     170                 :            :     inline int  SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
     171                 :            : };
     172                 :            : //__________________________________________________________________________________________________
     173                 :     769970 : inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
     174                 :     769970 :     : _pEnv( pEnv )
     175                 :            : {
     176         [ +  + ]:     769970 :     if (_pEnv)
     177                 :     293707 :         (*_pEnv->acquire)( _pEnv );
     178                 :     769970 : }
     179                 :            : //__________________________________________________________________________________________________
     180                 :      56987 : inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
     181                 :      56987 :     : _pEnv(NULL)
     182                 :            : {
     183                 :      56987 :     uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
     184                 :      56987 : }
     185                 :            : //__________________________________________________________________________________________________
     186                 :      33601 : inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
     187                 :      33601 :     : _pEnv( rEnv._pEnv )
     188                 :            : {
     189         [ +  - ]:      33601 :     if (_pEnv)
     190                 :      33601 :         (*_pEnv->acquire)( _pEnv );
     191                 :      33601 : }
     192                 :            : //__________________________________________________________________________________________________
     193                 :     860526 : inline Environment::~Environment() SAL_THROW(())
     194                 :            : {
     195         [ +  + ]:     860526 :     if (_pEnv)
     196                 :     471276 :         (*_pEnv->release)( _pEnv );
     197                 :     860526 : }
     198                 :            : //__________________________________________________________________________________________________
     199                 :            : inline void Environment::clear() SAL_THROW(())
     200                 :            : {
     201                 :            :     if (_pEnv)
     202                 :            :     {
     203                 :            :         (*_pEnv->release)( _pEnv );
     204                 :            :         _pEnv = 0;
     205                 :            :     }
     206                 :            : }
     207                 :            : //__________________________________________________________________________________________________
     208                 :      86776 : inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
     209                 :            : {
     210         [ +  - ]:      86776 :     if (pEnv != _pEnv)
     211                 :            :     {
     212         [ +  - ]:      86776 :         if (pEnv)
     213                 :      86776 :             (*pEnv->acquire)( pEnv );
     214         [ -  + ]:      86776 :         if (_pEnv)
     215                 :          0 :             (*_pEnv->release)( _pEnv );
     216                 :      86776 :         _pEnv = pEnv;
     217                 :            :     }
     218                 :      86776 :     return *this;
     219                 :            : }
     220                 :            : //__________________________________________________________________________________________________
     221                 :            : inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(())
     222                 :            : {
     223                 :            :     if (_pEnv)
     224                 :            :         uno_Environment_invoke_v(_pEnv, pCallee, pParam);
     225                 :            : }
     226                 :            : //__________________________________________________________________________________________________
     227                 :      30657 : inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
     228                 :            : {
     229         [ +  - ]:      30657 :     if (_pEnv)
     230                 :            :     {
     231                 :            :         va_list param;
     232                 :            : 
     233                 :      30657 :         va_start(param, pCallee);
     234                 :      30657 :         uno_Environment_invoke_v(_pEnv, pCallee, &param);
     235                 :      30657 :         va_end(param);
     236                 :            :     }
     237                 :            : 
     238                 :      30657 : }
     239                 :            : //__________________________________________________________________________________________________
     240                 :            : inline void SAL_CALL Environment::enter() const SAL_THROW(())
     241                 :            : {
     242                 :            :     uno_Environment_enter(_pEnv);
     243                 :            : }
     244                 :            : //__________________________________________________________________________________________________
     245                 :          0 : inline int  SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
     246                 :            : {
     247                 :          0 :     return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
     248                 :            : }
     249                 :            : //__________________________________________________________________________________________________
     250                 :      55160 : inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
     251                 :            : {
     252         [ +  - ]:      55160 :     Environment environment;
     253                 :            : 
     254                 :      55160 :     uno_Environment * pEnv = NULL;
     255                 :      55160 :     uno_getCurrentEnvironment(&pEnv, typeName.pData);
     256         [ +  - ]:      55160 :     environment = pEnv;
     257         [ +  - ]:      55160 :     if (pEnv)
     258         [ +  - ]:      55160 :         pEnv->release(pEnv);
     259                 :            : 
     260                 :      55160 :     return environment;
     261                 :            : }
     262                 :            : 
     263                 :            : }
     264                 :            : }
     265                 :            : }
     266                 :            : }
     267                 :            : 
     268                 :            : #endif
     269                 :            : 
     270                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10