xref: /trunk/main/cppu/inc/cppu/Map.hxx (revision c059a6bf)
1c6ed87c9SAndrew Rist /**************************************************************
2*c059a6bfSmseidel  *
3c6ed87c9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c6ed87c9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c6ed87c9SAndrew Rist  * distributed with this work for additional information
6c6ed87c9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c6ed87c9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c6ed87c9SAndrew Rist  * "License"); you may not use this file except in compliance
9c6ed87c9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c059a6bfSmseidel  *
11c6ed87c9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c059a6bfSmseidel  *
13c6ed87c9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c6ed87c9SAndrew Rist  * software distributed under the License is distributed on an
15c6ed87c9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c6ed87c9SAndrew Rist  * KIND, either express or implied.  See the License for the
17c6ed87c9SAndrew Rist  * specific language governing permissions and limitations
18c6ed87c9SAndrew Rist  * under the License.
19*c059a6bfSmseidel  *
20c6ed87c9SAndrew Rist  *************************************************************/
21c6ed87c9SAndrew Rist 
22c6ed87c9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_cppu_Map_hxx
25cdf0e10cSrcweir #define INCLUDED_cppu_Map_hxx
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <uno/mapping.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace cssu = com::sun::star::uno;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace cppu
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     /** Helpers for mapping objects relative to the current environment.
35*c059a6bfSmseidel         (https://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Map_Helpers)
36cdf0e10cSrcweir     */
37cdf0e10cSrcweir 
38cdf0e10cSrcweir     /** Maps an object from the current to an outer Environment, returns mapped object.
39cdf0e10cSrcweir 
40cdf0e10cSrcweir         @param  pT        the object to be mapped
41cdf0e10cSrcweir         @param  outerEnv  the target environment
42cdf0e10cSrcweir         @return           the mapped object
43cdf0e10cSrcweir         @since UDK 3.2.7
44cdf0e10cSrcweir      */
mapOut(T * pT,cssu::Environment const & outerEnv)45cdf0e10cSrcweir 	template<class T> inline T * mapOut(T * pT, cssu::Environment const & outerEnv)
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 		cssu::Mapping curr2outer(cssu::Environment::getCurrent(), outerEnv);
48*c059a6bfSmseidel 
49cdf0e10cSrcweir 		return reinterpret_cast<T *>(curr2outer.mapInterface(pT, getCppuType((cssu::Reference<T> *)NULL)));
50cdf0e10cSrcweir 	}
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /** Maps an object from an outer Environment to the current, returns mapped object.
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         @param  pT        the object to be mapped
56cdf0e10cSrcweir         @param  outerEnv  the source environment
57cdf0e10cSrcweir         @return           the mapped object
58cdf0e10cSrcweir         @since UDK 3.2.7
59cdf0e10cSrcweir      */
mapIn(T * pT,cssu::Environment const & outerEnv)60cdf0e10cSrcweir 	template<class T> inline T * mapIn(T * pT, cssu::Environment const & outerEnv)
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		cssu::Mapping outer2curr(outerEnv, cssu::Environment::getCurrent());
63*c059a6bfSmseidel 
64cdf0e10cSrcweir 		return reinterpret_cast<T *>(outer2curr.mapInterface(pT, getCppuType((cssu::Reference<T> *)NULL)));
65cdf0e10cSrcweir 	}
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /** Maps an any from the current to an outer Environment, fills passed any.
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         @param  any       the any to be mapped
71cdf0e10cSrcweir         @param  res       the target any
72cdf0e10cSrcweir         @param  outerEnv  the target environment
73cdf0e10cSrcweir         @since UDK 3.2.7
74cdf0e10cSrcweir      */
75cdf0e10cSrcweir     // Problem: any gets assigned to something, acquire/releases may be called in wrong env.
mapOutAny(cssu::Any const & any,cssu::Any * res,cssu::Environment const & outerEnv)76cdf0e10cSrcweir 	inline void mapOutAny(cssu::Any const & any, cssu::Any * res, cssu::Environment const & outerEnv)
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 		cssu::Mapping curr2outer(cssu::Environment::getCurrent(), outerEnv);
79*c059a6bfSmseidel 
80cdf0e10cSrcweir 		uno_any_destruct(res, (uno_ReleaseFunc)cssu::cpp_release);
81cdf0e10cSrcweir 		uno_type_any_constructAndConvert(
82cdf0e10cSrcweir 			res,
83cdf0e10cSrcweir 			const_cast<void *>(any.getValue()),
84cdf0e10cSrcweir 			any.getValueTypeRef(),
85cdf0e10cSrcweir 			curr2outer.get());
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /** Maps an any from an outer Environment to the current, fills passed any.
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         @param  any       the any to be mapped
92cdf0e10cSrcweir         @param  res       the target any
93cdf0e10cSrcweir         @param  outerEnv  the source environment
94cdf0e10cSrcweir         @since UDK 3.2.7
95cdf0e10cSrcweir      */
mapInAny(cssu::Any const & any,cssu::Any * res,cssu::Environment const & outerEnv)96cdf0e10cSrcweir 	inline void mapInAny(cssu::Any const & any, cssu::Any * res, cssu::Environment const & outerEnv)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		cssu::Mapping outer2curr(outerEnv, cssu::Environment::getCurrent());
99*c059a6bfSmseidel 
100cdf0e10cSrcweir 		uno_any_destruct(res, (uno_ReleaseFunc)cssu::cpp_release);
101cdf0e10cSrcweir 		uno_type_any_constructAndConvert(
102cdf0e10cSrcweir 			res,
103cdf0e10cSrcweir 			const_cast<void *>(any.getValue()),
104cdf0e10cSrcweir 			any.getValueTypeRef(),
105cdf0e10cSrcweir 			outer2curr.get());
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir #endif
110