LibreOffice: uno/environment.hxx Source File

LibreOffice LibreOffice 5.1 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 #ifndef INCLUDED_UNO_ENVIRONMENT_HXX
20 #define INCLUDED_UNO_ENVIRONMENT_HXX
21
22 #include <sal/config.h>
23
24 #include <cstddef>
25
26 #include <rtl/alloc.h>
27 #include <rtl/ustring.hxx>
28 #include <uno/environment.h>
29
30 #include <uno/lbnames.h>
31 //for docpp
33 namespace com
34 { //for docpp
36 namespace sun
37 { //for docpp
39 namespace star
40 { //for docpp
42 namespace uno
43 {
44
49 class Environment
50 {
53 uno_Environment * _pEnv;
54
55 public:
62 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
63
65 // these are here to force memory de/allocation to sal lib.
66 inline static void * SAL_CALL operator new ( size_t nSize )
67 { return ::rtl_allocateMemory( nSize ); }
68 inline static void SAL_CALL operator delete ( void * pMem )
69 { ::rtl_freeMemory( pMem ); }
70 inline static void * SAL_CALL operator new ( size_t, void * pMem )
71 { return pMem; }
72 inline static void SAL_CALL operator delete ( void *, void * )
73 {}
75
80 inline Environment( uno_Environment * pEnv = NULL );
81
88 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
89
90
95 inline Environment( const Environment & rEnv );
96
99 inline ~Environment();
100
106 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
112 inline Environment & SAL_CALL operator = ( const Environment & rEnv )
113 { return operator = ( rEnv._pEnv ); }
114
119 inline uno_Environment * SAL_CALL get() const
120 { return _pEnv; }
121
126 inline ::rtl::OUString SAL_CALL getTypeName() const
127 { return _pEnv->pTypeName; }
128
133 inline void * SAL_CALL getContext() const
134 { return _pEnv->pContext; }
135
140 inline bool SAL_CALL is() const
141 { return (_pEnv != NULL); }
142
145 inline void SAL_CALL clear();
146
153 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
154
161 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
162
167 inline void SAL_CALL enter() const;
168
174 inline int SAL_CALL isValid(rtl::OUString * pReason) const;
175 };
176
177 inline Environment::Environment( uno_Environment * pEnv )
178 : _pEnv( pEnv )
179 {
180 if (_pEnv)
181 (*_pEnv->acquire)( _pEnv );
182 }
183
184 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
185 : _pEnv(NULL)
186 {
187 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
188 }
189
190 inline Environment::Environment( const Environment & rEnv )
191 : _pEnv( rEnv._pEnv )
192 {
193 if (_pEnv)
194 (*_pEnv->acquire)( _pEnv );
195 }
196
197 inline Environment::~Environment()
198 {
199 if (_pEnv)
200 (*_pEnv->release)( _pEnv );
201 }
202
203 inline void Environment::clear()
204 {
205 if (_pEnv)
206 {
207 (*_pEnv->release)( _pEnv );
208 _pEnv = NULL;
209 }
210 }
211
212 inline Environment & Environment::operator = ( uno_Environment * pEnv )
213 {
214 if (pEnv != _pEnv)
215 {
216 if (pEnv)
217 (*pEnv->acquire)( pEnv );
218 if (_pEnv)
219 (*_pEnv->release)( _pEnv );
220 _pEnv = pEnv;
221 }
222 return *this;
223 }
224
225 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
226 {
227 if (_pEnv)
228 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
229 }
230
231 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
232 {
233 if (_pEnv)
234 {
235 va_list param;
236
237 va_start(param, pCallee);
238 uno_Environment_invoke_v(_pEnv, pCallee, &param);
239 va_end(param);
240 }
241
242 }
243
244 inline void SAL_CALL Environment::enter() const
245 {
246 uno_Environment_enter(_pEnv);
247 }
248
249 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
250 {
251 return uno_Environment_isValid(_pEnv, &pReason->pData);
252 }
253
254 inline Environment Environment::getCurrent(rtl::OUString const & typeName)
255 {
256 Environment environment;
257
258 uno_Environment * pEnv = NULL;
259 uno_getCurrentEnvironment(&pEnv, typeName.pData);
260 environment = pEnv;
261 if (pEnv)
262 pEnv->release(pEnv);
263
264 return environment;
265 }
266
267 }
268 }
269 }
270 }
271
272 #endif
273
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:249
config.h
com::sun::star::uno::Environment::operator=
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition: environment.hxx:212
uno_getEnvironment
CPPU_DLLPUBLIC void uno_getEnvironment(uno_Environment **ppEnv, rtl_uString *pEnvDcp, void *pContext) SAL_THROW_EXTERN_C()
Gets a specific environment.
alloc.h
uno_EnvCallee
void uno_EnvCallee(va_list *pParam)
Typedef for variable argument function.
Definition: environment.h:338
com::sun::star::uno::Environment::clear
void clear()
Releases a set environment.
Definition: environment.hxx:203
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
com::sun::star::uno::Environment::invoke
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition: environment.hxx:231
com::sun::star::uno::Environment::getTypeName
inline::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition: environment.hxx:126
com
Definition: types.h:389
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.
com::sun::star::uno::Environment::is
bool is() const
Tests if a environment is set.
Definition: environment.hxx:140
com::sun::star::uno::Environment::getContext
void * getContext() const
Gets free context pointer of set environment.
Definition: environment.hxx:133
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...
com::sun::star::uno::Environment
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:49
lbnames.h
uno_Environment_enter
CPPU_DLLPUBLIC void uno_Environment_enter(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Enter an environment explicitly.
environment.h
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:225
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
ustring.hxx
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:254
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
com::sun::star::uno::Environment::enter
void enter() const
Enter this environment explicitly.
Definition: environment.hxx:244
uno_Environment
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of an UNO environment.
com::sun::star::uno::Environment::Environment
Environment(uno_Environment *pEnv=NULL)
Constructor: acquires given environment.
Definition: environment.hxx:177
com::sun::star::uno::Environment::~Environment
~Environment()
Destructor: releases a set environment.
Definition: environment.hxx:197
uno_getCurrentEnvironment
CPPU_DLLPUBLIC void uno_getCurrentEnvironment(uno_Environment **ppEnv, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
Returns the current Environment.