AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #ifndef INCLUDED_UNO_ENVIRONMENT_HXX
4 #define INCLUDED_UNO_ENVIRONMENT_HXX
5 
6 #include "sal/config.h"
7 
8 #include <cstddef>
9 
10 #include "rtl/alloc.h"
11 #include "rtl/ustring.hxx"
12 #include "uno/environment.h"
13 
14 #include "uno/lbnames.h"
15 
16 namespace com
17 {
18 namespace sun
19 {
20 namespace star
21 {
22 namespace uno
23 {
24 
30 {
33  uno_Environment * _pEnv;
34 
35 public:
42  inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
43 
45  // these are here to force memory de/allocation to sal lib.
46  static void * SAL_CALL operator new ( size_t nSize )
47  { return ::rtl_allocateMemory( nSize ); }
48  static void SAL_CALL operator delete ( void * pMem )
49  { ::rtl_freeMemory( pMem ); }
50  static void * SAL_CALL operator new ( size_t, void * pMem )
51  { return pMem; }
52  static void SAL_CALL operator delete ( void *, void * )
53  {}
55 
60  inline Environment( uno_Environment * pEnv = NULL );
61 
68  inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
69 
70 
75  inline Environment( const Environment & rEnv );
76 
77 #if defined LIBO_INTERNAL_ONLY
78  Environment(Environment && other) noexcept : _pEnv(other._pEnv)
79  { other._pEnv = nullptr; }
80 #endif
81 
84  inline ~Environment();
85 
91  inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
97  Environment & SAL_CALL operator = ( const Environment & rEnv )
98  { return operator = ( rEnv._pEnv ); }
99 
100 #if defined LIBO_INTERNAL_ONLY
101  Environment & operator =(Environment && other) {
102  if (_pEnv != nullptr) {
103  (*_pEnv->release)(_pEnv);
104  }
105  _pEnv = other._pEnv;
106  other._pEnv = nullptr;
107  return *this;
108  }
109 #endif
110 
115  uno_Environment * SAL_CALL get() const
116  { return _pEnv; }
117 
122  ::rtl::OUString SAL_CALL getTypeName() const
123  { return _pEnv->pTypeName; }
124 
129  void * SAL_CALL getContext() const
130  { return _pEnv->pContext; }
131 
136  bool SAL_CALL is() const
137  { return (_pEnv != NULL); }
138 
141  inline void SAL_CALL clear();
142 
149  inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
150 
157  inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
158 
163  inline void SAL_CALL enter() const;
164 
170  inline int SAL_CALL isValid(rtl::OUString * pReason) const;
171 };
172 
174  : _pEnv( pEnv )
175 {
176  if (_pEnv)
177  (*_pEnv->acquire)( _pEnv );
178 }
179 
180 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
181  : _pEnv(NULL)
182 {
183  uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
184 }
185 
186 inline Environment::Environment( const Environment & rEnv )
187  : _pEnv( rEnv._pEnv )
188 {
189  if (_pEnv)
190  (*_pEnv->acquire)( _pEnv );
191 }
192 
194 {
195  if (_pEnv)
196  (*_pEnv->release)( _pEnv );
197 }
198 
199 inline void Environment::clear()
200 {
201  if (_pEnv)
202  {
203  (*_pEnv->release)( _pEnv );
204  _pEnv = NULL;
205  }
206 }
207 
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
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
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
241 {
242  uno_Environment_enter(_pEnv);
243 }
244 
245 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
246 {
247  return uno_Environment_isValid(_pEnv, &pReason->pData);
248 }
249 
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: */
int isValid(rtl::OUString *pReason) const
Checks, if it is valid to currently call objects belonging to this environment.
Definition: environment.hxx:245
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
Environment & operator=(uno_Environment *pEnv)
Sets a given environment, i.e.
Definition: environment.hxx:208
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
void clear()
Releases a set environment.
Definition: environment.hxx:199
CPPU_DLLPUBLIC void uno_getEnvironment(uno_Environment **ppEnv, rtl_uString *pEnvDcp, void *pContext) SAL_THROW_EXTERN_C()
Gets a specific environment.
void invoke(uno_EnvCallee *pCallee,...) const
Invoke the passed function in this environment.
Definition: environment.hxx:227
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.
bool is() const
Tests if an environment is set.
Definition: environment.hxx:136
void * getContext() const
Gets free context pointer of set environment.
Definition: environment.hxx:129
pData
Definition: ustring.hxx:334
C++ wrapper for binary C uno_Environment.
Definition: environment.hxx:29
void invoke_v(uno_EnvCallee *pCallee, va_list *pParam) const
Invoke the passed function in this environment.
Definition: environment.hxx:221
CPPU_DLLPUBLIC void uno_Environment_enter(uno_Environment *pEnv) SAL_THROW_EXTERN_C()
Enter an environment explicitly.
static Environment getCurrent(rtl::OUString const &typeName=rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME))
Returns the current Environment.
Definition: environment.hxx:250
struct SAL_DLLPUBLIC_RTTI _uno_Environment uno_Environment
The binary specification of a UNO environment.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
CPPU_DLLPUBLIC void uno_getCurrentEnvironment(uno_Environment **ppEnv, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
Returns the current Environment.
void enter() const
Enter this environment explicitly.
Definition: environment.hxx:240
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...
Environment(uno_Environment *pEnv=NULL)
Constructor: acquires given environment.
Definition: environment.hxx:173
::rtl::OUString getTypeName() const
Gets type name of set environment.
Definition: environment.hxx:122
~Environment()
Destructor: releases a set environment.
Definition: environment.hxx:193
void uno_EnvCallee(va_list *pParam)
Typedef for variable argument function.
Definition: environment.h:322