My Project
UDK 3.2.7 C/C++ API Reference
 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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _UNO_ENVIRONMENT_HXX_
29 #define _UNO_ENVIRONMENT_HXX_
30 
31 #include <rtl/alloc.h>
32 #include <rtl/ustring.hxx>
33 #include <uno/environment.h>
34 
35 #include "uno/lbnames.h"
36  //for docpp
38 namespace com
39 { //for docpp
41 namespace sun
42 { //for docpp
44 namespace star
45 { //for docpp
47 namespace uno
48 {
49 
55 {
58  uno_Environment * _pEnv;
59 
60 public:
67  inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)))) SAL_THROW(());
68 
70  // these are here to force memory de/allocation to sal lib.
71  inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
72  { return ::rtl_allocateMemory( nSize ); }
73  inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
74  { ::rtl_freeMemory( pMem ); }
75  inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
76  { return pMem; }
77  inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
78  {}
80 
85  inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
86 
93  inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
94 
95 
100  inline Environment( const Environment & rEnv ) SAL_THROW(());
101 
104  inline ~Environment() SAL_THROW(());
105 
111  inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW(());
117  inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
118  { return operator = ( rEnv._pEnv ); }
119 
124  inline uno_Environment * SAL_CALL get() const SAL_THROW(())
125  { return _pEnv; }
126 
131  inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
132  { return _pEnv->pTypeName; }
133 
138  inline void * SAL_CALL getContext() const SAL_THROW(())
139  { return _pEnv->pContext; }
140 
145  inline sal_Bool SAL_CALL is() const SAL_THROW(())
146  { return (_pEnv != 0); }
147 
150  inline void SAL_CALL clear() SAL_THROW(());
151 
158  inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
159 
166  inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
167 
172  inline void SAL_CALL enter() const SAL_THROW(());
173 
179  inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
180 };
181 //__________________________________________________________________________________________________
182 inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
183  : _pEnv( pEnv )
184 {
185  if (_pEnv)
186  (*_pEnv->acquire)( _pEnv );
187 }
188 //__________________________________________________________________________________________________
189 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
190  : _pEnv(NULL)
191 {
192  uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
193 }
194 //__________________________________________________________________________________________________
196  : _pEnv( rEnv._pEnv )
197 {
198  if (_pEnv)
199  (*_pEnv->acquire)( _pEnv );
200 }
201 //__________________________________________________________________________________________________
202 inline Environment::~Environment() SAL_THROW(())
203 {
204  if (_pEnv)
205  (*_pEnv->release)( _pEnv );
206 }
207 //__________________________________________________________________________________________________
208 inline void Environment::clear() SAL_THROW(())
209 {
210  if (_pEnv)
211  {
212  (*_pEnv->release)( _pEnv );
213  _pEnv = 0;
214  }
215 }
216 //__________________________________________________________________________________________________
218 {
219  if (pEnv != _pEnv)
220  {
221  if (pEnv)
222  (*pEnv->acquire)( pEnv );
223  if (_pEnv)
224  (*_pEnv->release)( _pEnv );
225  _pEnv = pEnv;
226  }
227  return *this;
228 }
229 //__________________________________________________________________________________________________
230 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(())
231 {
232  if (_pEnv)
233  uno_Environment_invoke_v(_pEnv, pCallee, pParam);
234 }
235 //__________________________________________________________________________________________________
236 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
237 {
238  if (_pEnv)
239  {
240  va_list param;
241 
242  va_start(param, pCallee);
243  uno_Environment_invoke_v(_pEnv, pCallee, &param);
244  va_end(param);
245  }
246 
247 }
248 //__________________________________________________________________________________________________
249 inline void SAL_CALL Environment::enter() const SAL_THROW(())
250 {
251  uno_Environment_enter(_pEnv);
252 }
253 //__________________________________________________________________________________________________
254 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
255 {
256  return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
257 }
258 //__________________________________________________________________________________________________
260 {
261  Environment environment;
262 
263  uno_Environment * pEnv = NULL;
264  uno_getCurrentEnvironment(&pEnv, typeName.pData);
265  environment = pEnv;
266  if (pEnv)
267  pEnv->release(pEnv);
268 
269  return environment;
270 }
271 
272 }
273 }
274 }
275 }
276 
277 #endif
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */