1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
25 #include <typelib/typeclass.h>
26 #include <typelib/typedescription.hxx>
29 #include "binaryany.hxx"
35 // Cf. com::sun::star::uno::Any move ctor in
36 // include/com/sun/star/uno/Any.hxx:
37 void moveInternals(uno_Any
& from
, uno_Any
& to
) {
38 uno_any_construct(&to
, nullptr, nullptr, nullptr);
39 std::swap(from
.pType
, to
.pType
);
40 std::swap(from
.pData
, to
.pData
);
41 std::swap(from
.pReserved
, to
.pReserved
);
42 if (to
.pData
== &from
.pReserved
) {
43 to
.pData
= &to
.pReserved
;
45 // This leaves to.pData (where "to" is now VOID) dangling to somewhere (cf.
46 // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is
47 // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData ->
48 // _assignData takes a null pSource to mean "construct a default value").
53 BinaryAny::BinaryAny() noexcept
{
54 uno_any_construct(&data_
, nullptr, nullptr, nullptr);
57 BinaryAny::BinaryAny(css::uno::TypeDescription
const & type
, void * value
)
61 uno_any_construct(&data_
, value
, type
.get(), nullptr);
64 BinaryAny::BinaryAny(uno_Any
const & raw
) noexcept
{
65 assert(raw
.pType
!= nullptr);
66 data_
.pType
= raw
.pType
;
67 typelib_typedescriptionreference_acquire(data_
.pType
);
68 data_
.pData
= raw
.pData
== &raw
.pReserved
? &data_
.pReserved
: raw
.pData
;
69 data_
.pReserved
= raw
.pReserved
;
72 BinaryAny::BinaryAny(BinaryAny
const & other
) noexcept
{
73 uno_type_any_construct(&data_
, other
.data_
.pData
, other
.data_
.pType
, nullptr);
76 BinaryAny::BinaryAny(BinaryAny
&& other
) noexcept
{
77 moveInternals(other
.data_
, data_
);
80 BinaryAny::~BinaryAny() noexcept
{
81 uno_any_destruct(&data_
, nullptr);
84 BinaryAny
& BinaryAny::operator =(BinaryAny
const & other
) noexcept
{
86 uno_type_any_assign(&data_
, other
.data_
.pData
, other
.data_
.pType
, nullptr, nullptr);
91 BinaryAny
& BinaryAny::operator =(BinaryAny
&& other
) noexcept
{
92 uno_any_destruct(&data_
, nullptr);
93 moveInternals(other
.data_
, data_
);
97 css::uno::TypeDescription
BinaryAny::getType() const noexcept
{
98 return css::uno::TypeDescription(data_
.pType
);
101 void * BinaryAny::getValue(css::uno::TypeDescription
const & type
) const
106 type
.get()->eTypeClass
== typelib_TypeClass_ANY
||
107 type
.equals(css::uno::TypeDescription(data_
.pType
)));
108 return type
.get()->eTypeClass
== typelib_TypeClass_ANY
109 ? &data_
: data_
.pData
;
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */