LibreOffice: com/sun/star/uno/Any.h Source File

LibreOffice LibreOffice 26.2 SDK C/C++ API Reference

Loading...
Searching...
No Matches
Any.h
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/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_COM_SUN_STAR_UNO_ANY_H
24#define INCLUDED_COM_SUN_STAR_UNO_ANY_H
25
26#include "sal/config.h"
27
28#include <cstddef>
29
30#include "rtl/ustring.hxx"
31#include "uno/any2.h"
32#include "typelib/typedescription.h"
33#include "cppu/unotype.hxx"
34#include "com/sun/star/uno/TypeClass.hdl"
35#include "rtl/alloc.h"
36
37#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
38#include <type_traits>
39#endif
40
41namespace com
42{
43namespace sun
44{
45namespace star
46{
47namespace uno
48{
49
50class Type;
51template<class interface_type> class Reference;
52
61 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
62{
63public:
65 // these are here to force memory de/allocation to sal lib.
66 static void * SAL_CALL operator new ( size_t nSize )
67 { return ::rtl_allocateMemory( nSize ); }
68 static void SAL_CALL operator delete ( void * pMem )
69 { ::rtl_freeMemory( pMem ); }
70 static void * SAL_CALL operator new ( size_t, void * pMem )
71 { return pMem; }
72 static void SAL_CALL operator delete ( void *, void * )
73 {}
75
78 inline Any();
79
84 template <typename T>
85#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
86 // Disallow things like
87 // Reference<XInterface> x(...);
88 // Any a(*x);
89 requires (!std::is_base_of_v<XInterface, T>)
90#endif
91 explicit inline Any( T const & value );
93 explicit inline Any( bool value );
94
95#if defined LIBO_INTERNAL_ONLY
96 template<typename T1, typename T2>
97 explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
98 template<typename T1, typename T2>
99 explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
100 template<std::size_t nBufSize> explicit inline Any(rtl::StringNumber<sal_Unicode, nBufSize> && value);
101 template<std::size_t nBufSize> explicit Any(rtl::StringNumber<sal_Unicode, nBufSize> const &) = delete;
102 template <std::size_t N> explicit inline Any(const rtl::OUStringLiteral<N>& value);
103#endif
104
109 inline Any( const Any & rAny );
110
116 inline Any( const void * pData_, const Type & rType );
117
123 inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
124
130 inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
131
132#if defined LIBO_INTERNAL_ONLY
133 Any(bool const *, Type const &) = delete;
134 Any(bool const *, typelib_TypeDescription *) = delete;
135 Any(bool const *, typelib_TypeDescriptionReference *) = delete;
136 Any(sal_Bool const *, Type const &) = delete;
137 Any(sal_Bool const *, typelib_TypeDescription *) = delete;
138 Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
139 Any(std::nullptr_t, Type const & type):
140 Any(static_cast<void *>(nullptr), type) {}
141 Any(std::nullptr_t, typelib_TypeDescription * type):
142 Any(static_cast<void *>(nullptr), type) {}
143 Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
144 Any(static_cast<void *>(nullptr), type) {}
145#endif
146
149 inline ~Any();
150
156 inline Any & SAL_CALL operator = ( const Any & rAny );
157
158#if defined LIBO_INTERNAL_ONLY
159#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
160 inline Any(Any && other) noexcept;
161#endif
162 inline Any & operator =(Any && other) noexcept;
163#endif
164
169 const Type & SAL_CALL getValueType() const
170 { return * reinterpret_cast< const Type * >( &pType ); }
171
175 typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const
176 { return pType; }
177
183 void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
184 { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
185
190 TypeClass SAL_CALL getValueTypeClass() const
191 { return static_cast<TypeClass>(pType->eTypeClass); }
192
197 inline ::rtl::OUString SAL_CALL getValueTypeName() const;
198
203 bool SAL_CALL hasValue() const
204 { return (typelib_TypeClass_VOID != pType->eTypeClass); }
205
210 const void * SAL_CALL getValue() const
211 { return pData; }
212
225 template <typename T>
226 inline T get() const;
227
234 inline void SAL_CALL setValue( const void * pData_, const Type & rType );
241 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
248 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
249
250#if defined LIBO_INTERNAL_ONLY
251 void setValue(bool const *, Type const &) = delete;
252 void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
253 void setValue(bool const *, typelib_TypeDescription *) = delete;
254 void setValue(sal_Bool const *, Type const &) = delete;
255 void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
256 = delete;
257 void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
258 void setValue(std::nullptr_t, Type const & type)
259 { setValue(static_cast<void *>(nullptr), type); }
260 void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
261 { setValue(static_cast<void *>(nullptr), type); }
262 void setValue(std::nullptr_t, typelib_TypeDescription * type)
263 { setValue(static_cast<void *>(nullptr), type); }
264#endif
265
269 inline void SAL_CALL clear();
270
277 inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
278
285 template <typename T>
286 inline bool has() const;
287
294 inline bool SAL_CALL operator == ( const Any & rAny ) const;
301 inline bool SAL_CALL operator != ( const Any & rAny ) const;
302
303#if defined LIBO_INTERNAL_ONLY
304 // Similar to Reference::query/queryThrow, these allow to simplify calling constructors of
305 // Reference taking Any. queryThrow is functionally similar to get(), but doesn't require
306 // to specify the full Reference type explicitly, only the interface type.
307 template<class interface_type> inline Reference<interface_type> query() const;
308 template<class interface_type> inline Reference<interface_type> queryThrow() const;
309#endif
310
311private:
312#if !defined LIBO_INTERNAL_ONLY
314 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
315 explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
317#endif
318};
319
320#if !defined LIBO_INTERNAL_ONLY
322// Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
323template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
324template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
326#endif
327
328#if !defined LIBO_INTERNAL_ONLY
340template< class C >
341inline Any SAL_CALL makeAny( const C & value );
342
343template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
344
345 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
346#endif
347
355template<typename T> inline Any toAny(T const & value);
356
357template<> inline Any toAny(Any const & value);
358
359#if defined LIBO_INTERNAL_ONLY
360
378template<typename T> inline bool fromAny(Any const & any, T * value);
379
380template<> inline bool fromAny(Any const & any, Any * value);
381
382#endif
383
384class BaseReference;
385
392template< class C >
393inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
394
395// additionally for C++ bool:
396template<>
397inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
398
408template< class C >
409inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
410
421template< class C >
422inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
433template< class C >
434inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
435
436// additional specialized >>= and == operators
437// bool
438template<>
439 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
440template<>
441inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
442template<>
443inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
444template<>
445inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
446// byte
447template<>
448 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
449// short
450template<>
451inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
452template<>
453inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
454// long
455template<>
456inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
457template<>
458inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
459// hyper
460template<>
461inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
462template<>
463inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
464// float
465template<>
466inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
467// double
468template<>
469inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
470// string
471template<>
472inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
473template<>
474inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
475#if defined LIBO_INTERNAL_ONLY
476template<std::size_t N>
477inline bool SAL_CALL operator == (const Any& rAny, const rtl::OUStringLiteral<N>& value);
478#endif
479// type
480template<>
481inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
482template<>
483inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
484// any
485#if !defined LIBO_INTERNAL_ONLY
486template<>
487inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
488#endif
489// interface
490template<>
491inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
492
493}
494}
495}
496}
497
510 SAL_DEPRECATED("use cppu::UnoType")
511inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
512{
513 return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
514}
515
516#endif
517
518/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
config.h
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:492
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition types.h:396
SAL_UNUSED_PARAMETER
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition types.h:592
sal_Bool
unsigned char sal_Bool
Definition types.h:38
sal_Int8
signed char sal_Int8
Definition types.h:43
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
ustring.hxx
alloc.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
typelib_TypeClass_VOID
@ typelib_TypeClass_VOID
type class of void
Definition typeclass.h:32
typedescription.h
typelib_TypeDescription
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
typelib_typedescriptionreference_getDescription
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
typelib_TypeDescriptionReference
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
any2.h
uno_Any
struct SAL_DLLPUBLIC_RTTI _uno_Any uno_Any
This is the binary specification of a UNO any.
unotype.hxx
getCppuType
const ::com::sun::star::uno::Type & getCppuType(SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any *)
Gets the meta type of IDL type any.
Definition Any.h:511
com
Definition types.h:377
com::sun
Definition types.h:377
com::sun::star
Definition types.h:377
com::sun::star::uno
Definition typedescription.hxx:43
com::sun::star::uno::operator==
bool operator==(const Any &rAny, const C &value)
Template equality operator: compares set value of left side any to right side value.
Definition Any.hxx:649
com::sun::star::uno::makeAny
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition Any.hxx:234
com::sun::star::uno::operator!=
bool operator!=(const Any &rAny, const C &value)
Template inequality operator: compares set value of left side any to right side value.
Definition Any.hxx:660
com::sun::star::uno::operator>>=
bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition Any.hxx:313
com::sun::star::uno::toAny
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition Any.hxx:243
com::sun::star::uno::operator<<=
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition Any.hxx:275
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:172
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition Reference.h:184
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition Any.h:62
com::sun::star::uno::Any::getValueType
const Type & getValueType() const
Gets the type of the set value.
Definition Any.h:169
com::sun::star::uno::Any::get
T get() const
Provides a value of specified type, so you can easily write e.g.
Definition Any.hxx:666
com::sun::star::uno::Any::getValueTypeDescription
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition Any.h:183
com::sun::star::uno::Any::hasValue
bool hasValue() const
Tests if any contains a value.
Definition Any.h:203
com::sun::star::uno::Any::getValueTypeRef
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition Any.h:175
com::sun::star::uno::Any::getValue
const void * getValue() const
Gets a pointer to the set value.
Definition Any.h:210
com::sun::star::uno::Any::getValueTypeClass
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition Any.h:190
com::sun::star::uno::Any::Any
Any()
Default constructor: Any holds no value; its type is void.
Definition Any.hxx:59
com::sun::star::uno::BaseReference
This base class serves as a base class for all template reference classes and has been introduced due...
Definition Reference.h:67
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition Type.h:59