LibreOffice
LibreOffice 5.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>
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  inline static void * SAL_CALL operator new ( size_t nSize )
58  { return ::rtl_allocateMemory( nSize ); }
59  inline static void SAL_CALL operator delete ( void * pMem )
60  { ::rtl_freeMemory( pMem ); }
61  inline static void * SAL_CALL operator new ( size_t, void * pMem )
62  { return pMem; }
63  inline 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> const & value);
83 #endif
84 
89  inline Any( const Any & rAny );
90 
96  inline Any( const void * pData_, const Type & rType );
97 
103  inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
104 
110  inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
111 
112 #if defined LIBO_INTERNAL_ONLY
113  Any(bool const *, Type const &) = delete;
114  Any(bool const *, typelib_TypeDescription *) = delete;
115  Any(bool const *, typelib_TypeDescriptionReference *) = delete;
116  Any(sal_Bool const *, Type const &) = delete;
117  Any(sal_Bool const *, typelib_TypeDescription *) = delete;
118  Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
119  Any(std::nullptr_t, Type const & type):
120  Any(static_cast<void *>(nullptr), type) {}
121  Any(std::nullptr_t, typelib_TypeDescription * type):
122  Any(static_cast<void *>(nullptr), type) {}
123  Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
124  Any(static_cast<void *>(nullptr), type) {}
125 #endif
126 
129  inline ~Any();
130 
136  inline Any & SAL_CALL operator = ( const Any & rAny );
137 
142  inline const Type & SAL_CALL getValueType() const
143  { return * reinterpret_cast< const Type * >( &pType ); }
149  { return pType; }
150 
156  inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
157  { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
158 
163  inline TypeClass SAL_CALL getValueTypeClass() const
164  { return (TypeClass)pType->eTypeClass; }
165 
170  inline ::rtl::OUString SAL_CALL getValueTypeName() const;
171 
176  inline bool SAL_CALL hasValue() const
177  { return (typelib_TypeClass_VOID != pType->eTypeClass); }
178 
183  inline const void * SAL_CALL getValue() const
184  { return pData; }
185 
198  template <typename T>
199  inline T get() const;
200 
207  inline void SAL_CALL setValue( const void * pData_, const Type & rType );
214  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
221  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
222 
223 #if defined LIBO_INTERNAL_ONLY
224  void setValue(bool const *, Type const &) = delete;
225  void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
226  void setValue(bool const *, typelib_TypeDescription *) = delete;
227  void setValue(sal_Bool const *, Type const &) = delete;
228  void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
229  = delete;
230  void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
231  void setValue(std::nullptr_t, Type const & type)
232  { setValue(static_cast<void *>(nullptr), type); }
233  void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
234  { setValue(static_cast<void *>(nullptr), type); }
235  void setValue(std::nullptr_t, typelib_TypeDescription * type)
236  { setValue(static_cast<void *>(nullptr), type); }
237 #endif
238 
242  inline void SAL_CALL clear();
243 
250  inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
251 
258  template <typename T>
259  inline bool has() const;
260 
267  inline bool SAL_CALL operator == ( const Any & rAny ) const;
274  inline bool SAL_CALL operator != ( const Any & rAny ) const;
275 
276 private:
277 #if !defined LIBO_INTERNAL_ONLY
278  // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
280  explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
282 #endif
283 };
284 
285 #if !defined LIBO_INTERNAL_ONLY
286 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
288 template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
289 template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
291 #endif
292 
304 template< class C >
305 inline Any SAL_CALL makeAny( const C & value );
306 
307 #if !defined LIBO_INTERNAL_ONLY
308 template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
309 #endif
310 
311 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
312 
320 template<typename T> inline Any toAny(T const & value);
321 
322 template<> inline Any toAny(Any const & value);
323 
324 class BaseReference;
325 
332 template< class C >
333 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
334 
335 // additionally for C++ bool:
336 template<>
337 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
338 
348 template< class C >
349 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
350 
361 template< class C >
362 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
373 template< class C >
374 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
375 
376 // additional specialized >>= and == operators
377 // bool
378 template<>
379 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
380 template<>
381 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
382 template<>
383 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
384 template<>
385 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
386 // byte
387 template<>
388 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
389 // short
390 template<>
391 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
392 template<>
393 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
394 // long
395 template<>
396 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
397 template<>
398 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
399 // hyper
400 template<>
401 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
402 template<>
403 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
404 // float
405 template<>
406 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
407 // double
408 template<>
409 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
410 // string
411 template<>
412 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
413 template<>
414 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
415 // type
416 template<>
417 inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
418 template<>
419 inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
420 // any
421 template<>
422 inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
423 // interface
424 template<>
425 inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
426 
427 }
428 }
429 }
430 }
431 
444 SAL_DEPRECATED("use cppu::UnoType")
445 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
446 {
447  return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
448 }
449 
450 #endif
451 
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:562
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:183
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:410
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:624
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition: Any.hxx:204
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
C++ class representing an IDL any.
Definition: Any.h:52
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
struct SAL_DLLPUBLIC_RTTI _uno_Any uno_Any
This is the binary specification of an UNO any.
Definition: types.h:391
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:445
unsigned char sal_Bool
Definition: types.h:48
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:148
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:573
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:603
C++ class representing an IDL meta type.
Definition: Type.h:54
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
signed char sal_Int8
Definition: types.h:53
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:142
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:176
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:163
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:509
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:156
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:189
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:58
Any toAny(T const &value)
Wrap a value in an Any, if necessary.
Definition: Any.hxx:199
bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition: Any.hxx:237
type class of void
Definition: typeclass.h:29