1*37adc4f0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*37adc4f0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*37adc4f0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*37adc4f0SAndrew Rist * distributed with this work for additional information 6*37adc4f0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*37adc4f0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*37adc4f0SAndrew Rist * "License"); you may not use this file except in compliance 9*37adc4f0SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*37adc4f0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*37adc4f0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*37adc4f0SAndrew Rist * software distributed under the License is distributed on an 15*37adc4f0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*37adc4f0SAndrew Rist * KIND, either express or implied. See the License for the 17*37adc4f0SAndrew Rist * specific language governing permissions and limitations 18*37adc4f0SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*37adc4f0SAndrew Rist *************************************************************/ 21*37adc4f0SAndrew Rist 22*37adc4f0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "sal/config.h" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "osl/diagnose.h" 27cdf0e10cSrcweir #include "typelib/typeclass.h" 28cdf0e10cSrcweir #include "typelib/typedescription.hxx" 29cdf0e10cSrcweir #include "uno/any2.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "binaryany.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace binaryurp { 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace { 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace css = com::sun::star; 38cdf0e10cSrcweir 39cdf0e10cSrcweir } 40cdf0e10cSrcweir 41cdf0e10cSrcweir BinaryAny::BinaryAny() throw () { 42cdf0e10cSrcweir uno_any_construct(&data_, 0, 0, 0); 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir BinaryAny::BinaryAny(css::uno::TypeDescription const & type, void * value) 46cdf0e10cSrcweir throw () 47cdf0e10cSrcweir { 48cdf0e10cSrcweir OSL_ASSERT(type.is()); 49cdf0e10cSrcweir uno_any_construct(&data_, value, type.get(), 0); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir BinaryAny::BinaryAny(uno_Any const & raw) throw () { 53cdf0e10cSrcweir OSL_ASSERT(raw.pType != 0); 54cdf0e10cSrcweir data_.pType = raw.pType; 55cdf0e10cSrcweir typelib_typedescriptionreference_acquire(data_.pType); 56cdf0e10cSrcweir data_.pData = raw.pData == &raw.pReserved ? &data_.pReserved : raw.pData; 57cdf0e10cSrcweir data_.pReserved = raw.pReserved; 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir BinaryAny::BinaryAny(BinaryAny const & other) throw () { 61cdf0e10cSrcweir uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, 0); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir BinaryAny::~BinaryAny() throw () { 65cdf0e10cSrcweir uno_any_destruct(&data_, 0); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () { 69cdf0e10cSrcweir if (&other != this) { 70cdf0e10cSrcweir uno_type_any_assign(&data_, other.data_.pData, other.data_.pType, 0, 0); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir return *this; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir uno_Any * BinaryAny::get() throw () { 76cdf0e10cSrcweir return &data_; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir css::uno::TypeDescription BinaryAny::getType() const throw () { 80cdf0e10cSrcweir return css::uno::TypeDescription(data_.pType); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir void * BinaryAny::getValue(css::uno::TypeDescription const & type) const 84cdf0e10cSrcweir throw () 85cdf0e10cSrcweir { 86cdf0e10cSrcweir OSL_ASSERT( 87cdf0e10cSrcweir type.is() && 88cdf0e10cSrcweir (type.get()->eTypeClass == typelib_TypeClass_ANY || 89cdf0e10cSrcweir type.equals(css::uno::TypeDescription(data_.pType)))); 90cdf0e10cSrcweir return type.get()->eTypeClass == typelib_TypeClass_ANY 91cdf0e10cSrcweir ? &data_ : data_.pData; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir } 95