LibreOffice LibreOffice 4.1 SDK C/C++ API Reference

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 _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 //for docpp
29 namespace com
30 { //for docpp
32 namespace sun
33 { //for docpp
35 namespace star
36 { //for docpp
38 namespace uno
39 {
40
45 class Environment
46 {
49 uno_Environment * _pEnv;
50
51 public:
58 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_STRINGIFY(CPPU_ENV))) SAL_THROW(());
59
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 {}
71
76 inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
77
84 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
85
86
91 inline Environment( const Environment & rEnv ) SAL_THROW(());
92
95 inline ~Environment() SAL_THROW(());
96
102 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW(());
108 inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
109 { return operator = ( rEnv._pEnv ); }
110
115 inline uno_Environment * SAL_CALL get() const SAL_THROW(())
116 { return _pEnv; }
117
122 inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
123 { return _pEnv->pTypeName; }
124
129 inline void * SAL_CALL getContext() const SAL_THROW(())
130 { return _pEnv->pContext; }
131
136 inline sal_Bool SAL_CALL is() const SAL_THROW(())
137 { return (_pEnv != 0); }
138
141 inline void SAL_CALL clear() SAL_THROW(());
142
149 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
150
157 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
158
163 inline void SAL_CALL enter() const SAL_THROW(());
164
170 inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
171 };
172 //__________________________________________________________________________________________________
173 inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
174 : _pEnv( pEnv )
175 {
176 if (_pEnv)
177 (*_pEnv->acquire)( _pEnv );
178 }
179 //__________________________________________________________________________________________________
180 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
181 : _pEnv(NULL)
182 {
183 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
184 }
185 //__________________________________________________________________________________________________
186 inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
187 : _pEnv( rEnv._pEnv )
188 {
189 if (_pEnv)
190 (*_pEnv->acquire)( _pEnv );
191 }
192 //__________________________________________________________________________________________________
193 inline Environment::~Environment() SAL_THROW(())
194 {
195 if (_pEnv)
196 (*_pEnv->release)( _pEnv );
197 }
198 //__________________________________________________________________________________________________
199 inline void Environment::clear() SAL_THROW(())
200 {
201 if (_pEnv)
202 {
203 (*_pEnv->release)( _pEnv );
204 _pEnv = 0;
205 }
206 }
207 //__________________________________________________________________________________________________
208 inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
209 {
210 if (pEnv != _pEnv)
211 {
212 if (pEnv)
213 (*pEnv->acquire)( pEnv );
214 if (_pEnv)
215 (*_pEnv->release)( _pEnv );
216 _pEnv = pEnv;
217 }
218 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 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
228 {
229 if (_pEnv)
230 {
231 va_list param;
232
233 va_start(param, pCallee);
234 uno_Environment_invoke_v(_pEnv, pCallee, &param);
235 va_end(param);
236 }
237
238 }
239 //__________________________________________________________________________________________________
240 inline void SAL_CALL Environment::enter() const SAL_THROW(())
241 {
242 uno_Environment_enter(_pEnv);
243 }
244 //__________________________________________________________________________________________________
245 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
246 {
247 return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
248 }
249 //__________________________________________________________________________________________________
250 inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
251 {
252 Environment environment;
253
254 uno_Environment * pEnv = NULL;
255 uno_getCurrentEnvironment(&pEnv, typeName.pData);
256 environment = pEnv;
257 if (pEnv)
258 pEnv->release(pEnv);
259
260 return environment;
261 }
262
263 }
264 }
265 }
266 }
267
268 #endif
269
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Environment::clear
void clear()
Releases a set environment.
Definition: environment.hxx:199
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:87
_uno_Environment::acquire
void(* acquire)(struct _uno_Environment *pEnv)
Acquires this environment.
Definition: environment.h:63
com::sun::star::uno::Environment::getTypeName
inline::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition: environment.hxx:122
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:245
SAL_THROW
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
com::sun::star::uno::Environment::getContext
void * getContext() const
Gets free context pointer of set environment.
Definition: environment.hxx:129
_uno_Environment::pContext
void * pContext
free context pointer to be used for specific classes of environments (e.g., a jvm pointer) ...
Definition: environment.h:53
environment.h
uno_Environment_enter
CPPU_DLLPUBLIC void uno_Environment_enter(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Enter an environment explicitly.
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_EnvCallee
void uno_EnvCallee(va_list *pParam)
Typedef for variable argument function.
Definition: environment.h:339
com::sun::star::uno::Environment::invoke
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition: environment.hxx:227
uno_getCurrentEnvironment
CPPU_DLLPUBLIC void uno_getCurrentEnvironment(uno_Environment **ppEnv, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
Returns the current Environment.
com::sun::star::uno::Environment::getCurrent
static Environment getCurrent(rtl::OUString const &typeName=rtl::OUString(CPPU_STRINGIFY(CPPU_ENV)))
Returns the current Environment.
Definition: environment.hxx:250
_uno_Environment
The binary specification of an UNO environment.
Definition: environment.h:41
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::release
void(* release)(struct _uno_Environment *pEnv)
Releases this environment; last release of environment will revoke the environment from runtime...
Definition: environment.h:70
com::sun::star::uno::Environment::Environment
Environment(uno_Environment *pEnv=0)
Constructor: acquires given environment.
Definition: environment.hxx:173
_uno_Environment::pTypeName
rtl_uString * pTypeName
type name of environment
Definition: environment.h:49
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
com::sun::star::uno::Environment::enter
void enter() const
Enter this environment explicitly.
Definition: environment.hxx:240
lbnames.h
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
ustring.hxx
com::sun::star::uno::Environment::~Environment
~Environment()
Destructor: releases a set environment.
Definition: environment.hxx:193
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:221
com::sun::star::uno::Environment
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:45
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::operator=
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition: environment.hxx:208
com::sun::star::uno::Environment::is
sal_Bool is() const
Tests if a environment is set.
Definition: environment.hxx:136
alloc.h