LibreOffice
LibreOffice 4.1 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  * 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 _COM_SUN_STAR_UNO_ANY_H_
20 #define _COM_SUN_STAR_UNO_ANY_H_
21 
22 #include <uno/any2.h>
24 #include <com/sun/star/uno/Type.h>
25 #include "cppu/unotype.hxx"
26 #include <rtl/alloc.h>
27 
28 
29 namespace com
30 {
31 namespace sun
32 {
33 namespace star
34 {
35 namespace uno
36 {
37 
46 class Any : public uno_Any
47 {
48 public:
50  // these are here to force memory de/allocation to sal lib.
51  inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
52  { return ::rtl_allocateMemory( nSize ); }
53  inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
54  { ::rtl_freeMemory( pMem ); }
55  inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
56  { return pMem; }
57  inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
58  {}
60 
63  inline Any() SAL_THROW(());
64 
69  template <typename T>
70  explicit inline Any( T const & value );
72  explicit inline Any( bool value );
73 
78  inline Any( const Any & rAny ) SAL_THROW(());
79 
85  inline Any( const void * pData_, const Type & rType ) SAL_THROW(());
86 
92  inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(());
93 
99  inline Any( const void * pData_, typelib_TypeDescriptionReference * pType ) SAL_THROW(());
100 
103  inline ~Any() SAL_THROW(());
104 
110  inline Any & SAL_CALL operator = ( const Any & rAny ) SAL_THROW(());
111 
116  inline const Type & SAL_CALL getValueType() const SAL_THROW(())
117  { return * reinterpret_cast< const Type * >( &pType ); }
122  inline typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const SAL_THROW(())
123  { return pType; }
124 
130  inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const SAL_THROW(())
131  { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); }
132 
137  inline TypeClass SAL_CALL getValueTypeClass() const SAL_THROW(())
138  { return (TypeClass)pType->eTypeClass; }
139 
144  inline ::rtl::OUString SAL_CALL getValueTypeName() const SAL_THROW(());
145 
150  inline sal_Bool SAL_CALL hasValue() const SAL_THROW(())
151  { return (typelib_TypeClass_VOID != pType->eTypeClass); }
152 
157  inline const void * SAL_CALL getValue() const SAL_THROW(())
158  { return pData; }
159 
160 #if ! defined(EXCEPTIONS_OFF)
161 
174  template <typename T>
175  inline T get() const;
176 #endif // ! defined(EXCEPTIONS_OFF)
177 
184  inline void SAL_CALL setValue( const void * pData_, const Type & rType ) SAL_THROW(());
191  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType ) SAL_THROW(());
198  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(());
199 
203  inline void SAL_CALL clear() SAL_THROW(());
204 
211  inline sal_Bool SAL_CALL isExtractableTo( const Type & rType ) const SAL_THROW(());
212 
219  template <typename T>
220  inline bool has() const;
221 
228  inline sal_Bool SAL_CALL operator == ( const Any & rAny ) const SAL_THROW(());
235  inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const SAL_THROW(());
236 
237 private:
238  // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
239  explicit Any( sal_uInt16 );
240 #if defined(_MSC_VER)
241  // Omitting the following private declarations leads to an internal compiler
242  // error on MSVC (version 1310).
243  // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
244 #if ! defined(EXCEPTIONS_OFF)
245  template <>
246  sal_uInt16 get<sal_uInt16>() const;
247 #endif // ! defined(EXCEPTIONS_OFF)
248  template <>
249  bool has<sal_uInt16>() const;
250 #endif // defined(_MSC_VER)
251 };
252 
259 template< class C >
260 inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(());
261 
262 // additionally specialized for C++ bool
263 template<>
264 inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(());
265 
266 class BaseReference;
267 class Type;
268 
275 template< class C >
276 inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(());
277 
278 // additionally for C++ bool:
279 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
280  SAL_THROW(());
281 
291 template< class C >
292 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(());
293 
304 template< class C >
305 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(());
316 template< class C >
317 inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(());
318 
319 // additional specialized >>= and == operators
320 // bool
321 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value ) SAL_THROW(());
322 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW(());
323 template<>
324 inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
325  SAL_THROW(());
326 template<>
327 inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value )
328  SAL_THROW(());
329 // byte
330 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value ) SAL_THROW(());
331 // short
332 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(());
333 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(());
334 // long
335 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(());
336 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(());
337 // hyper
338 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(());
339 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(());
340 // float
341 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(());
342 // double
343 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(());
344 // string
345 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(());
346 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW(());
347 // type
348 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(());
349 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW(());
350 // any
351 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(());
352 // interface
353 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW(());
354 
355 }
356 }
357 }
358 }
359 
369 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * ) SAL_THROW(())
370 {
371  return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
372 }
373 
374 #endif
375 
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Bool isExtractableTo(const Type &rType) const
Tests whether this any is extractable to a value of given type.
Definition: Any.hxx:136
Any & operator=(const Any &rAny)
Assignment operator: Sets the value of the given any.
Definition: Any.hxx:93
void * pData
pointer to value; this may point to pReserved and thus the uno_Any is not anytime mem-copyable! You m...
Definition: any2.h:49
Any()
Default constructor: Any holds no value; its type is void.
Definition: Any.hxx:39
sal_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:558
Holds a weak reference to a type description.
Definition: typedescription.h:40
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:540
bool has() const
Tests whether this any can provide a value of specified type.
Definition: Any.hxx:145
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:87
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:116
C++ class representing an IDL meta type.
Definition: Type.h:55
void clear()
Clears this any.
Definition: Any.hxx:130
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:122
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:130
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
struct _typelib_TypeDescriptionReference * pType
type of value
Definition: any2.h:44
Full type description of a type.
Definition: typedescription.h:71
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition: Any.hxx:201
sal_Bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition: Any.hxx:235
type class of void
Definition: typeclass.h:29
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:157
inline::rtl::OUString getValueTypeName() const
Gets the type name of the set value.
Definition: Any.hxx:104
C++ class representing an IDL any.
Definition: Any.h:46
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
typelib_TypeClass eTypeClass
type class of type
Definition: typedescription.h:52
sal_Bool hasValue() const
Tests if any contains a value.
Definition: Any.h:150
unsigned char sal_Bool
Definition: types.h:37
This is the binary specification of an UNO any.
Definition: any2.h:40
sal_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:547
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:176
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:137
void setValue(const void *pData_, const Type &rType)
Sets a value.
Definition: Any.hxx:109
~Any()
Destructor: Destructs any content and frees memory.
Definition: Any.hxx:87
signed char sal_Int8
Definition: types.h:42
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:369