LibreOffice Module binaryurp (master) 1
binaryany.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <cassert>
23#include <utility>
24
25#include <typelib/typeclass.h>
26#include <typelib/typedescription.hxx>
27#include <uno/any2.h>
28
29#include "binaryany.hxx"
30
31namespace binaryurp {
32
33namespace {
34
35// Cf. com::sun::star::uno::Any move ctor in
36// include/com/sun/star/uno/Any.hxx:
37void 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;
44 }
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").
49}
50
51}
52
54 uno_any_construct(&data_, nullptr, nullptr, nullptr);
55}
56
57BinaryAny::BinaryAny(css::uno::TypeDescription const & type, void * value)
58 noexcept
59{
60 assert(type.is());
61 uno_any_construct(&data_, value, type.get(), nullptr);
62}
63
64BinaryAny::BinaryAny(uno_Any const & raw) noexcept {
65 assert(raw.pType != nullptr);
66 data_.pType = raw.pType;
68 data_.pData = raw.pData == &raw.pReserved ? &data_.pReserved : raw.pData;
69 data_.pReserved = raw.pReserved;
70}
71
72BinaryAny::BinaryAny(BinaryAny const & other) noexcept {
73 uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, nullptr);
74}
75
76BinaryAny::BinaryAny(BinaryAny && other) noexcept {
77 moveInternals(other.data_, data_);
78}
79
81 uno_any_destruct(&data_, nullptr);
82}
83
84BinaryAny & BinaryAny::operator =(BinaryAny const & other) noexcept {
85 if (&other != this) {
86 uno_type_any_assign(&data_, other.data_.pData, other.data_.pType, nullptr, nullptr);
87 }
88 return *this;
89}
90
92 uno_any_destruct(&data_, nullptr);
93 moveInternals(other.data_, data_);
94 return *this;
95}
96
97css::uno::TypeDescription BinaryAny::getType() const noexcept {
98 return css::uno::TypeDescription(data_.pType);
99}
100
101void * BinaryAny::getValue(css::uno::TypeDescription const & type) const
102 noexcept
103{
104 assert(type.is());
105 assert(
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;
110}
111
112}
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SAL_CALL uno_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_type_any_assign(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_type_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
UBlockCode from
UBlockCode to
BinaryAny & operator=(BinaryAny const &other) noexcept
Definition: binaryany.cxx:84
com::sun::star::uno::TypeDescription getType() const noexcept
Definition: binaryany.cxx:97
BinaryAny() noexcept
Definition: binaryany.cxx:53
void * getValue(com::sun::star::uno::TypeDescription const &type) const noexcept
Definition: binaryany.cxx:101
~BinaryAny() noexcept
Definition: binaryany.cxx:80
struct _uno_Any uno_Any
void SAL_CALL typelib_typedescriptionreference_acquire(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
ResultType type