LibreOffice: uno/environment.hxx Source File

LibreOffice LibreOffice 7.3 SDK C/C++ API Reference

environment.hxx
Go to the documentation of this file.
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/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_UNO_ENVIRONMENT_HXX
24#define INCLUDED_UNO_ENVIRONMENT_HXX
25
26#include "sal/config.h"
27
28#include <cstddef>
29
30#include "rtl/alloc.h"
31#include "rtl/ustring.hxx"
32#include "uno/environment.h"
33
34#include "uno/lbnames.h"
35 //for docpp
37namespace com
38{ //for docpp
40namespace sun
41{ //for docpp
43namespace star
44{ //for docpp
46namespace uno
47{
48
53 class Environment
54{
57 uno_Environment * _pEnv;
58
59public:
66 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
67
69 // these are here to force memory de/allocation to sal lib.
70 static void * SAL_CALL operator new ( size_t nSize )
71 { return ::rtl_allocateMemory( nSize ); }
72 static void SAL_CALL operator delete ( void * pMem )
73 { ::rtl_freeMemory( pMem ); }
74 static void * SAL_CALL operator new ( size_t, void * pMem )
75 { return pMem; }
76 static void SAL_CALL operator delete ( void *, void * )
77 {}
79
84 inline Environment( uno_Environment * pEnv = NULL );
85
92 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
93
94
99 inline Environment( const Environment & rEnv );
100
101#if defined LIBO_INTERNAL_ONLY
102 Environment(Environment && other) noexcept : _pEnv(other._pEnv)
103 { other._pEnv = nullptr; }
104#endif
105
108 inline ~Environment();
109
115 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
121 Environment & SAL_CALL operator = ( const Environment & rEnv )
122 { return operator = ( rEnv._pEnv ); }
123
124#if defined LIBO_INTERNAL_ONLY
125 Environment & operator =(Environment && other) {
126 if (_pEnv != nullptr) {
127 (*_pEnv->release)(_pEnv);
128 }
129 _pEnv = other._pEnv;
130 other._pEnv = nullptr;
131 return *this;
132 }
133#endif
134
139 uno_Environment * SAL_CALL get() const
140 { return _pEnv; }
141
146 ::rtl::OUString SAL_CALL getTypeName() const
147 { return _pEnv->pTypeName; }
148
153 void * SAL_CALL getContext() const
154 { return _pEnv->pContext; }
155
160 bool SAL_CALL is() const
161 { return (_pEnv != NULL); }
162
165 inline void SAL_CALL clear();
166
173 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
174
181 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
182
187 inline void SAL_CALL enter() const;
188
194 inline int SAL_CALL isValid(rtl::OUString * pReason) const;
195};
196
197 inline Environment::Environment( uno_Environment * pEnv )
198 : _pEnv( pEnv )
199{
200 if (_pEnv)
201 (*_pEnv->acquire)( _pEnv );
202}
203
204 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
205 : _pEnv(NULL)
206{
207 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
208}
209
210 inline Environment::Environment( const Environment & rEnv )
211 : _pEnv( rEnv._pEnv )
212{
213 if (_pEnv)
214 (*_pEnv->acquire)( _pEnv );
215}
216
217 inline Environment::~Environment()
218{
219 if (_pEnv)
220 (*_pEnv->release)( _pEnv );
221}
222
223 inline void Environment::clear()
224{
225 if (_pEnv)
226 {
227 (*_pEnv->release)( _pEnv );
228 _pEnv = NULL;
229 }
230}
231
232 inline Environment & Environment::operator = ( uno_Environment * pEnv )
233{
234 if (pEnv != _pEnv)
235 {
236 if (pEnv)
237 (*pEnv->acquire)( pEnv );
238 if (_pEnv)
239 (*_pEnv->release)( _pEnv );
240 _pEnv = pEnv;
241 }
242 return *this;
243}
244
245 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
246{
247 if (_pEnv)
248 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
249}
250
251 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
252{
253 if (_pEnv)
254 {
255 va_list param;
256
257 va_start(param, pCallee);
258 uno_Environment_invoke_v(_pEnv, pCallee, &param);
259 va_end(param);
260 }
261
262}
263
264 inline void SAL_CALL Environment::enter() const
265{
266 uno_Environment_enter(_pEnv);
267}
268
269 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
270{
271 return uno_Environment_isValid(_pEnv, &pReason->pData);
272}
273
274 inline Environment Environment::getCurrent(rtl::OUString const & typeName)
275{
276 Environment environment;
277
278 uno_Environment * pEnv = NULL;
279 uno_getCurrentEnvironment(&pEnv, typeName.pData);
280 environment = pEnv;
281 if (pEnv)
282 pEnv->release(pEnv);
283
284 return environment;
285}
286
287}
288}
289}
290}
291
292#endif
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
config.h
alloc.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
ustring.hxx
lbnames.h
environment.h
uno_Environment
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of a UNO environment.
uno_getEnvironment
CPPU_DLLPUBLIC void uno_getEnvironment(uno_Environment **ppEnv, rtl_uString *pEnvDcp, void *pContext) SAL_THROW_EXTERN_C()
Gets a specific environment.
uno_Environment_isValid
CPPU_DLLPUBLIC int uno_Environment_isValid(uno_Environment *pEnv, rtl_uString **pReason) SAL_THROW_EXTERN_C()
Check if a particular environment is currently valid, so that objects of that environment might be ca...
uno_Environment_enter
CPPU_DLLPUBLIC void uno_Environment_enter(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Enter an environment explicitly.
uno_Environment_invoke_v
CPPU_DLLPUBLIC void uno_Environment_invoke_v(uno_Environment *pEnv, uno_EnvCallee *pCallee, va_list *pParam) SAL_THROW_EXTERN_C()
Invoke the passed function in the given environment.
uno_EnvCallee
void uno_EnvCallee(va_list *pParam)
Typedef for variable argument function.
Definition: environment.h:342
uno_getCurrentEnvironment
CPPU_DLLPUBLIC void uno_getCurrentEnvironment(uno_Environment **ppEnv, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
Returns the current Environment.
com
Definition: types.h:359
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:204
com::sun::star::uno::Environment
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:54
com::sun::star::uno::Environment::invoke_v
void invoke_v(uno_EnvCallee *pCallee, va_list *pParam) const
Invoke the passed function in this environment.
Definition: environment.hxx:245
com::sun::star::uno::Environment::invoke
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition: environment.hxx:251
com::sun::star::uno::Environment::clear
void clear()
Releases a set environment.
Definition: environment.hxx:223
com::sun::star::uno::Environment::Environment
Environment(uno_Environment *pEnv=NULL)
Constructor: acquires given environment.
Definition: environment.hxx:197
com::sun::star::uno::Environment::~Environment
~Environment()
Destructor: releases a set environment.
Definition: environment.hxx:217
com::sun::star::uno::Environment::getCurrent
static Environment getCurrent(rtl::OUString const &typeName=rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME))
Returns the current Environment.
Definition: environment.hxx:274
com::sun::star::uno::Environment::operator=
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition: environment.hxx:232
com::sun::star::uno::Environment::getContext
void * getContext() const
Gets free context pointer of set environment.
Definition: environment.hxx:153
com::sun::star::uno::Environment::getTypeName
::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition: environment.hxx:146
com::sun::star::uno::Environment::isValid
int isValid(rtl::OUString *pReason) const
Checks, if it is valid to currently call objects belonging to this environment.
Definition: environment.hxx:269
com::sun::star::uno::Environment::is
bool is() const
Tests if an environment is set.
Definition: environment.hxx:160
com::sun::star::uno::Environment::get
uno_Environment * get() const
Provides UNacquired pointer to the set C environment.
Definition: environment.hxx:139
com::sun::star::uno::Environment::enter
void enter() const
Enter this environment explicitly.
Definition: environment.hxx:264