Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / cppu / inc / uno / current_context.hxx
blobf1326e8108c3f9d51ad89726e2b857bff115fc54
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_CURRENT_CONTEXT_HXX_
29 #define _UNO_CURRENT_CONTEXT_HXX_
31 #include <uno/current_context.h>
33 #include <com/sun/star/uno/XCurrentContext.hpp>
36 namespace com
38 namespace sun
40 namespace star
42 namespace uno
45 /** Getting the current context.
46 @attention
47 Don't spread the returned interface around to other threads. Every thread has its own
48 current context.
50 @return current context or null ref, if none is set
52 inline Reference< XCurrentContext > SAL_CALL getCurrentContext()
53 SAL_THROW(())
55 Reference< XCurrentContext > xRet;
56 ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
57 ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 );
58 return xRet;
60 /** Setting the current context.
62 @param xContext current context to be set
63 @return true, if context has been successfully set
65 inline bool SAL_CALL setCurrentContext(
66 Reference< XCurrentContext > const & xContext )
67 SAL_THROW(())
69 ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
70 return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False);
73 /** Objects of this class are used for applying a current context until they are destructed, i.e.
74 the ctor of this class saves the previous and sets the given context while the dtor restores
75 the previous one upon destruction.
77 class ContextLayer
79 /** this C++ environment type name.
81 ::rtl::OUString m_aEnvTypeName;
82 /** previous context
84 Reference< XCurrentContext > m_xPreviousContext;
86 public:
87 /** Constructor: Saves the previous context and sets the new (given) one.
89 @param xNewContext new context to be set
91 inline ContextLayer(
92 Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() )
93 SAL_THROW(());
94 /** Destructor: restores the previous context.
96 inline ~ContextLayer() SAL_THROW(());
98 /** Gets the previously set context.
100 @return the previously set context
102 inline Reference< XCurrentContext > SAL_CALL getPreviousContext() const
103 SAL_THROW(())
104 { return m_xPreviousContext; }
106 //__________________________________________________________________________________________________
107 inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext )
108 SAL_THROW(())
109 : m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )
111 ::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 );
112 ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 );
114 //__________________________________________________________________________________________________
115 inline ContextLayer::~ContextLayer()
116 SAL_THROW(())
118 ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 );
126 #endif
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */