UDK 3.2.7 C/C++ API Reference

cppu/EnvGuards.hxx

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 #ifndef INCLUDED_cppu_EnvGuards_hxx
00021 #define INCLUDED_cppu_EnvGuards_hxx
00022 
00023 #include "uno/environment.hxx"
00024 #include "uno/mapping.hxx"
00025 
00026 
00027 namespace cssuno = com::sun::star::uno;
00028 
00029 
00030 namespace cppu
00031 {
00039     class EnvGuard
00040     {
00041         cssuno::Environment m_env;
00042 
00043     public:
00044         explicit EnvGuard(cssuno::Environment const & env)
00045         {
00046             if (env.is())
00047             {
00048                 m_env = cssuno::Environment::getCurrent();
00049                 env.enter();
00050             }
00051         }
00052 
00053         ~EnvGuard()
00054         {
00055             m_env.enter();
00056         }
00057 
00062         sal_Bool SAL_CALL is() const SAL_THROW(())
00063         {
00064             return m_env.is();
00065         }
00066 
00070         void clear()
00071         {
00072             if (m_env.is())
00073             {
00074                 m_env.enter();
00075                 m_env.clear();
00076             }
00077         }
00078     };
00079 
00087     class AntiEnvGuard
00088     {
00089         cssuno::Environment m_env;
00090 
00091     public:
00092         explicit AntiEnvGuard()
00093             : m_env(cssuno::Environment::getCurrent())
00094         {
00095             uno_Environment_enter(NULL);
00096         }
00097 
00098         ~AntiEnvGuard()
00099         {
00100             m_env.enter();
00101         }
00102     };
00103 }
00104 
00105 #endif
00106 
00107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines