update emoji autocorrect entries from po-files
[LibreOffice.git] / include / uno / environment.hxx
blob78cf1634cd416e19d6a203ee057c1c9b1289ee7c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_UNO_ENVIRONMENT_HXX
20 #define INCLUDED_UNO_ENVIRONMENT_HXX
22 #include <rtl/alloc.h>
23 #include <rtl/ustring.hxx>
24 #include <uno/environment.h>
26 #include <uno/lbnames.h>
28 /** */ //for docpp
29 namespace com
31 /** */ //for docpp
32 namespace sun
34 /** */ //for docpp
35 namespace star
37 /** */ //for docpp
38 namespace uno
41 /** C++ wrapper for binary C uno_Environment.
43 @see uno_Environment
45 class Environment
47 /** binary C uno_Environment
49 uno_Environment * _pEnv;
51 public:
52 /** Returns the current Environment.
54 @param typeName the optional type of the Environment, falls back to "uno" in case being empty,
55 respectively to current C++ Environment.
56 @since UDK 3.2.7
58 inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(CPPU_CURRENT_LANGUAGE_BINDING_NAME));
60 /// @cond INTERNAL
61 // these are here to force memory de/allocation to sal lib.
62 inline static void * SAL_CALL operator new ( size_t nSize )
63 { return ::rtl_allocateMemory( nSize ); }
64 inline static void SAL_CALL operator delete ( void * pMem )
65 { ::rtl_freeMemory( pMem ); }
66 inline static void * SAL_CALL operator new ( size_t, void * pMem )
67 { return pMem; }
68 inline static void SAL_CALL operator delete ( void *, void * )
70 /// @endcond
72 /** Constructor: acquires given environment
74 @param pEnv environment
76 inline Environment( uno_Environment * pEnv = 0 );
78 /** Gets a specific environment. If the specified environment does not exist, then a default one
79 is created and registered.
81 @param envDcp descriptor of the environment
82 @param pContext context pointer
84 inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL );
87 /** Copy constructor: acquires given environment
89 @param rEnv another environment
91 inline Environment( const Environment & rEnv );
93 /** Destructor: releases a set environment.
95 inline ~Environment();
97 /** Sets a given environment, i.e. acquires given one and releases a set one.
99 @param pEnv another environment
100 @return this environment
102 inline Environment & SAL_CALL operator = ( uno_Environment * pEnv );
103 /** Sets a given environment, i.e. acquires given one and releases a set one.
105 @param rEnv another environment
106 @return this environment
108 inline Environment & SAL_CALL operator = ( const Environment & rEnv )
109 { return operator = ( rEnv._pEnv ); }
111 /** Provides UNacquired pointer to the set C environment.
113 @return UNacquired pointer to the C environment struct
115 inline uno_Environment * SAL_CALL get() const
116 { return _pEnv; }
118 /** Gets type name of set environment.
120 @return type name of set environment
122 inline ::rtl::OUString SAL_CALL getTypeName() const
123 { return _pEnv->pTypeName; }
125 /** Gets free context pointer of set environment.
127 @return free context pointer of set environment
129 inline void * SAL_CALL getContext() const
130 { return _pEnv->pContext; }
132 /** Tests if a environment is set.
134 @return true, if a environment is set, false otherwise
136 inline bool SAL_CALL is() const
137 { return (_pEnv != 0); }
139 /** Releases a set environment.
141 inline void SAL_CALL clear();
143 /** Invoke the passed function in this environment.
145 @param pCallee the function to call
146 @param pParam the parameter pointer to be passed to the function
147 @since UDK 3.2.7
149 inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const;
151 /** Invoke the passed function in this environment.
153 @param pCallee the function to call
154 @param ... the parameters to be passed to the function
155 @since UDK 3.2.7
157 inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const;
159 /** Enter this environment explicitly.
161 @since UDK 3.2.7
163 inline void SAL_CALL enter() const;
165 /** Checks, if it is valid to currently call objects
166 belonging to this environment.
168 @since UDK 3.2.7
170 inline int SAL_CALL isValid(rtl::OUString * pReason) const;
173 inline Environment::Environment( uno_Environment * pEnv )
174 : _pEnv( pEnv )
176 if (_pEnv)
177 (*_pEnv->acquire)( _pEnv );
180 inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext )
181 : _pEnv(NULL)
183 uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext);
186 inline Environment::Environment( const Environment & rEnv )
187 : _pEnv( rEnv._pEnv )
189 if (_pEnv)
190 (*_pEnv->acquire)( _pEnv );
193 inline Environment::~Environment()
195 if (_pEnv)
196 (*_pEnv->release)( _pEnv );
199 inline void Environment::clear()
201 if (_pEnv)
203 (*_pEnv->release)( _pEnv );
204 _pEnv = 0;
208 inline Environment & Environment::operator = ( uno_Environment * pEnv )
210 if (pEnv != _pEnv)
212 if (pEnv)
213 (*pEnv->acquire)( pEnv );
214 if (_pEnv)
215 (*_pEnv->release)( _pEnv );
216 _pEnv = pEnv;
218 return *this;
221 inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const
223 if (_pEnv)
224 uno_Environment_invoke_v(_pEnv, pCallee, pParam);
227 inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const
229 if (_pEnv)
231 va_list param;
233 va_start(param, pCallee);
234 uno_Environment_invoke_v(_pEnv, pCallee, &param);
235 va_end(param);
240 inline void SAL_CALL Environment::enter() const
242 uno_Environment_enter(_pEnv);
245 inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const
247 return uno_Environment_isValid(_pEnv, &pReason->pData);
250 inline Environment Environment::getCurrent(rtl::OUString const & typeName)
252 Environment environment;
254 uno_Environment * pEnv = NULL;
255 uno_getCurrentEnvironment(&pEnv, typeName.pData);
256 environment = pEnv;
257 if (pEnv)
258 pEnv->release(pEnv);
260 return environment;
268 #endif
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */