LibreOffice
LibreOffice 4.4 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>
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 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 ); }
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 class BaseReference;
264 
271 template< class C >
272 inline void SAL_CALL operator <<= ( Any & rAny, const C & value );
273 
274 // additionally for C++ bool:
275 template<>
276 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value );
277 
287 template< class C >
288 inline bool SAL_CALL operator >>= ( const Any & rAny, C & value );
289 
300 template< class C >
301 inline bool SAL_CALL operator == ( const Any & rAny, const C & value );
312 template< class C >
313 inline bool SAL_CALL operator != ( const Any & rAny, const C & value );
314 
315 // additional specialized >>= and == operators
316 // bool
317 template<>
318 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value );
319 template<>
320 inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value );
321 template<>
322 inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value );
323 template<>
324 inline bool SAL_CALL operator == ( Any const & rAny, bool const & value );
325 // byte
326 template<>
327 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value );
328 // short
329 template<>
330 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value );
331 template<>
332 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value );
333 // long
334 template<>
335 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value );
336 template<>
337 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value );
338 // hyper
339 template<>
340 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value );
341 template<>
342 inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value );
343 // float
344 template<>
345 inline bool SAL_CALL operator >>= ( const Any & rAny, float & value );
346 // double
347 template<>
348 inline bool SAL_CALL operator >>= ( const Any & rAny, double & value );
349 // string
350 template<>
351 inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value );
352 template<>
353 inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value );
354 // type
355 template<>
356 inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value );
357 template<>
358 inline bool SAL_CALL operator == ( const Any & rAny, const Type & value );
359 // any
360 template<>
361 inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value );
362 // interface
363 template<>
364 inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value );
365 
366 }
367 }
368 }
369 }
370 
380 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * )
381 {
382  return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
383 }
384 
385 #endif
386 
387 /* 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:563
unsigned char sal_Bool
Definition: types.h:48
type class of void
Definition: typeclass.h:29
Definition: types.h:375
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:160
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:133
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
Definition: bootstrap.hxx:24
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:567
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:380
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:140
Holds a weak reference to a type description.
Definition: typedescription.h:40
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:394
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:574
C++ class representing an IDL meta type.
Definition: Type.h:54
bool hasValue() const
Tests if any contains a value.
Definition: Any.h:153
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
signed char sal_Int8
Definition: types.h:53
C++ class representing an IDL any.
Definition: Any.h:49
Full type description of a type.
Definition: typedescription.h:71
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:57
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:125
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:119
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:178
This is the binary specification of an UNO any.
Definition: any2.h:40
typelib_TypeClass eTypeClass
type class of type
Definition: typedescription.h:52
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:588