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  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef INCLUDED_cppu_EnvGuards_hxx
00030 #define INCLUDED_cppu_EnvGuards_hxx
00031 
00032 #include "uno/environment.hxx"
00033 #include "uno/mapping.hxx"
00034 
00035 
00036 namespace cssuno = com::sun::star::uno;
00037 
00038 
00039 namespace cppu
00040 {
00048     class EnvGuard
00049     {
00050         cssuno::Environment m_env;
00051 
00052     public:
00053         explicit EnvGuard(cssuno::Environment const & env)
00054         {
00055             if (env.is())
00056             {
00057                 m_env = cssuno::Environment::getCurrent();
00058                 env.enter();
00059             }
00060         }
00061 
00062         ~EnvGuard()
00063         {
00064             m_env.enter();
00065         }
00066 
00071         sal_Bool SAL_CALL is() const SAL_THROW(())
00072         {
00073             return m_env.is();
00074         }
00075 
00079         void clear()
00080         {
00081             if (m_env.is())
00082             {
00083                 m_env.enter();
00084                 m_env.clear();
00085             }
00086         }
00087     };
00088 
00096     class AntiEnvGuard
00097     {
00098         cssuno::Environment m_env;
00099 
00100     public:
00101         explicit AntiEnvGuard()
00102             : m_env(cssuno::Environment::getCurrent())
00103         {
00104             uno_Environment_enter(NULL);
00105         }
00106 
00107         ~AntiEnvGuard()
00108         {
00109             m_env.enter();
00110         }
00111     };
00112 }
00113 
00114 #endif
00115 
00116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines