AlterOffice
AlterOffice 3.4 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 
36 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
37 {
38 public:
40  // these are here to force memory de/allocation to sal lib.
41  static void * SAL_CALL operator new ( size_t nSize )
42  { return ::rtl_allocateMemory( nSize ); }
43  static void SAL_CALL operator delete ( void * pMem )
44  { ::rtl_freeMemory( pMem ); }
45  static void * SAL_CALL operator new ( size_t, void * pMem )
46  { return pMem; }
47  static void SAL_CALL operator delete ( void *, void * )
48  {}
50 
53  inline Any();
54 
59  template <typename T>
60  explicit inline Any( T const & value );
62  explicit inline Any( bool value );
63 
64 #if defined LIBO_INTERNAL_ONLY
65  template<typename T1, typename T2>
66  explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
67  template<typename T1, typename T2>
68  explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
69  template<typename T> explicit inline Any(rtl::OUStringNumber<T> && value);
70  template<typename T> explicit Any(rtl::OUStringNumber<T> const &) = delete;
71  template <std::size_t N> explicit inline Any(const rtl::OUStringLiteral<N>& value);
72 #endif
73 
78  inline Any( const Any & rAny );
79 
85  inline Any( const void * pData_, const Type & rType );
86 
92  inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
93 
99  inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
100 
101 #if defined LIBO_INTERNAL_ONLY
102  Any(bool const *, Type const &) = delete;
103  Any(bool const *, typelib_TypeDescription *) = delete;
104  Any(bool const *, typelib_TypeDescriptionReference *) = delete;
105  Any(sal_Bool const *, Type const &) = delete;
106  Any(sal_Bool const *, typelib_TypeDescription *) = delete;
107  Any(sal_Bool const *, typelib_TypeDescriptionReference *) = delete;
108  Any(std::nullptr_t, Type const & type):
109  Any(static_cast<void *>(nullptr), type) {}
110  Any(std::nullptr_t, typelib_TypeDescription * type):
111  Any(static_cast<void *>(nullptr), type) {}
112  Any(std::nullptr_t, typelib_TypeDescriptionReference * type):
113  Any(static_cast<void *>(nullptr), type) {}
114 #endif
115 
118  inline ~Any();
119 
125  inline Any & SAL_CALL operator = ( const Any & rAny );
126 
127 #if defined LIBO_INTERNAL_ONLY
128  inline Any(Any && other) noexcept;
129  inline Any & operator =(Any && other) noexcept;
130 #endif
131 
136  const Type & SAL_CALL getValueType() const
137  { return * reinterpret_cast< const Type * >( &pType ); }
143  { return pType; }
144 
150  void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
151  { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
152 
157  TypeClass SAL_CALL getValueTypeClass() const
158  { return static_cast<TypeClass>(pType->eTypeClass); }
159 
164  inline ::rtl::OUString SAL_CALL getValueTypeName() const;
165 
170  bool SAL_CALL hasValue() const
171  { return (typelib_TypeClass_VOID != pType->eTypeClass); }
172 
177  const void * SAL_CALL getValue() const
178  { return pData; }
179 
192  template <typename T>
193  inline T get() const;
194 
201  inline void SAL_CALL setValue( const void * pData_, const Type & rType );
208  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
215  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
216 
217 #if defined LIBO_INTERNAL_ONLY
218  void setValue(bool const *, Type const &) = delete;
219  void setValue(bool const *, typelib_TypeDescriptionReference *) = delete;
220  void setValue(bool const *, typelib_TypeDescription *) = delete;
221  void setValue(sal_Bool const *, Type const &) = delete;
222  void setValue(sal_Bool const *, typelib_TypeDescriptionReference *)
223  = delete;
224  void setValue(sal_Bool const *, typelib_TypeDescription *) = delete;
225  void setValue(std::nullptr_t, Type const & type)
226  { setValue(static_cast<void *>(nullptr), type); }
227  void setValue(std::nullptr_t, typelib_TypeDescriptionReference * type)
228  { setValue(static_cast<void *>(nullptr), type); }
229  void setValue(std::nullptr_t, typelib_TypeDescription * type)
230  { setValue(static_cast<void *>(nullptr), type); }
231 #endif
232 
236  inline void SAL_CALL clear();
237 
244  inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
245 
252  template <typename T>
253  inline bool has() const;
254 
261  inline bool SAL_CALL operator == ( const Any & rAny ) const;
268  inline bool SAL_CALL operator != ( const Any & rAny ) const;
269 
270 private:
271 #if !defined LIBO_INTERNAL_ONLY
272  // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
274  explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
276 #endif
277 };
278 
279 #if !defined LIBO_INTERNAL_ONLY
280 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
282 template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
283 template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
285 #endif
286 
287 #if !defined LIBO_INTERNAL_ONLY
288 
299 template< class C >
300 inline Any SAL_CALL makeAny( const C & value );
301 
302 template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value);
303 
304 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
305 #endif
306 
314 template<typename T> inline Any toAny(T const & value);
315 
316 template<> inline Any toAny(Any const & value);
317 
318 #if defined LIBO_INTERNAL_ONLY
319 
337 template<typename T> inline bool fromAny(Any const & any, T * value);
338 
339 template<> inline bool fromAny(Any const & any, Any * value);
340 
341 #endif
342 
343 class BaseReference;
344 
351 template< class C >
352 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
353 
354 // additionally for C++ bool:
355 template<>
356 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
357 
367 template< class C >
368 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
369 
380 template< class C >
381 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
392 template< class C >
393 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
394 
395 // additional specialized >>= and == operators
396 // bool
397 template<>
398 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
399 template<>
400 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
401 template<>
402 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
403 template<>
404 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
405 // byte
406 template<>
407 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
408 // short
409 template<>
410 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
411 template<>
412 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
413 // long
414 template<>
415 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
416 template<>
417 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
418 // hyper
419 template<>
420 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
421 template<>
422 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
423 // float
424 template<>
425 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
426 // double
427 template<>
428 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
429 // string
430 template<>
431 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
432 template<>
433 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
434 #if defined LIBO_INTERNAL_ONLY
435 template<std::size_t N>
436 inline bool SAL_CALL operator == (const Any& rAny, const rtl::OUStringLiteral<N>& value);
437 #endif
438 // type
439 template<>
440 inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
441 template<>
442 inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
443 // any
444 #if !defined LIBO_INTERNAL_ONLY
445 template<>
446 inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
447 #endif
448 // interface
449 template<>
450 inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
451 
452 }
453 }
454 }
455 }
456 
469 SAL_DEPRECATED("use cppu::UnoType")
470 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
471 {
472  return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
473 }
474 
475 #endif
476 
477 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:177
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:182
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:470
C++ class representing an IDL any.
Definition: Any.h:36
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:142
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:136
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:170
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:157
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:150
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