LibreOffice LibreOffice 6.4 SDK C/C++ API Reference

current_context.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #ifndef INCLUDED_UNO_CURRENT_CONTEXT_HXX
20 #define INCLUDED_UNO_CURRENT_CONTEXT_HXX
21
22 #include "sal/config.h"
23
24 #include <cstddef>
25
26 #include "uno/current_context.h"
27 #include "uno/lbnames.h"
28
29 #include "com/sun/star/uno/XCurrentContext.hpp"
30
31
32 namespace com
33 {
34 namespace sun
35 {
36 namespace star
37 {
38 namespace uno
39 {
40
48 inline Reference< XCurrentContext > SAL_CALL getCurrentContext()
49 {
50 Reference< XCurrentContext > xRet;
51 ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
52 ::uno_getCurrentContext( reinterpret_cast<void **>(&xRet), aEnvTypeName.pData, NULL );
53 return xRet;
54 }
60 inline bool SAL_CALL setCurrentContext(
61 Reference< XCurrentContext > const & xContext )
62 {
63 ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
64 return ::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, NULL );
65 }
66
71 class ContextLayer
72 {
75 ::rtl::OUString m_aEnvTypeName;
78 Reference< XCurrentContext > m_xPreviousContext;
79
80 public:
85 inline ContextLayer(
86 Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() );
89 inline ~ContextLayer();
90
95 Reference< XCurrentContext > SAL_CALL getPreviousContext() const
96 { return m_xPreviousContext; }
97 };
98
99 inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext )
100 : m_aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME )
101 {
102 ::uno_getCurrentContext( reinterpret_cast<void **>(&m_xPreviousContext), m_aEnvTypeName.pData, NULL );
103 ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, NULL );
104 }
105
106 inline ContextLayer::~ContextLayer()
107 {
108 ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, NULL );
109 }
110
111 }
112 }
113 }
114 }
115
116 #endif
117
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno_getCurrentContext
CPPU_DLLPUBLIC sal_Bool uno_getCurrentContext(void **ppCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Gets the current task's context.
com::sun::star::uno::Reference::get
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:444
com::sun::star::uno::ContextLayer
Objects of this class are used for applying a current context until they are destructed,...
Definition: current_context.hxx:71
com::sun::star::uno::ContextLayer::~ContextLayer
~ContextLayer()
Destructor: restores the previous context.
Definition: current_context.hxx:106
uno_setCurrentContext
CPPU_DLLPUBLIC sal_Bool uno_setCurrentContext(void *pCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Sets the current task's context.
current_context.h
lbnames.h
com
Definition: types.h:377
com::sun::star::uno::Reference< XCurrentContext >
com::sun::star::uno::setCurrentContext
bool setCurrentContext(Reference< XCurrentContext > const &xContext)
Setting the current context.
Definition: current_context.hxx:60
config.h
com::sun::star::uno::ContextLayer::ContextLayer
ContextLayer(Reference< XCurrentContext > const &xNewContext=Reference< XCurrentContext >())
Constructor: Saves the previous context and sets the new (given) one.
Definition: current_context.hxx:99
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:126
com::sun::star::uno::getCurrentContext
Reference< XCurrentContext > getCurrentContext()
Getting the current context.
Definition: current_context.hxx:48
com::sun::star::uno::ContextLayer::getPreviousContext
Reference< XCurrentContext > getPreviousContext() const
Gets the previously set context.
Definition: current_context.hxx:95