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