1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_cppu_Map_hxx
21 #define INCLUDED_cppu_Map_hxx
23 #include <uno/mapping.hxx>
26 namespace cssu
= com::sun::star::uno
;
30 /** Helpers for mapping objects relative to the current environment.
31 (http://wiki.services.openoffice.org/wiki/Uno/Cpp/Spec/Map_Helpers)
34 /** Maps an object from the current to an outer Environment, returns mapped object.
36 @param pT the object to be mapped
37 @param outerEnv the target environment
38 @return the mapped object
41 template<class T
> inline T
* mapOut(T
* pT
, cssu::Environment
const & outerEnv
)
43 cssu::Mapping
curr2outer(cssu::Environment::getCurrent(), outerEnv
);
45 return reinterpret_cast<T
*>(curr2outer
.mapInterface(pT
, getCppuType((cssu::Reference
<T
> *)NULL
)));
49 /** Maps an object from an outer Environment to the current, returns mapped object.
51 @param pT the object to be mapped
52 @param outerEnv the source environment
53 @return the mapped object
56 template<class T
> inline T
* mapIn(T
* pT
, cssu::Environment
const & outerEnv
)
58 cssu::Mapping
outer2curr(outerEnv
, cssu::Environment::getCurrent());
60 return reinterpret_cast<T
*>(outer2curr
.mapInterface(pT
, getCppuType((cssu::Reference
<T
> *)NULL
)));
64 /** Maps an any from the current to an outer Environment, fills passed any.
66 @param any the any to be mapped
67 @param res the target any
68 @param outerEnv the target environment
71 // Problem: any gets assigned to something, acquire/releases may be called in wrong env.
72 inline void mapOutAny(cssu::Any
const & any
, cssu::Any
* res
, cssu::Environment
const & outerEnv
)
74 cssu::Mapping
curr2outer(cssu::Environment::getCurrent(), outerEnv
);
76 uno_any_destruct(res
, (uno_ReleaseFunc
)cssu::cpp_release
);
77 uno_type_any_constructAndConvert(
79 const_cast<void *>(any
.getValue()),
80 any
.getValueTypeRef(),
85 /** Maps an any from an outer Environment to the current, fills passed any.
87 @param any the any to be mapped
88 @param res the target any
89 @param outerEnv the source environment
92 inline void mapInAny(cssu::Any
const & any
, cssu::Any
* res
, cssu::Environment
const & outerEnv
)
94 cssu::Mapping
outer2curr(outerEnv
, cssu::Environment::getCurrent());
96 uno_any_destruct(res
, (uno_ReleaseFunc
)cssu::cpp_release
);
97 uno_type_any_constructAndConvert(
99 const_cast<void *>(any
.getValue()),
100 any
.getValueTypeRef(),
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */