LibreOffice
LibreOffice 7.4 SDK C/C++ API Reference
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;
47
56class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
57{
58public:
60 // these are here to force memory de/allocation to sal lib.
61 static void * SAL_CALL operator new ( size_t nSize )
62 { return ::rtl_allocateMemory( nSize ); }
63 static void SAL_CALL operator delete ( void * pMem )
64 { ::rtl_freeMemory( pMem ); }
65 static void * SAL_CALL operator new ( size_t, void * pMem )
66 { return pMem; }
67 static void SAL_CALL operator delete ( void *, void * )
68 {}
70
73 inline Any();
74
79 template <typename T>
80 explicit inline Any( T const & value );
82 explicit inline Any( bool value );
83
84#if defined LIBO_INTERNAL_ONLY
85 template<typename T1, typename T2>
86 explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
87 template<typename T1, typename T2>
88 explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
89 template<typename T> explicit inline Any(rtl::OUStringNumber<T> && value);
90 template<typename T> explicit Any(rtl::OUStringNumber<T> const &) = delete;
91#endif
92
97 inline Any( const Any & rAny );
98
104 inline Any( const void * pData_, const Type & rType );
105
111 inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
112
118 inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
119
120#if defined LIBO_INTERNAL_ONLY
121 Any(bool const *, Type const &) = delete;
122 Any(bool const *, typelib_TypeDescription *) = delete;
123 Any(bool const *, typelib_TypeDescriptionReference *) = delete;
124 Any(sal_Bool const *, Type const &) = delete;
125 Any(sal_Bool const *, typelib_TypeDescription *) = delete;
126 Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
127 Any(std::nullptr_t, Type const & type):
128 Any(static_cast<void *>(nullptr), type) {}
129 Any(std::nullptr_t, typelib_TypeDescription * type):
130 Any(static_cast<void *>(nullptr), type) {}
131 Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
132 Any(static_cast<void *>(nullptr), type) {}
133#endif
134
137 inline ~Any();
138
144 inline Any & SAL_CALL operator = ( const Any & rAny );
145
146#if defined LIBO_INTERNAL_ONLY
147 inline Any(Any && other) noexcept;
148 inline Any & operator =(Any && other) noexcept;
149#endif
150
155 const Type & SAL_CALL getValueType() const
156 { return * reinterpret_cast< const Type * >( &pType ); }
162 { return pType; }
163
169 void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
171
176 TypeClass SAL_CALL getValueTypeClass() const
177 { return static_cast<TypeClass>(pType->eTypeClass); }
178
183 inline ::rtl::OUString SAL_CALL getValueTypeName() const;
184
189 bool SAL_CALL hasValue() const
190 { return (typelib_TypeClass_VOID != pType->eTypeClass); }
191
196 const void * SAL_CALL getValue() const
197 { return pData; }
198
211 template <typename T>
212 inline T get() const;
213
220 inline void SAL_CALL setValue( const void * pData_, const Type & rType );
227 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
234 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
235
236#if defined LIBO_INTERNAL_ONLY
237 void setValue(bool const *, Type const &) = delete;
238 void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
239 void setValue(bool const *, typelib_TypeDescription *) = delete;
240 void setValue(sal_Bool const *, Type const &) = delete;
241 void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
242 = delete;
243 void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
244 void setValue(std::nullptr_t, Type const & type)
245 { setValue(static_cast<void *>(nullptr), type); }
246 void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
247 { setValue(static_cast<void *>(nullptr), type); }
248 void setValue(std::nullptr_t, typelib_TypeDescription * type)
249 { setValue(static_cast<void *>(nullptr), type); }
250#endif
251
255 inline void SAL_CALL clear();
256
263 inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
264
271 template <typename T>
272 inline bool has() const;
273
280 inline bool SAL_CALL operator == ( const Any & rAny ) const;
287 inline bool SAL_CALL operator != ( const Any & rAny ) const;
288
289private:
290#if !defined LIBO_INTERNAL_ONLY
292 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
293 explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
295#endif
296};
297
298#if !defined LIBO_INTERNAL_ONLY
300// Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
301template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
302template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
304#endif
305
306#if !defined LIBO_INTERNAL_ONLY
318template< class C >
319inline Any SAL_CALL makeAny( const C & value );
320
321template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
322
323template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
324#endif
325
333template<typename T> inline Any toAny(T const & value);
334
335template<> inline Any toAny(Any const & value);
336
337#if defined LIBO_INTERNAL_ONLY
338
356template<typename T> inline bool fromAny(Any const & any, T * value);
357
358template<> inline bool fromAny(Any const & any, Any * value);
359
360#endif
361
362class BaseReference;
363
370template< class C >
371inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
372
373// additionally for C++ bool:
374template<>
375inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
376
386template< class C >
387inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
388
399template< class C >
400inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
411template< class C >
412inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
413
414// additional specialized >>= and == operators
415// bool
416template<>
417inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
418template<>
419inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
420template<>
421inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
422template<>
423inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
424// byte
425template<>
426inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
427// short
428template<>
429inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
430template<>
431inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
432// long
433template<>
434inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
435template<>
436inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
437// hyper
438template<>
439inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
440template<>
441inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
442// float
443template<>
444inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
445// double
446template<>
447inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
448// string
449template<>
450inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
451template<>
452inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
453// type
454template<>
455inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
456template<>
457inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
458// any
459#if !defined LIBO_INTERNAL_ONLY
460template<>
461inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
462#endif
463// interface
464template<>
465inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
466
467}
468}
469}
470}
471
484SAL_DEPRECATED("use cppu::UnoType")
485inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
486{
487 return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
488}
489
490#endif
491
492/* 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:474
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:378
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:568
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:587
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
@ typelib_TypeClass_VOID
type class of void
Definition: typeclass.h:32
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.
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:485
Definition: types.h:359
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:652
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:234
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:663
bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition: Any.hxx:323
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition: Any.hxx:243
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition: Any.hxx:273
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:203
C++ class representing an IDL any.
Definition: Any.h:57
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:155
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:169
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:189
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:161
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:196
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:176
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