LibreOffice LibreOffice 6.2 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 #ifndef INCLUDED_COM_SUN_STAR_UNO_ANY_H
20 #define INCLUDED_COM_SUN_STAR_UNO_ANY_H
21
22 #include "sal/config.h"
23
24 #include <cstddef>
25
26 #include "rtl/ustring.hxx"
27 #include "uno/any2.h"
28 #include "typelib/typedescription.h"
29 #include "cppu/unotype.hxx"
30 #include "com/sun/star/uno/TypeClass.hdl"
31 #include "rtl/alloc.h"
32
33 namespace com
34 {
35 namespace sun
36 {
37 namespace star
38 {
39 namespace uno
40 {
41
42 class Type;
43
52 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
53 {
54 public:
56 // these are here to force memory de/allocation to sal lib.
57 static void * SAL_CALL operator new ( size_t nSize )
58 { return ::rtl_allocateMemory( nSize ); }
59 static void SAL_CALL operator delete ( void * pMem )
60 { ::rtl_freeMemory( pMem ); }
61 static void * SAL_CALL operator new ( size_t, void * pMem )
62 { return pMem; }
63 static void SAL_CALL operator delete ( void *, void * )
64 {}
66
69 inline Any();
70
75 template <typename T>
76 explicit inline Any( T const & value );
78 explicit inline Any( bool value );
79
80 #if defined LIBO_INTERNAL_ONLY
81 template<typename T1, typename T2>
82 explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
83 template<typename T1, typename T2>
84 explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
85 #endif
86
91 inline Any( const Any & rAny );
92
98 inline Any( const void * pData_, const Type & rType );
99
105 inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
106
112 inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
113
114 #if defined LIBO_INTERNAL_ONLY
115 Any(bool const *, Type const &) = delete;
116 Any(bool const *, typelib_TypeDescription *) = delete;
117 Any(bool const *, typelib_TypeDescriptionReference *) = delete;
118 Any(sal_Bool const *, Type const &) = delete;
119 Any(sal_Bool const *, typelib_TypeDescription *) = delete;
120 Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
121 Any(std::nullptr_t, Type const & type):
122 Any(static_cast<void *>(nullptr), type) {}
123 Any(std::nullptr_t, typelib_TypeDescription * type):
124 Any(static_cast<void *>(nullptr), type) {}
125 Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
126 Any(static_cast<void *>(nullptr), type) {}
127 #endif
128
131 inline ~Any();
132
138 inline Any & SAL_CALL operator = ( const Any & rAny );
139
140 #if defined LIBO_INTERNAL_ONLY
141 inline Any(Any && other);
142 inline Any & operator =(Any && other);
143 #endif
144
149 const Type & SAL_CALL getValueType() const
150 { return * reinterpret_cast< const Type * >( &pType ); }
155 typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const
156 { return pType; }
157
163 void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
164 { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
165
170 TypeClass SAL_CALL getValueTypeClass() const
171 { return static_cast<TypeClass>(pType->eTypeClass); }
172
177 inline ::rtl::OUString SAL_CALL getValueTypeName() const;
178
183 bool SAL_CALL hasValue() const
184 { return (typelib_TypeClass_VOID != pType->eTypeClass); }
185
190 const void * SAL_CALL getValue() const
191 { return pData; }
192
205 template <typename T>
206 inline T get() const;
207
214 inline void SAL_CALL setValue( const void * pData_, const Type & rType );
221 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
228 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
229
230 #if defined LIBO_INTERNAL_ONLY
231 void setValue(bool const *, Type const &) = delete;
232 void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
233 void setValue(bool const *, typelib_TypeDescription *) = delete;
234 void setValue(sal_Bool const *, Type const &) = delete;
235 void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
236 = delete;
237 void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
238 void setValue(std::nullptr_t, Type const & type)
239 { setValue(static_cast<void *>(nullptr), type); }
240 void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
241 { setValue(static_cast<void *>(nullptr), type); }
242 void setValue(std::nullptr_t, typelib_TypeDescription * type)
243 { setValue(static_cast<void *>(nullptr), type); }
244 #endif
245
249 inline void SAL_CALL clear();
250
257 inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
258
265 template <typename T>
266 inline bool has() const;
267
274 inline bool SAL_CALL operator == ( const Any & rAny ) const;
281 inline bool SAL_CALL operator != ( const Any & rAny ) const;
282
283 private:
284 #if !defined LIBO_INTERNAL_ONLY
285 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
287 explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
289 #endif
290 };
291
292 #if !defined LIBO_INTERNAL_ONLY
293 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
295 template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
296 template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
298 #endif
299
311 template< class C >
312 inline Any SAL_CALL makeAny( const C & value );
313
314 #if !defined LIBO_INTERNAL_ONLY
315 template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
316 #endif
317
318 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
319
327 template<typename T> inline Any toAny(T const & value);
328
329 template<> inline Any toAny(Any const & value);
330
331 #if defined LIBO_INTERNAL_ONLY
332
350 template<typename T> inline bool fromAny(Any const & any, T * value);
351
352 template<> inline bool fromAny(Any const & any, Any * value);
353
354 #endif
355
356 class BaseReference;
357
364 template< class C >
365 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
366
367 // additionally for C++ bool:
368 template<>
369 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
370
380 template< class C >
381 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
382
393 template< class C >
394 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
405 template< class C >
406 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
407
408 // additional specialized >>= and == operators
409 // bool
410 template<>
411 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
412 template<>
413 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
414 template<>
415 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
416 template<>
417 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
418 // byte
419 template<>
420 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
421 // short
422 template<>
423 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
424 template<>
425 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
426 // long
427 template<>
428 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
429 template<>
430 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
431 // hyper
432 template<>
433 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
434 template<>
435 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
436 // float
437 template<>
438 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
439 // double
440 template<>
441 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
442 // string
443 template<>
444 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
445 template<>
446 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
447 // type
448 template<>
449 inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
450 template<>
451 inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
452 // any
453 #if !defined LIBO_INTERNAL_ONLY
454 template<>
455 inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
456 #endif
457 // interface
458 template<>
459 inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
460
461 }
462 }
463 }
464 }
465
478 SAL_DEPRECATED("use cppu::UnoType")
479 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
480 {
481 return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
482 }
483
484 #endif
485
486 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition: Type.h:54
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:52
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:479
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:305
sal_Int8
signed char sal_Int8
Definition: types.h:43
typelib_TypeDescriptionReference
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
com::sun::star::uno::Any::hasValue
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:183
SAL_UNUSED_PARAMETER
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:571
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:477
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:590
com::sun::star::uno::Any::getValueTypeClass
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:170
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
com::sun::star::uno::Any::getValueType
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:149
any2.h
ustring.hxx
com::sun::star::uno::toAny
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition: Any.hxx:238
typelib_TypeDescription
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
sal_Bool
unsigned char sal_Bool
Definition: types.h:38
uno_Any
struct SAL_DLLPUBLIC_RTTI _uno_Any uno_Any
This is the binary specification of an UNO any.
typelib_TypeClass_VOID
type class of void
Definition: typeclass.h:29
com
Definition: types.h:377
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.
unotype.hxx
com::sun::star::uno::Any::getValue
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:190
com::sun::star::uno::operator !=
bool operator !=(const Any &rAny, const C &value)
Template unequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:645
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:266
com::sun::star::uno::Any::getValueTypeDescription
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:163
typedescription.h
config.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
com::sun::star::uno::makeAny
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:228
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:123
alloc.h
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:634
com::sun::star::uno::Any::getValueTypeRef
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:155