LCOV - code coverage report
Current view: top level - include/uno - environment.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 47 50 94.0 %
Date: 2014-04-14 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)) 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           6 :     inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
     109           6 :         { 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         100 :     inline uno_Environment * SAL_CALL get() const SAL_THROW(())
     116         100 :         { return _pEnv; }
     117             : 
     118             :     /** Gets type name of set environment.
     119             : 
     120             :         @return type name of set environment
     121             :     */
     122          22 :     inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
     123          22 :         { 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          16 :     inline bool SAL_CALL is() const SAL_THROW(())
     137          16 :         { 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          41 : inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
     174          41 :     : _pEnv( pEnv )
     175             : {
     176          41 :     if (_pEnv)
     177          27 :         (*_pEnv->acquire)( _pEnv );
     178          41 : }
     179             : 
     180           9 : inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
     181           9 :     : _pEnv(NULL)
     182             : {
     183           9 :     uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
     184           9 : }
     185             : 
     186           5 : inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
     187           5 :     : _pEnv( rEnv._pEnv )
     188             : {
     189           5 :     if (_pEnv)
     190           5 :         (*_pEnv->acquire)( _pEnv );
     191           5 : }
     192             : 
     193          55 : inline Environment::~Environment() SAL_THROW(())
     194             : {
     195          55 :     if (_pEnv)
     196          54 :         (*_pEnv->release)( _pEnv );
     197          55 : }
     198             : 
     199             : inline void Environment::clear() SAL_THROW(())
     200             : {
     201             :     if (_pEnv)
     202             :     {
     203             :         (*_pEnv->release)( _pEnv );
     204             :         _pEnv = 0;
     205             :     }
     206             : }
     207             : 
     208          13 : inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
     209             : {
     210          13 :     if (pEnv != _pEnv)
     211             :     {
     212          13 :         if (pEnv)
     213          13 :             (*pEnv->acquire)( pEnv );
     214          13 :         if (_pEnv)
     215           0 :             (*_pEnv->release)( _pEnv );
     216          13 :         _pEnv = pEnv;
     217             :     }
     218          13 :     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           1 : inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
     228             : {
     229           1 :     if (_pEnv)
     230             :     {
     231             :         va_list param;
     232             : 
     233           1 :         va_start(param, pCallee);
     234           1 :         uno_Environment_invoke_v(_pEnv, pCallee, &param);
     235           1 :         va_end(param);
     236             :     }
     237             : 
     238           1 : }
     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           7 : inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
     251             : {
     252           7 :     Environment environment;
     253             : 
     254           7 :     uno_Environment * pEnv = NULL;
     255           7 :     uno_getCurrentEnvironment(&pEnv, typeName.pData);
     256           7 :     environment = pEnv;
     257           7 :     if (pEnv)
     258           7 :         pEnv->release(pEnv);
     259             : 
     260           7 :     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