LibreOffice
LibreOffice 4.2 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 INCLUDED_COM_SUN_STAR_UNO_ANY_H
20 #define INCLUDED_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 SAL_WARN_UNUSED 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 
172  template <typename T>
173  inline T get() const;
174 
181  inline void SAL_CALL setValue( const void * pData_, const Type & rType ) SAL_THROW(());
188  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType ) SAL_THROW(());
195  inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(());
196 
200  inline void SAL_CALL clear() SAL_THROW(());
201 
208  inline sal_Bool SAL_CALL isExtractableTo( const Type & rType ) const SAL_THROW(());
209 
216  template <typename T>
217  inline bool has() const;
218 
225  inline sal_Bool SAL_CALL operator == ( const Any & rAny ) const SAL_THROW(());
232  inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const SAL_THROW(());
233 
234 private:
235  // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
236  explicit Any( sal_uInt16 );
237 #if defined(_MSC_VER)
238  // Omitting the following private declarations leads to an internal compiler
239  // error on MSVC (version 1310).
240  // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
241  template <>
242  sal_uInt16 get<sal_uInt16>() const;
243  template <>
244  bool has<sal_uInt16>() const;
245 #endif // defined(_MSC_VER)
246 };
247 
254 template< class C >
255 inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(());
256 
257 // additionally specialized for C++ bool
258 template<>
259 inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(());
260 
261 class BaseReference;
262 class Type;
263 
270 template< class C >
271 inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(());
272 
273 // additionally for C++ bool:
274 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
275  SAL_THROW(());
276 
286 template< class C >
287 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(());
288 
299 template< class C >
300 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(());
311 template< class C >
312 inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(());
313 
314 // additional specialized >>= and == operators
315 // bool
316 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value ) SAL_THROW(());
317 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW(());
318 template<>
319 inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
320  SAL_THROW(());
321 template<>
322 inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value )
323  SAL_THROW(());
324 // byte
325 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value ) SAL_THROW(());
326 // short
327 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(());
328 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(());
329 // long
330 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(());
331 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(());
332 // hyper
333 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(());
334 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(());
335 // float
336 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(());
337 // double
338 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(());
339 // string
340 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(());
341 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW(());
342 // type
343 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(());
344 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW(());
345 // any
346 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(());
347 // interface
348 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW(());
349 
350 }
351 }
352 }
353 }
354 
364 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any * ) SAL_THROW(())
365 {
366  return ::cppu::UnoType< ::com::sun::star::uno::Any >::get();
367 }
368 
369 #endif
370 
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:565
Holds a weak reference to a type description.
Definition: typedescription.h:40
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:82
const Type & getValueType() const
Gets the type of the set value.
Definition: Any.h:116
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:570
C++ class representing an IDL meta type.
Definition: Type.h:55
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
typelib_TypeDescriptionReference * getValueTypeRef() const
Gets the type of the set value.
Definition: Any.h:122
void getValueTypeDescription(typelib_TypeDescription **ppTypeDescr) const
Gets the type description of the set value.
Definition: Any.h:130
Full type description of a type.
Definition: typedescription.h:71
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:591
void operator<<=(Any &rAny, const C &value)
Template binary <<= operator to set the value of an any.
Definition: Any.hxx:208
sal_Bool operator>>=(const Any &rAny, C &value)
Template binary >>= operator to assign a value from an any.
Definition: Any.hxx:242
const void * getValue() const
Gets a pointer to the set value.
Definition: Any.h:157
C++ class representing an IDL any.
Definition: Any.h:46
typelib_TypeClass eTypeClass
type class of type
Definition: typedescription.h:52
unsigned char sal_Bool
Definition: types.h:46
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:554
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:183
TypeClass getValueTypeClass() const
Gets the type class of the set value.
Definition: Any.h:137
signed char sal_Int8
Definition: types.h:51
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
type class of void
Definition: typeclass.h:29
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
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:364
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:358