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