/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* * This file is part of LibreOffice published API.
*/ #ifndef INCLUDED_COM_SUN_STAR_UNO_ANY_HXX #define INCLUDED_COM_SUN_STAR_UNO_ANY_HXX
inline Any & Any::operator = ( const Any & rAny )
{ if (this != &rAny)
{
::uno_type_any_assign( this, rAny.pData, rAny.pType,
cpp_acquire, cpp_release );
} return *this;
}
#ifdefined LIBO_INTERNAL_ONLY
#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
Any::Any(Any && other) noexcept {
uno_any_construct(this, nullptr, nullptr, &cpp_acquire);
std::swap(other.pType, pType);
std::swap(other.pData, pData);
std::swap(other.pReserved, pReserved); if (pData == &other.pReserved) {
pData = &pReserved;
} // This leaves other.pData (where "other" is now VOID) dangling to somewhere (cf. // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData -> // _assignData takes a null pSource to mean "construct a default value").
} #endif
template<> inlinebool SAL_CALL operator >>= ( const Any & rAny, Type & value )
{ if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
{
value = * static_cast< const Type * >( rAny.pData ); returntrue;
} returnfalse;
}
template<> inlinebool SAL_CALL operator == ( const Any & rAny, const Type & value )
{ return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
value.equals( * static_cast< const Type * >( rAny.pData ) ));
} // any
#ifdefined LIBO_INTERNAL_ONLY template<> bool SAL_CALL operator >>=(Any const &, Any &) = delete; #else template<> inlinebool SAL_CALL operator >>= ( const Any & rAny, Any & value )
{ if (&rAny != &value)
{
::uno_type_any_assign(
&value, rAny.pData, rAny.pType,
cpp_acquire, cpp_release );
} returntrue;
} #endif // interface
template<> inlinebool SAL_CALL operator == ( const Any & rAny, const BaseReference & value )
{ if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
{ returnstatic_cast< const BaseReference * >( rAny.pData )->operator == ( value );
} returnfalse;
}
// operator to compare to an any.
template< class C > inlinebool SAL_CALL operator == ( const Any & rAny, const C & value )
{ const Type & rType = ::cppu::getTypeFavourUnsigned(&value); return ::uno_type_equalData(
rAny.pData, rAny.pType, const_cast< C * >( &value ), rType.getTypeLibType(),
cpp_queryInterface, cpp_release );
} // operator to compare to an any. may use specialized operators ==.
template< class C > inlinebool SAL_CALL operator != ( const Any & rAny, const C & value )
{ return (! operator == ( rAny, value ));
}
template <typename T>
T Any::get() const
{
T value = T(); if (! (*this >>= value)) { throw RuntimeException(
::rtl::OUString(
cppu_Any_extraction_failure_msg( this,
::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
SAL_NO_ACQUIRE ) );
} return value;
}
#ifdefined LIBO_INTERNAL_ONLY template<> Any Any::get() const = delete; #endif
/** Support for Any in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO macros, for example).
@since LibreOffice 4.2
*/ template<typename charT, typename traits> inline std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &o, Any const &any) {
o << "<Any: (" << any.getValueTypeName() << ')'; switch(any.pType->eTypeClass) { case typelib_TypeClass_VOID: break; case typelib_TypeClass_BOOLEAN:
o << ' ' << any.get<bool>(); break; case typelib_TypeClass_BYTE: case typelib_TypeClass_SHORT: case typelib_TypeClass_LONG: case typelib_TypeClass_HYPER:
o << ' ' << any.get<sal_Int64>(); break; case typelib_TypeClass_UNSIGNED_SHORT: case typelib_TypeClass_UNSIGNED_LONG: case typelib_TypeClass_UNSIGNED_HYPER:
o << ' ' << any.get<sal_uInt64>(); break; case typelib_TypeClass_FLOAT: case typelib_TypeClass_DOUBLE:
o << ' ' << any.get<double>(); break; case typelib_TypeClass_CHAR: {
std::ios_base::fmtflags flgs = o.setf(
std::ios_base::hex, std::ios_base::basefield);
charT fill = o.fill('0');
o << " U+" << std::setw(4)
<< unsigned(*static_cast<sal_Unicode const *>(any.getValue()));
o.setf(flgs);
o.fill(fill); break;
} case typelib_TypeClass_STRING:
o << ' ' << any.get<rtl::OUString>(); break; case typelib_TypeClass_TYPE:
o << ' ' << any.get<css::uno::Type>().getTypeName(); break; case typelib_TypeClass_SEQUENCE:
o << " len "
<< ((*static_cast<uno_Sequence * const *>(any.getValue()))->
nElements); break; case typelib_TypeClass_ENUM:
o << ' ' << *static_cast<sal_Int32 const *>(any.getValue()); break; case typelib_TypeClass_STRUCT: case typelib_TypeClass_EXCEPTION:
o << ' ' << any.getValue(); break; case typelib_TypeClass_INTERFACE:
o << ' ' << *static_cast<void * const *>(any.getValue()); break; default:
assert(false); // this cannot happen break;
}
o << '>'; return o;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.