1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2011 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "sal/config.h" 29 30 #include "osl/diagnose.h" 31 #include "typelib/typeclass.h" 32 #include "typelib/typedescription.hxx" 33 #include "uno/any2.h" 34 35 #include "binaryany.hxx" 36 37 namespace binaryurp { 38 39 namespace { 40 41 namespace css = com::sun::star; 42 43 } 44 45 BinaryAny::BinaryAny() throw () { 46 uno_any_construct(&data_, 0, 0, 0); 47 } 48 49 BinaryAny::BinaryAny(css::uno::TypeDescription const & type, void * value) 50 throw () 51 { 52 OSL_ASSERT(type.is()); 53 uno_any_construct(&data_, value, type.get(), 0); 54 } 55 56 BinaryAny::BinaryAny(uno_Any const & raw) throw () { 57 OSL_ASSERT(raw.pType != 0); 58 data_.pType = raw.pType; 59 typelib_typedescriptionreference_acquire(data_.pType); 60 data_.pData = raw.pData == &raw.pReserved ? &data_.pReserved : raw.pData; 61 data_.pReserved = raw.pReserved; 62 } 63 64 BinaryAny::BinaryAny(BinaryAny const & other) throw () { 65 uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, 0); 66 } 67 68 BinaryAny::~BinaryAny() throw () { 69 uno_any_destruct(&data_, 0); 70 } 71 72 BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () { 73 if (&other != this) { 74 uno_type_any_assign(&data_, other.data_.pData, other.data_.pType, 0, 0); 75 } 76 return *this; 77 } 78 79 uno_Any * BinaryAny::get() throw () { 80 return &data_; 81 } 82 83 css::uno::TypeDescription BinaryAny::getType() const throw () { 84 return css::uno::TypeDescription(data_.pType); 85 } 86 87 void * BinaryAny::getValue(css::uno::TypeDescription const & type) const 88 throw () 89 { 90 OSL_ASSERT( 91 type.is() && 92 (type.get()->eTypeClass == typelib_TypeClass_ANY || 93 type.equals(css::uno::TypeDescription(data_.pType)))); 94 return type.get()->eTypeClass == typelib_TypeClass_ANY 95 ? &data_ : data_.pData; 96 } 97 98 } 99