LCOV - code coverage report
Current view: top level - include/uno - environment.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 50 94.0 %
Date: 2014-11-03 Functions: 11 12 91.7 %
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             : #ifndef INCLUDED_UNO_ENVIRONMENT_HXX
      20             : #define INCLUDED_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(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
      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 )
      63             :         { return ::rtl_allocateMemory( nSize ); }
      64             :     inline static void SAL_CALL operator delete ( void * pMem )
      65             :         { ::rtl_freeMemory( pMem ); }
      66             :     inline static void * SAL_CALL operator new ( size_t, void * pMem )
      67             :         { return pMem; }
      68             :     inline static void SAL_CALL operator delete ( void *, void * )
      69             :         {}
      70             :     /// @endcond
      71             : 
      72             :     /** Constructor: acquires given environment
      73             : 
      74             :         @param pEnv environment
      75             :     */
      76             :     inline Environment( uno_Environment * pEnv = 0 );
      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 );
      85             : 
      86             : 
      87             :     /** Copy constructor: acquires given environment
      88             : 
      89             :         @param rEnv another environment
      90             :     */
      91             :     inline Environment( const Environment & rEnv );
      92             : 
      93             :     /** Destructor: releases a set environment.
      94             :     */
      95             :     inline ~Environment();
      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 );
     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        2066 :     inline Environment & SAL_CALL operator = ( const Environment & rEnv )
     109        2066 :         { 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     1161547 :     inline uno_Environment * SAL_CALL get() const
     116     1161547 :         { return _pEnv; }
     117             : 
     118             :     /** Gets type name of set environment.
     119             : 
     120             :         @return type name of set environment
     121             :     */
     122      197805 :     inline ::rtl::OUString SAL_CALL getTypeName() const
     123      197805 :         { 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
     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       84604 :     inline bool SAL_CALL is() const
     137       84604 :         { return (_pEnv != 0); }
     138             : 
     139             :     /** Releases a set environment.
     140             :     */
     141             :     inline void SAL_CALL clear();
     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;
     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;
     158             : 
     159             :     /** Enter this environment explicitly.
     160             : 
     161             :         @since UDK 3.2.7
     162             :     */
     163             :     inline void SAL_CALL enter() const;
     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;
     171             : };
     172             : 
     173      642141 : inline Environment::Environment( uno_Environment * pEnv )
     174      642141 :     : _pEnv( pEnv )
     175             : {
     176      642141 :     if (_pEnv)
     177      151780 :         (*_pEnv->acquire)( _pEnv );
     178      642141 : }
     179             : 
     180       73952 : inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
     181       73952 :     : _pEnv(NULL)
     182             : {
     183       73952 :     uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
     184       73952 : }
     185             : 
     186        3878 : inline Environment::Environment( const Environment & rEnv )
     187        3878 :     : _pEnv( rEnv._pEnv )
     188             : {
     189        3878 :     if (_pEnv)
     190        3878 :         (*_pEnv->acquire)( _pEnv );
     191        3878 : }
     192             : 
     193      719813 : inline Environment::~Environment()
     194             : {
     195      719813 :     if (_pEnv)
     196      304282 :         (*_pEnv->release)( _pEnv );
     197      719813 : }
     198             : 
     199             : inline void Environment::clear()
     200             : {
     201             :     if (_pEnv)
     202             :     {
     203             :         (*_pEnv->release)( _pEnv );
     204             :         _pEnv = 0;
     205             :     }
     206             : }
     207             : 
     208       73850 : inline Environment & Environment::operator = ( uno_Environment * pEnv )
     209             : {
     210       73850 :     if (pEnv != _pEnv)
     211             :     {
     212       73850 :         if (pEnv)
     213       73850 :             (*pEnv->acquire)( pEnv );
     214       73850 :         if (_pEnv)
     215           0 :             (*_pEnv->release)( _pEnv );
     216       73850 :         _pEnv = pEnv;
     217             :     }
     218       73850 :     return *this;
     219             : }
     220             : 
     221             : inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
     222             : {
     223             :     if (_pEnv)
     224             :         uno_Environment_invoke_v(_pEnv, pCallee, pParam);
     225             : }
     226             : 
     227         750 : inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
     228             : {
     229         750 :     if (_pEnv)
     230             :     {
     231             :         va_list param;
     232             : 
     233         750 :         va_start(param, pCallee);
     234         750 :         uno_Environment_invoke_v(_pEnv, pCallee, &param);
     235         750 :         va_end(param);
     236             :     }
     237             : 
     238         750 : }
     239             : 
     240             : inline void SAL_CALL Environment::enter() const
     241             : {
     242             :     uno_Environment_enter(_pEnv);
     243             : }
     244             : 
     245           0 : inline int  SAL_CALL Environment::isValid(rtl::OUString * pReason) const
     246             : {
     247           0 :     return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
     248             : }
     249             : 
     250       71784 : inline Environment Environment::getCurrent(rtl::OUString const & typeName)
     251             : {
     252       71784 :     Environment environment;
     253             : 
     254       71784 :     uno_Environment * pEnv = NULL;
     255       71784 :     uno_getCurrentEnvironment(&pEnv, typeName.pData);
     256       71784 :     environment = pEnv;
     257       71784 :     if (pEnv)
     258       71784 :         pEnv->release(pEnv);
     259             : 
     260       71784 :     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