Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / cppu / inc / uno / environment.hxx
blob51f2570131ed769defa21f1c90653ceb6084bed5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
28 #ifndef _UNO_ENVIRONMENT_HXX_
29 #define _UNO_ENVIRONMENT_HXX_
31 #include <rtl/alloc.h>
32 #include <rtl/ustring.hxx>
33 #include <uno/environment.h>
35 #include "uno/lbnames.h"
37 /** */ //for docpp
38 namespace com
40 /** */ //for docpp
41 namespace sun
43 /** */ //for docpp
44 namespace star
46 /** */ //for docpp
47 namespace uno
50 /** C++ wrapper for binary C uno_Environment.
52 @see uno_Environment
54 class Environment
56 /** binary C uno_Environment
58 uno_Environment * _pEnv;
60 public:
61 /** Returns the current Environment.
63 @param typeName the optional type of the Environment, falls back to "uno" in case being empty,
64 respectively to current C++ Environment.
65 @since UDK 3.2.7
67 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)))) SAL_THROW(());
69 /// @cond INTERNAL
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(())
79 /// @endcond
81 /** Constructor: acquires given environment
83 @param pEnv environment
85 inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW(());
87 /** Gets a specific environment. If the specified environment does not exist, then a default one
88 is created and registered.
90 @param envDcp descriptor of the environment
91 @param pContext context pointer
93 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW(());
96 /** Copy constructor: acquires given environment
98 @param rEnv another environment
100 inline Environment( const Environment & rEnv ) SAL_THROW(());
102 /** Destructor: releases a set environment.
104 inline ~Environment() SAL_THROW(());
106 /** Sets a given environment, i.e. acquires given one and releases a set one.
108 @param pEnv another environment
109 @return this environment
111 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW(());
112 /** Sets a given environment, i.e. acquires given one and releases a set one.
114 @param rEnv another environment
115 @return this environment
117 inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW(())
118 { return operator = ( rEnv._pEnv ); }
120 /** Provides UNacquired pointer to the set C environment.
122 @return UNacquired pointer to the C environment struct
124 inline uno_Environment * SAL_CALL get() const SAL_THROW(())
125 { return _pEnv; }
127 /** Gets type name of set environment.
129 @return type name of set environment
131 inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(())
132 { return _pEnv->pTypeName; }
134 /** Gets free context pointer of set environment.
136 @return free context pointer of set environment
138 inline void * SAL_CALL getContext() const SAL_THROW(())
139 { return _pEnv->pContext; }
141 /** Tests if a environment is set.
143 @return true, if a environment is set, false otherwise
145 inline sal_Bool SAL_CALL is() const SAL_THROW(())
146 { return (_pEnv != 0); }
148 /** Releases a set environment.
150 inline void SAL_CALL clear() SAL_THROW(());
152 /** Invoke the passed function in this environment.
154 @param pCallee the function to call
155 @param pParam the parameter pointer to be passed to the function
156 @since UDK 3.2.7
158 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(());
160 /** Invoke the passed function in this environment.
162 @param pCallee the function to call
163 @param ... the parameters to be passed to the function
164 @since UDK 3.2.7
166 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(());
168 /** Enter this environment explicitly.
170 @since UDK 3.2.7
172 inline void SAL_CALL enter() const SAL_THROW(());
174 /** Checks, if it is valid to currently call objects
175 belonging to this environment.
177 @since UDK 3.2.7
179 inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW(());
181 //__________________________________________________________________________________________________
182 inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW(())
183 : _pEnv( pEnv )
185 if (_pEnv)
186 (*_pEnv->acquire)( _pEnv );
188 //__________________________________________________________________________________________________
189 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW(())
190 : _pEnv(NULL)
192 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
194 //__________________________________________________________________________________________________
195 inline Environment::Environment( const Environment & rEnv ) SAL_THROW(())
196 : _pEnv( rEnv._pEnv )
198 if (_pEnv)
199 (*_pEnv->acquire)( _pEnv );
201 //__________________________________________________________________________________________________
202 inline Environment::~Environment() SAL_THROW(())
204 if (_pEnv)
205 (*_pEnv->release)( _pEnv );
207 //__________________________________________________________________________________________________
208 inline void Environment::clear() SAL_THROW(())
210 if (_pEnv)
212 (*_pEnv->release)( _pEnv );
213 _pEnv = 0;
216 //__________________________________________________________________________________________________
217 inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW(())
219 if (pEnv != _pEnv)
221 if (pEnv)
222 (*pEnv->acquire)( pEnv );
223 if (_pEnv)
224 (*_pEnv->release)( _pEnv );
225 _pEnv = pEnv;
227 return *this;
229 //__________________________________________________________________________________________________
230 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW(())
232 if (_pEnv)
233 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
235 //__________________________________________________________________________________________________
236 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW(())
238 if (_pEnv)
240 va_list param;
242 va_start(param, pCallee);
243 uno_Environment_invoke_v(_pEnv, pCallee, &param);
244 va_end(param);
248 //__________________________________________________________________________________________________
249 inline void SAL_CALL Environment::enter() const SAL_THROW(())
251 uno_Environment_enter(_pEnv);
253 //__________________________________________________________________________________________________
254 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW(())
256 return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason);
258 //__________________________________________________________________________________________________
259 inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW(())
261 Environment environment;
263 uno_Environment * pEnv = NULL;
264 uno_getCurrentEnvironment(&pEnv, typeName.pData);
265 environment = pEnv;
266 if (pEnv)
267 pEnv->release(pEnv);
269 return environment;
277 #endif
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */