LibreOffice
LibreOffice 24.2 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 
20 /*
21  * This file is part of LibreOffice published API.
22  */
23 #ifndef INCLUDED_UNO_CURRENT_CONTEXT_HXX
24 #define INCLUDED_UNO_CURRENT_CONTEXT_HXX
25 
26 #include "sal/config.h"
27 
28 #include <cstddef>
29 
30 #include "uno/current_context.h"
31 #include "uno/lbnames.h"
32 
33 #include "com/sun/star/uno/XCurrentContext.hpp"
34 
35 
36 namespace com
37 {
38 namespace sun
39 {
40 namespace star
41 {
42 namespace uno
43 {
44 
53 {
55  ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
56  ::uno_getCurrentContext( reinterpret_cast<void **>(&xRet), aEnvTypeName.pData, NULL );
57  return xRet;
58 }
64 inline bool SAL_CALL setCurrentContext(
65  Reference< XCurrentContext > const & xContext )
66 {
67  ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
68  return ::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, NULL );
69 }
70 
76 {
79  ::rtl::OUString m_aEnvTypeName;
82  Reference< XCurrentContext > m_xPreviousContext;
83 
84 public:
89  inline ContextLayer(
93  inline ~ContextLayer();
94 
100  { return m_xPreviousContext; }
101 };
102 
104  : m_aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME )
105 {
106  ::uno_getCurrentContext( reinterpret_cast<void **>(&m_xPreviousContext), m_aEnvTypeName.pData, NULL );
107  ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, NULL );
108 }
109 
111 {
112  ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, NULL );
113 }
114 
115 }
116 }
117 }
118 }
119 
120 #endif
121 
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CPPU_DLLPUBLIC sal_Bool uno_getCurrentContext(void **ppCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Gets the current task&#39;s context.
Objects of this class are used for applying a current context until they are destructed, i.e.
Definition: current_context.hxx:75
CPPU_DLLPUBLIC sal_Bool uno_setCurrentContext(void *pCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Sets the current task&#39;s context.
Definition: types.h:359
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:403
~ContextLayer()
Destructor: restores the previous context.
Definition: current_context.hxx:110
bool setCurrentContext(Reference< XCurrentContext > const &xContext)
Setting the current context.
Definition: current_context.hxx:64
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:170
Reference< XCurrentContext > getCurrentContext()
Getting the current context.
Definition: current_context.hxx:52
ContextLayer(Reference< XCurrentContext > const &xNewContext=Reference< XCurrentContext >())
Constructor: Saves the previous context and sets the new (given) one.
Definition: current_context.hxx:103
Reference< XCurrentContext > getPreviousContext() const
Gets the previously set context.
Definition: current_context.hxx:99