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 #include "sal/config.h"
25
26 #include "osl/diagnose.h"
27 #include "typelib/typeclass.h"
28 #include "typelib/typedescription.hxx"
29 #include "uno/any2.h"
30
31 #include "binaryany.hxx"
32
33 namespace binaryurp {
34
35 namespace {
36
37 namespace css = com::sun::star;
38
39 }
40
BinaryAny()41 BinaryAny::BinaryAny() throw () {
42 uno_any_construct(&data_, 0, 0, 0);
43 }
44
BinaryAny(css::uno::TypeDescription const & type,void * value)45 BinaryAny::BinaryAny(css::uno::TypeDescription const & type, void * value)
46 throw ()
47 {
48 OSL_ASSERT(type.is());
49 uno_any_construct(&data_, value, type.get(), 0);
50 }
51
BinaryAny(uno_Any const & raw)52 BinaryAny::BinaryAny(uno_Any const & raw) throw () {
53 OSL_ASSERT(raw.pType != 0);
54 data_.pType = raw.pType;
55 typelib_typedescriptionreference_acquire(data_.pType);
56 data_.pData = raw.pData == &raw.pReserved ? &data_.pReserved : raw.pData;
57 data_.pReserved = raw.pReserved;
58 }
59
BinaryAny(BinaryAny const & other)60 BinaryAny::BinaryAny(BinaryAny const & other) throw () {
61 uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, 0);
62 }
63
~BinaryAny()64 BinaryAny::~BinaryAny() throw () {
65 uno_any_destruct(&data_, 0);
66 }
67
operator =(BinaryAny const & other)68 BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () {
69 if (&other != this) {
70 uno_type_any_assign(&data_, other.data_.pData, other.data_.pType, 0, 0);
71 }
72 return *this;
73 }
74
get()75 uno_Any * BinaryAny::get() throw () {
76 return &data_;
77 }
78
getType() const79 css::uno::TypeDescription BinaryAny::getType() const throw () {
80 return css::uno::TypeDescription(data_.pType);
81 }
82
getValue(css::uno::TypeDescription const & type) const83 void * BinaryAny::getValue(css::uno::TypeDescription const & type) const
84 throw ()
85 {
86 OSL_ASSERT(
87 type.is() &&
88 (type.get()->eTypeClass == typelib_TypeClass_ANY ||
89 type.equals(css::uno::TypeDescription(data_.pType))));
90 return type.get()->eTypeClass == typelib_TypeClass_ANY
91 ? &data_ : data_.pData;
92 }
93
94 }
95