AlterOffice
AlterOffice 2026.0 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #ifndef INCLUDED_COM_SUN_STAR_UNO_ANY_H
4 #define INCLUDED_COM_SUN_STAR_UNO_ANY_H
5 
6 #include "sal/config.h"
7 
8 #include <cstddef>
9 
10 #include "rtl/ustring.hxx"
11 #include "uno/any2.h"
13 #include "cppu/unotype.hxx"
14 #include "com/sun/star/uno/TypeClass.hdl"
15 #include "rtl/alloc.h"
16 
17 namespace com
18 {
19 namespace sun
20 {
21 namespace star
22 {
23 namespace uno
24 {
25 
26 class Type;
27 template<class interface_type> class Reference;
28 
37 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
38 {
39 public:
41  // these are here to force memory de/allocation to sal lib.
42  static void * SAL_CALL operator new ( size_t nSize )
43  { return ::rtl_allocateMemory( nSize ); }
44  static void SAL_CALL operator delete ( void * pMem )
45  { ::rtl_freeMemory( pMem ); }
46  static void * SAL_CALL operator new ( size_t, void * pMem )
47  { return pMem; }
48  static void SAL_CALL operator delete ( void *, void * )
49  {}
51 
54  inline Any();
55 
60  template <typename T>
61  explicit inline Any( T const & value );
63  explicit inline Any( bool value );
64 
65 #if defined LIBO_INTERNAL_ONLY
66  template<typename T1, typename T2>
67  explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
68  template<typename T1, typename T2>
69  explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
70  template<typename T> explicit inline Any(rtl::OUStringNumber<T> && value);
71  template<typename T> explicit Any(rtl::OUStringNumber<T> const &) = delete;
72  template <std::size_t N> explicit inline Any(const rtl::OUStringLiteral<N>& value);
73 #endif
74 
79  inline Any( const Any & rAny );
80 
86  inline Any( const void * pData_, const Type & rType );
87 
93  inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
94 
100  inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
101 
102 #if defined LIBO_INTERNAL_ONLY
103  Any(bool const *, Type const &) = delete;
104  Any(bool const *, typelib_TypeDescription *) = delete;
105  Any(bool const *, typelib_TypeDescriptionReference *) = delete;
106  Any(sal_Bool const *, Type const &) = delete;
107  Any(sal_Bool const *, typelib_TypeDescription *) = delete;
108  Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
109  Any(std::nullptr_t, Type const & type):
110  Any(static_cast<void *>(nullptr), type) {}
111  Any(std::nullptr_t, typelib_TypeDescription * type):
112  Any(static_cast<void *>(nullptr), type) {}
113  Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
114  Any(static_cast<void *>(nullptr), type) {}
115 #endif
116 
119  inline ~Any();
120 
126  inline Any & SAL_CALL operator = ( const Any & rAny );
127 
128 #if defined LIBO_INTERNAL_ONLY
129  inline Any(Any && other) noexcept;
130  inline Any & operator =(Any && other) noexcept;
131 #endif
132 
137  const Type & SAL_CALL getValueType() const
138  { return * reinterpret_cast< const Type * >( &pType ); }
144  { return pType; }
145 
151  void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
152  { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
153 
158  TypeClass SAL_CALL getValueTypeClass() const
159  { return static_cast<TypeClass>(pType->eTypeClass); }
160 
165  inline ::rtl::OUString SAL_CALL getValueTypeName() const;
166 
171  bool SAL_CALL hasValue() const
172  { return (typelib_TypeClass_VOID != pType->eTypeClass); }
173 
178  const void * SAL_CALL getValue() const
179  { return pData; }
180 
193  template <typename T>
194  inline T get() const;
195 
202  inline void SAL_CALL setValue( const void * pData_, const Type & rType );
209  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
216  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
217 
218 #if defined LIBO_INTERNAL_ONLY
219  void setValue(bool const *, Type const &) = delete;
220  void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
221  void setValue(bool const *, typelib_TypeDescription *) = delete;
222  void setValue(sal_Bool const *, Type const &) = delete;
223  void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
224  = delete;
225  void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
226  void setValue(std::nullptr_t, Type const & type)
227  { setValue(static_cast<void *>(nullptr), type); }
228  void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
229  { setValue(static_cast<void *>(nullptr), type); }
230  void setValue(std::nullptr_t, typelib_TypeDescription * type)
231  { setValue(static_cast<void *>(nullptr), type); }
232 #endif
233 
237  inline void SAL_CALL clear();
238 
245  inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
246 
253  template <typename T>
254  inline bool has() const;
255 
262  inline bool SAL_CALL operator == ( const Any & rAny ) const;
269  inline bool SAL_CALL operator != ( const Any & rAny ) const;
270 
271 #if defined LIBO_INTERNAL_ONLY
272  // Similar to Reference::query/queryThrow, these allow to simplify calling constructors of
273  // Reference taking Any. queryThrow is functionally similar to get(), but doesn't require
274  // to specify the full Reference type explicitly, only the interface type.
275  template<class interface_type> inline Reference<interface_type> query() const;
276  template<class interface_type> inline Reference<interface_type> queryThrow() const;
277 #endif
278 
279 private:
280 #if !defined LIBO_INTERNAL_ONLY
281  // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
283  explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
285 #endif
286 };
287 
288 #if !defined LIBO_INTERNAL_ONLY
289 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
291 template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
292 template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
294 #endif
295 
296 #if !defined LIBO_INTERNAL_ONLY
297 
308 template< class C >
309 inline Any SAL_CALL makeAny( const C & value );
310 
311 template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
312 
313 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
314 #endif
315 
323 template<typename T> inline Any toAny(T const & value);
324 
325 template<> inline Any toAny(Any const & value);
326 
327 #if defined LIBO_INTERNAL_ONLY
328 
346 template<typename T> inline bool fromAny(Any const & any, T * value);
347 
348 template<> inline bool fromAny(Any const & any, Any * value);
349 
350 #endif
351 
352 class BaseReference;
353 
360 template< class C >
361 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
362 
363 // additionally for C++ bool:
364 template<>
365 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
366 
376 template< class C >
377 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
378 
389 template< class C >
390 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
401 template< class C >
402 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
403 
404 // additional specialized >>= and == operators
405 // bool
406 template<>
407 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
408 template<>
409 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
410 template<>
411 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
412 template<>
413 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
414 // byte
415 template<>
416 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
417 // short
418 template<>
419 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
420 template<>
421 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
422 // long
423 template<>
424 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
425 template<>
426 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
427 // hyper
428 template<>
429 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
430 template<>
431 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
432 // float
433 template<>
434 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
435 // double
436 template<>
437 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
438 // string
439 template<>
440 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
441 template<>
442 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
443 #if defined LIBO_INTERNAL_ONLY
444 template<std::size_t N>
445 inline bool SAL_CALL operator == (const Any& rAny, const rtl::OUStringLiteral<N>& value);
446 #endif
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: */
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:178
unsigned char sal_Bool
Definition: types.h:18
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
type class of void
Definition: typeclass.h:12
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:183
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
C++ class representing an IDL any.
Definition: Any.h:37
struct SAL_DLLPUBLIC_RTTI _uno_Any uno_Any
This is the binary specification of a UNO any.
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition: Any.hxx:225
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:548
bool operator>>=(const Any &rAny, C &value)
Template binary &gt;&gt;= operator to assign a value from an any.
Definition: Any.hxx:305
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:642
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:143
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:216
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED(&quot;Don&#39;t use, it&#39;s evil.&quot;) void doit(int nPara);.
Definition: types.h:454
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:567
void operator<<=(Any &rAny, const C &value)
Template binary &lt;&lt;= operator to set the value of an any.
Definition: Any.hxx:255
C++ class representing an IDL meta type.
Definition: Type.h:38
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:137
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:653
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:171
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:158
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:151
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
signed char sal_Int8
Definition: types.h:23
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:358