LibreOffice
LibreOffice 24.8 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"
33#include "cppu/unotype.hxx"
34#include "com/sun/star/uno/TypeClass.hdl"
35#include "rtl/alloc.h"
36
37namespace com
38{
39namespace sun
40{
41namespace star
42{
43namespace uno
44{
45
46class Type;
47template<class interface_type> class Reference;
48
57class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
58{
59public:
61 // these are here to force memory de/allocation to sal lib.
62 static void * SAL_CALL operator new ( size_t nSize )
63 { return ::rtl_allocateMemory( nSize ); }
64 static void SAL_CALL operator delete ( void * pMem )
65 { ::rtl_freeMemory( pMem ); }
66 static void * SAL_CALL operator new ( size_t, void * pMem )
67 { return pMem; }
68 static void SAL_CALL operator delete ( void *, void * )
69 {}
71
74 inline Any();
75
80 template <typename T>
81 explicit inline Any( T const & value );
83 explicit inline Any( bool value );
84
85#if defined LIBO_INTERNAL_ONLY
86 template<typename T1, typename T2>
87 explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
88 template<typename T1, typename T2>
89 explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
90 template<std::size_t nBufSize> explicit inline Any(rtl::StringNumber<sal_Unicode, nBufSize> && value);
91 template<std::size_t nBufSize> explicit Any(rtl::StringNumber<sal_Unicode, nBufSize> const &) = delete;
92 template <std::size_t N> explicit inline Any(const rtl::OUStringLiteral<N>& value);
93#endif
94
99 inline Any( const Any & rAny );
100
106 inline Any( const void * pData_, const Type & rType );
107
113 inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
114
120 inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
121
122#if defined LIBO_INTERNAL_ONLY
123 Any(bool const *, Type const &) = delete;
124 Any(bool const *, typelib_TypeDescription *) = delete;
125 Any(bool const *, typelib_TypeDescriptionReference *) = delete;
126 Any(sal_Bool const *, Type const &) = delete;
127 Any(sal_Bool const *, typelib_TypeDescription *) = delete;
128 Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
129 Any(std::nullptr_t, Type const & type):
130 Any(static_cast<void *>(nullptr), type) {}
131 Any(std::nullptr_t, typelib_TypeDescription * type):
132 Any(static_cast<void *>(nullptr), type) {}
133 Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
134 Any(static_cast<void *>(nullptr), type) {}
135#endif
136
139 inline ~Any();
140
146 inline Any & SAL_CALL operator = ( const Any & rAny );
147
148#if defined LIBO_INTERNAL_ONLY
149#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
150 inline Any(Any && other) noexcept;
151#endif
152 inline Any & operator =(Any && other) noexcept;
153#endif
154
159 const Type & SAL_CALL getValueType() const
160 { return * reinterpret_cast< const Type * >( &pType ); }
161
166 { return pType; }
167
173 void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
175
180 TypeClass SAL_CALL getValueTypeClass() const
181 { return static_cast<TypeClass>(pType->eTypeClass); }
182
187 inline ::rtl::OUString SAL_CALL getValueTypeName() const;
188
193 bool SAL_CALL hasValue() const
194 { return (typelib_TypeClass_VOID != pType->eTypeClass); }
195
200 const void * SAL_CALL getValue() const
201 { return pData; }
202
215 template <typename T>
216 inline T get() const;
217
224 inline void SAL_CALL setValue( const void * pData_, const Type & rType );
231 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
238 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
239
240#if defined LIBO_INTERNAL_ONLY
241 void setValue(bool const *, Type const &) = delete;
242 void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
243 void setValue(bool const *, typelib_TypeDescription *) = delete;
244 void setValue(sal_Bool const *, Type const &) = delete;
245 void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
246 = delete;
247 void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
248 void setValue(std::nullptr_t, Type const & type)
249 { setValue(static_cast<void *>(nullptr), type); }
250 void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
251 { setValue(static_cast<void *>(nullptr), type); }
252 void setValue(std::nullptr_t, typelib_TypeDescription * type)
253 { setValue(static_cast<void *>(nullptr), type); }
254#endif
255
259 inline void SAL_CALL clear();
260
267 inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
268
275 template <typename T>
276 inline bool has() const;
277
284 inline bool SAL_CALL operator == ( const Any & rAny ) const;
291 inline bool SAL_CALL operator != ( const Any & rAny ) const;
292
293#if defined LIBO_INTERNAL_ONLY
294 // Similar to Reference::query/queryThrow, these allow to simplify calling constructors of
295 // Reference taking Any. queryThrow is functionally similar to get(), but doesn't require
296 // to specify the full Reference type explicitly, only the interface type.
297 template<class interface_type> inline Reference<interface_type> query() const;
298 template<class interface_type> inline Reference<interface_type> queryThrow() const;
299#endif
300
301private:
302#if !defined LIBO_INTERNAL_ONLY
304 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
305 explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
307#endif
308};
309
310#if !defined LIBO_INTERNAL_ONLY
312// Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
313template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
314template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
316#endif
317
318#if !defined LIBO_INTERNAL_ONLY
330template< class C >
331inline Any SAL_CALL makeAny( const C & value );
332
333template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
334
335template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
336#endif
337
345template<typename T> inline Any toAny(T const & value);
346
347template<> inline Any toAny(Any const & value);
348
349#if defined LIBO_INTERNAL_ONLY
350
368template<typename T> inline bool fromAny(Any const & any, T * value);
369
370template<> inline bool fromAny(Any const & any, Any * value);
371
372#endif
373
374class BaseReference;
375
382template< class C >
383inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
384
385// additionally for C++ bool:
386template<>
387inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
388
398template< class C >
399inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
400
411template< class C >
412inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
423template< class C >
424inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
425
426// additional specialized >>= and == operators
427// bool
428template<>
429inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
430template<>
431inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
432template<>
433inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
434template<>
435inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
436// byte
437template<>
438inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
439// short
440template<>
441inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
442template<>
443inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
444// long
445template<>
446inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
447template<>
448inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
449// hyper
450template<>
451inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
452template<>
453inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
454// float
455template<>
456inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
457// double
458template<>
459inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
460// string
461template<>
462inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
463template<>
464inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
465#if defined LIBO_INTERNAL_ONLY
466template<std::size_t N>
467inline bool SAL_CALL operator == (const Any& rAny, const rtl::OUStringLiteral<N>& value);
468#endif
469// type
470template<>
471inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
472template<>
473inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
474// any
475#if !defined LIBO_INTERNAL_ONLY
476template<>
477inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
478#endif
479// interface
480template<>
481inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
482
483}
484}
485}
486}
487
500SAL_DEPRECATED("use cppu::UnoType")
501inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
502{
503 return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
504}
505
506#endif
507
508/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:492
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition types.h:396
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition types.h:592
unsigned char sal_Bool
Definition types.h:38
signed char sal_Int8
Definition types.h:43
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
@ typelib_TypeClass_VOID
type class of void
Definition typeclass.h:32
struct SAL_DLLPUBLIC_RTTI _uno_Any uno_Any
This is the binary specification of a UNO any.
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:501
Definition types.h:377
Definition types.h:377
Definition types.h:377
Definition typedescription.hxx:43
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:666
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition Any.hxx:238
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:677
bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition Any.hxx:329
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition Any.hxx:247
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition Any.hxx:279
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:172
Template reference class for interface type derived from BaseReference.
Definition Reference.h:184
C++ class representing an IDL any.
Definition Any.h:58
const Type & getValueType() const
Gets the type of the set value.
Definition Any.h:159
T get() const
Provides a value of specified type, so you can easily write e.g.
Definition Any.hxx:683
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition Any.h:173
bool hasValue() const
Tests if any contains a value.
Definition Any.h:193
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition Any.h:165
const void * getValue() const
Gets a pointer to the set value.
Definition Any.h:200
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition Any.h:180
Any()
Default constructor: Any holds no value; its type is void.
Definition Any.hxx:59
This base class serves as a base class for all template reference classes and has been introduced due...
Definition Reference.h:67
C++ class representing an IDL meta type.
Definition Type.h:59