LibreOffice: com/sun/star/uno/Any.h Source File

LibreOffice LibreOffice 5.1 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 <uno/any2.h>
23 #include <typelib/typedescription.h>
24 #include <cppu/unotype.hxx>
25 #include <com/sun/star/uno/TypeClass.hdl>
26 #include <rtl/alloc.h>
27
28 namespace rtl { class OUString; }
29
30 namespace com
31 {
32 namespace sun
33 {
34 namespace star
35 {
36 namespace uno
37 {
38
39 class Type;
40
49 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Any : public uno_Any
50 {
51 public:
53 // these are here to force memory de/allocation to sal lib.
54 inline static void * SAL_CALL operator new ( size_t nSize )
55 { return ::rtl_allocateMemory( nSize ); }
56 inline static void SAL_CALL operator delete ( void * pMem )
57 { ::rtl_freeMemory( pMem ); }
58 inline static void * SAL_CALL operator new ( size_t, void * pMem )
59 { return pMem; }
60 inline static void SAL_CALL operator delete ( void *, void * )
61 {}
63
66 inline Any();
67
72 template <typename T>
73 explicit inline Any( T const & value );
75 explicit inline Any( bool value );
76
81 inline Any( const Any & rAny );
82
88 inline Any( const void * pData_, const Type & rType );
89
95 inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr );
96
102 inline Any( const void * pData_, typelib_TypeDescriptionReference * pType_ );
103
106 inline ~Any();
107
113 inline Any & SAL_CALL operator = ( const Any & rAny );
114
119 inline const Type & SAL_CALL getValueType() const
120 { return * reinterpret_cast< const Type * >( &pType ); }
125 inline typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const
126 { return pType; }
127
133 inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const
134 { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
135
140 inline TypeClass SAL_CALL getValueTypeClass() const
141 { return (TypeClass)pType->eTypeClass; }
142
147 inline ::rtl::OUString SAL_CALL getValueTypeName() const;
148
153 inline bool SAL_CALL hasValue() const
154 { return (typelib_TypeClass_VOID != pType->eTypeClass); }
155
160 inline const void * SAL_CALL getValue() const
161 { return pData; }
162
175 template <typename T>
176 inline T get() const;
177
184 inline void SAL_CALL setValue( const void * pData_, const Type & rType );
191 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ );
198 inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr );
199
203 inline void SAL_CALL clear();
204
211 inline bool SAL_CALL isExtractableTo( const Type & rType ) const;
212
219 template <typename T>
220 inline bool has() const;
221
228 inline bool SAL_CALL operator == ( const Any & rAny ) const;
235 inline bool SAL_CALL operator != ( const Any & rAny ) const;
236
237 private:
239 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
240 explicit Any(sal_uInt16) SAL_DELETED_FUNCTION;
242 };
243
245 // Forbid use with ambiguous type (sal_Unicode, sal_uInt16):
246 template<> sal_uInt16 Any::get<sal_uInt16>() const SAL_DELETED_FUNCTION;
247 template<> bool Any::has<sal_uInt16>() const SAL_DELETED_FUNCTION;
249
256 template< class C >
257 inline Any SAL_CALL makeAny( const C & value );
258
259 // additionally specialized for C++ bool
260 template<>
261 inline Any SAL_CALL makeAny( bool const & value );
262
263 template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION;
264
272 template<typename T> inline Any toAny(T const & value);
273
274 template<> inline Any toAny(Any const & value);
275
276 class BaseReference;
277
284 template< class C >
285 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
286
287 // additionally for C++ bool:
288 template<>
289 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
290
300 template< class C >
301 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
302
313 template< class C >
314 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
325 template< class C >
326 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
327
328 // additional specialized >>= and == operators
329 // bool
330 template<>
331 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
332 template<>
333 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
334 template<>
335 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
336 template<>
337 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
338 // byte
339 template<>
340 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
341 // short
342 template<>
343 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
344 template<>
345 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
346 // long
347 template<>
348 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
349 template<>
350 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
351 // hyper
352 template<>
353 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
354 template<>
355 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
356 // float
357 template<>
358 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
359 // double
360 template<>
361 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
362 // string
363 template<>
364 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
365 template<>
366 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
367 // type
368 template<>
369 inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
370 template<>
371 inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
372 // any
373 template<>
374 inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
375 // interface
376 template<>
377 inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
378
379 }
380 }
381 }
382 }
383
396 SAL_DEPRECATED("use cppu::UnoType")
397 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
398 {
399 return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
400 }
401
402 #endif
403
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Any::hasValue
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:153
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:397
com::sun::star::uno::toAny
Any toAny(Any const &value)
Definition: Any.hxx:210
com::sun::star::uno::operator>>=
bool operator>>=(const Any &rAny, Any &value)
Definition: Any.hxx:548
sal_Int8
signed char sal_Int8
Definition: types.h:53
com
Definition: types.h:389
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:408
SAL_UNUSED_PARAMETER
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:591
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Dont use, its evil.") void doit(int nPara);.
Definition: types.h:499
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:612
com::sun::star::uno::operator==
bool operator==(const Any &rAny, const BaseReference &value)
Definition: Any.hxx:561
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
any2.h
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:48
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::sun::star::uno::makeAny
Any makeAny(Any const &) SAL_DELETED_FUNCTION
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
typedescription.h
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:584
com::sun::star::uno::BaseReference
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:58
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
com::sun::star::uno::Any::getValueTypeDescription
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:133
com::sun::star::uno::Any::getValueType
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:119
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
alloc.h
com::sun::star::uno::operator<<=
void operator<<=(Any &rAny, bool const &value)
Definition: Any.hxx:224
com::sun::star::uno::Any::getValue
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:160
rtl
Definition: bootstrap.hxx:29
com::sun::star::uno::Any::getValueTypeClass
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:140
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition: Type.h:54
com::sun::star::uno::Any::getValueTypeRef
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:125
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:49