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 #if ! defined(INCLUDED_COMPHELPER_OPTIONAL_HXX) 24 #define INCLUDED_COMPHELPER_OPTIONAL_HXX 25 26 #if ! defined(_COM_SUN_STAR_BEANS_OPTIONAL_HPP_) 27 #include "com/sun/star/beans/Optional.hpp" 28 #endif 29 #include "boost/optional.hpp" 30 31 namespace comphelper { 32 33 /// Object generators for boost::optional<T>, beans::Optional<T>: 34 35 template <typename T> make_optional(T const & v)36inline ::boost::optional<T> make_optional( T const& v ) 37 { 38 return ::boost::optional<T>(v); 39 } 40 41 template <typename T> make_optional(::com::sun::star::beans::Optional<T> const & o)42inline ::boost::optional<T> make_optional( 43 ::com::sun::star::beans::Optional<T> const& o ) 44 { 45 if (o.IsPresent) 46 return ::boost::optional<T>(o.Value); 47 else 48 return ::boost::optional<T>(); 49 } 50 51 template <typename T> makeOptional(T const & v)52inline ::com::sun::star::beans::Optional<T> makeOptional( T const& v ) 53 { 54 // CPPU_IS_CPP_MAPPING_OF_NON_VOID_UNO_TYPE(T); 55 return ::com::sun::star::beans::Optional<T>(true, v); 56 } 57 58 template <typename T> makeOptional(::boost::optional<T> const & o)59inline ::com::sun::star::beans::Optional<T> makeOptional( 60 ::boost::optional<T> const& o ) 61 { 62 // CPPU_IS_CPP_MAPPING_OF_NON_VOID_UNO_TYPE(T); 63 if (o) 64 return ::com::sun::star::beans::Optional<T>(true, *o); 65 else 66 return ::com::sun::star::beans::Optional<T>(); 67 } 68 makeOptional(::boost::optional<bool> const & o)69inline ::com::sun::star::beans::Optional<sal_Bool> makeOptional( 70 ::boost::optional<bool> const& o ) 71 { 72 if (o) 73 return ::com::sun::star::beans::Optional<sal_Bool>(true, *o); 74 else 75 return ::com::sun::star::beans::Optional<sal_Bool>(); 76 } 77 makeOptional(bool v)78inline ::com::sun::star::beans::Optional<sal_Bool> makeOptional( bool v ) 79 { 80 return ::com::sun::star::beans::Optional<sal_Bool>(true, v); 81 } 82 83 } // namespace comphelper 84 85 #endif // ! defined(INCLUDED_COMPHELPER_OPTIONAL_HXX) 86 87