update dev300-m58
[ooovba.git] / cppu / inc / uno / current_context.hxx
blob5531d7f1afdec026c2dc4ff302aeecd9058e8e35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: current_context.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _UNO_CURRENT_CONTEXT_HXX_
31 #define _UNO_CURRENT_CONTEXT_HXX_
33 #include <uno/current_context.h>
35 #include <com/sun/star/uno/XCurrentContext.hpp>
38 namespace com
40 namespace sun
42 namespace star
44 namespace uno
47 /** Getting the current context.
48 @attention
49 Don't spread the returned interface around to other threads. Every thread has its own
50 current context.
52 @return current context or null ref, if none is set
54 inline Reference< XCurrentContext > SAL_CALL getCurrentContext()
55 SAL_THROW( () )
57 Reference< XCurrentContext > xRet;
58 ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
59 ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 );
60 return xRet;
62 /** Setting the current context.
64 @param xContext current context to be set
65 @return true, if context has been successfully set
67 inline bool SAL_CALL setCurrentContext(
68 Reference< XCurrentContext > const & xContext )
69 SAL_THROW( () )
71 ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
72 return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False);
75 /** Objects of this class are used for applying a current context until they are destructed, i.e.
76 the ctor of this class saves the previous and sets the given context while the dtor restores
77 the previous one upon destruction.
79 class ContextLayer
81 /** this C++ environment type name.
82 @internal
84 ::rtl::OUString m_aEnvTypeName;
85 /** previous context
86 @internal
88 Reference< XCurrentContext > m_xPreviousContext;
90 public:
91 /** Constructor: Saves the previous context and sets the new (given) one.
93 @param xNewContext new context to be set
95 inline ContextLayer(
96 Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() )
97 SAL_THROW( () );
98 /** Destructor: restores the previous context.
100 inline ~ContextLayer() SAL_THROW( () );
102 /** Gets the previously set context.
104 @return the previously set context
106 inline Reference< XCurrentContext > SAL_CALL getPreviousContext() const
107 SAL_THROW( () )
108 { return m_xPreviousContext; }
110 //__________________________________________________________________________________________________
111 inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext )
112 SAL_THROW( () )
113 : m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )
115 ::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 );
116 ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 );
118 //__________________________________________________________________________________________________
119 inline ContextLayer::~ContextLayer()
120 SAL_THROW( () )
122 ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 );
130 #endif