update dev300-m58
[ooovba.git] / configmgr / source / misc / anypair.cxx
blob9b763debbf85a18cd68db30224d07fa9d7860179
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: anypair.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include <anypair.hxx>
35 #include <uno/any2.h>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/uno/Type.hxx>
39 #define CFG_PRECOND( expr ) OSL_PRECOND ( expr, "Violated Precondition: " #expr)
40 #define CFG_POSTCOND( expr ) OSL_POSTCOND( expr, "Violated Postcondition: " #expr)
42 namespace configmgr
44 namespace css = com::sun::star;
45 namespace uno = css::uno;
47 // -----------------------------------------------------------------------------
48 static inline bool impl_Any_hasValue(uno_Any const * _pData)
49 { return (typelib_TypeClass_VOID != _pData->pType->eTypeClass); }
51 // -----------------------------------------------------------------------------
52 static inline bool impl_Any_storesData(uno_Any const * _pData)
54 const void * pAnyData = _pData->pData;
56 const bool bSelfReferential = (pAnyData == &_pData->pReserved);
57 OSL_ENSURE( bSelfReferential == ( _pData <= pAnyData && pAnyData < _pData+1 ),
58 "uno_Any layout changed: Unreckognized self-referentiality" );
60 return bSelfReferential;
63 // -----------------------------------------------------------------------------
64 static inline void * impl_getDataPointer(const void * const * _pAnyPairData)
66 const void * const pResult = *_pAnyPairData;
68 return const_cast<void*>(pResult);
71 // -----------------------------------------------------------------------------
72 static inline void * impl_getData(const void * const * _pAnyPairData, bool _bStoredData)
74 const void * const pResult = _bStoredData ? _pAnyPairData : *_pAnyPairData;
76 return const_cast<void*>(pResult);
79 // -----------------------------------------------------------------------------
80 static inline void impl_setDataPointer(const void * * _pAnyPairData, void* _pData)
82 *_pAnyPairData = _pData;
84 // -----------------------------------------------------------------------------
85 static const unsigned SHIFT_DATA_FLAG = 4;
86 // -----------------------------------------------------------------------------
87 static
88 inline void impl_state_setState(sal_uInt8* _pState, sal_uInt8 _nState, sal_uInt8 _nSelect)
90 sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG);
91 OSL_ENSURE( (_nState & nSelectMask) == _nState, "State specified does not belong to the selector");
93 *_pState &= ~nSelectMask;
94 *_pState |= _nState;
97 // -----------------------------------------------------------------------------
98 static
99 inline void impl_state_setNull(sal_uInt8* _pState, sal_uInt8 _nSelect)
101 sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG);
102 *_pState &= ~nSelectMask;
105 // -----------------------------------------------------------------------------
106 static inline
107 void impl_state_setData(sal_uInt8* _pState, sal_uInt8 _nSelect)
109 sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG);
110 *_pState |= nSelectMask;
113 // -----------------------------------------------------------------------------
114 static inline
115 void impl_state_setValue(sal_uInt8* _pState, sal_uInt8 _nSelect, bool _bStoresData)
117 *_pState |= _nSelect;
119 _nSelect <<= SHIFT_DATA_FLAG;
120 if (_bStoresData)
121 *_pState |= _nSelect;
122 else
123 *_pState &= ~_nSelect;
126 // -----------------------------------------------------------------------------
127 static
128 inline bool impl_state_isNull(sal_uInt8 const _nState, sal_uInt8 _nSelect)
130 return 0 == (_nState & _nSelect);
133 // -----------------------------------------------------------------------------
134 static
135 inline bool impl_state_isData(sal_uInt8 const _nState, sal_uInt8 _nSelect)
137 return 0 != (_nState & (_nSelect<<SHIFT_DATA_FLAG));
141 // -----------------------------------------------------------------------------
142 static
143 typelib_TypeDescriptionReference * impl_getVoidType()
145 static const uno::Type aNullType;
146 return aNullType.getTypeLibType();
149 // -----------------------------------------------------------------------------
150 static inline
151 void anypair_type_construct_Desc( cfgmgr_AnyPair_Desc* _pAnyPairDesc,
152 typelib_TypeDescriptionReference * _pType)
154 _pAnyPairDesc->nState = 0;
155 _pAnyPairDesc->pType = _pType;
157 typelib_typedescriptionreference_acquire( _pAnyPairDesc->pType );
160 // -----------------------------------------------------------------------------
161 static inline
162 void anypair_default_construct_Desc( cfgmgr_AnyPair_Desc* _pAnyPairDesc )
164 anypair_type_construct_Desc(_pAnyPairDesc, impl_getVoidType());
167 // -----------------------------------------------------------------------------
168 static inline
169 void anypair_empty_set_Data( const void ** _pAnyPairData )
171 impl_setDataPointer(_pAnyPairData, NULL);
172 OSL_DEBUG_ONLY( impl_setDataPointer(_pAnyPairData, reinterpret_cast<void*>(0xdeadbeef)) );
175 // -----------------------------------------------------------------------------
176 // returns a state for the specified selector
177 static inline
178 sal_uInt8 anypair_any_set_Data( const void ** _pAnyPairData,
179 sal_uInt8 _nSelect,
180 uno_Any const *_pUnoAny)
182 sal_uInt8 nState = 0;
184 bool bValue = impl_Any_hasValue(_pUnoAny);
185 if (bValue)
187 uno_Any aTmpAny;
188 uno_type_any_construct(&aTmpAny, _pUnoAny->pData, _pUnoAny->pType, reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire ));
190 bool bData = impl_Any_storesData(&aTmpAny);
192 impl_setDataPointer(_pAnyPairData, bData ? aTmpAny.pReserved : aTmpAny.pData);
194 impl_state_setValue(&nState, _nSelect, bData);
196 else
197 anypair_empty_set_Data(_pAnyPairData);
199 return nState;
202 // -----------------------------------------------------------------------------
203 static inline
204 sal_uInt8 anypair_copy_Data( const void ** _pAnyPairData,
205 sal_uInt8 _nSelect,
206 cfgmgr_AnyPair_Desc const* _pAnyPairDescFrom,
207 const void * const* _pAnyPairDataFrom )
209 sal_uInt8 nState = 0;
211 if (impl_state_isNull(_pAnyPairDescFrom->nState, _nSelect))
213 anypair_empty_set_Data(_pAnyPairData);
216 else
218 bool bOldIsData = impl_state_isData(_pAnyPairDescFrom->nState, _nSelect);
220 void * pFromData = impl_getData(_pAnyPairDataFrom, bOldIsData);
222 uno_Any aTmpAny;
223 uno_type_any_construct(&aTmpAny, pFromData, _pAnyPairDescFrom->pType, reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire ));
225 bool bNewIsData = impl_Any_storesData(&aTmpAny);
226 OSL_ENSURE(bOldIsData == bNewIsData, "INFO [safe to ignore]: Copy of uno_Any changes directness !?");
228 impl_setDataPointer(_pAnyPairData, bNewIsData ? aTmpAny.pReserved : aTmpAny.pData);
230 impl_state_setValue(&nState, _nSelect, bNewIsData);
233 return nState;
236 // -----------------------------------------------------------------------------
237 static inline
238 void anypair_destruct_Desc(cfgmgr_AnyPair_Desc* _pAnyPairDesc)
240 typelib_typedescriptionreference_release( _pAnyPairDesc->pType );
241 OSL_DEBUG_ONLY(_pAnyPairDesc->nState = 0xDD);
242 OSL_DEBUG_ONLY(_pAnyPairDesc->pType = (typelib_TypeDescriptionReference*)0xdeadbeef);
245 // -----------------------------------------------------------------------------
246 static
247 void anypair_clear_Data( const void ** _pAnyPairData,
248 sal_uInt8 _nSelect,
249 cfgmgr_AnyPair_Desc const* _pAnyPairDesc
252 if (!impl_state_isNull(_pAnyPairDesc->nState,_nSelect))
254 uno_Any aTmpAny;
255 aTmpAny.pType = _pAnyPairDesc->pType;
257 if (impl_state_isData(_pAnyPairDesc->nState,_nSelect))
259 aTmpAny.pReserved = impl_getDataPointer(_pAnyPairData);
260 aTmpAny.pData = &aTmpAny.pReserved;
262 else
264 aTmpAny.pReserved = NULL;
265 aTmpAny.pData = impl_getDataPointer(_pAnyPairData);
268 typelib_typedescriptionreference_acquire( aTmpAny.pType );
269 uno_any_destruct(&aTmpAny, reinterpret_cast< uno_ReleaseFunc >( uno::cpp_release ));
271 impl_setDataPointer(_pAnyPairData, NULL);
272 OSL_DEBUG_ONLY(impl_setDataPointer(_pAnyPairData, reinterpret_cast<void*>(0xDeadBeef)));
276 // -----------------------------------------------------------------------------
277 static
278 void anypair_Data_fill_Any( uno_Any* _pUnoAny,
279 cfgmgr_AnyPair_Desc const* _pAnyPairDesc,
280 const void * const* _pAnyPairData,
281 sal_uInt8 _nSelect )
283 if (impl_state_isNull(_pAnyPairDesc->nState,_nSelect))
285 _pUnoAny->pType = impl_getVoidType();
286 _pUnoAny->pReserved = NULL;
287 _pUnoAny->pData = NULL;
289 else if (impl_state_isData(_pAnyPairDesc->nState,_nSelect))
291 _pUnoAny->pType = _pAnyPairDesc->pType;
292 _pUnoAny->pReserved = impl_getDataPointer(_pAnyPairData);
293 _pUnoAny->pData = &_pUnoAny->pReserved;
295 else
297 _pUnoAny->pType = _pAnyPairDesc->pType;
298 _pUnoAny->pReserved = NULL;
299 _pUnoAny->pData = impl_getDataPointer(_pAnyPairData);
303 // -----------------------------------------------------------------------------
304 static inline
305 typelib_TypeDescriptionReference*
306 anypair_test_assigned_type( typelib_TypeDescriptionReference* _pOldType,
307 typelib_TypeDescriptionReference* _pNewType)
309 typelib_TypeDescriptionReference* pResult;
310 if ( _pNewType->eTypeClass == typelib_TypeClass_VOID)
311 pResult = _pOldType;
313 else if (_pOldType->eTypeClass == typelib_TypeClass_VOID || _pOldType->eTypeClass == typelib_TypeClass_ANY )
314 pResult = _pNewType;
316 else if ( typelib_typedescriptionreference_equals(_pOldType,_pNewType) )
317 pResult = _pOldType;
319 else
320 pResult = NULL;
322 return pResult;
325 // -----------------------------------------------------------------------------
326 static
327 sal_Bool anypair_any_assign_Data( cfgmgr_AnyPair_Desc* _pAnyPairDesc,
328 const void ** _pAnyPairData,
329 sal_uInt8 _nSelect,
330 uno_Any const *_pUnoAny)
332 typelib_TypeDescriptionReference* pOldType = _pAnyPairDesc->pType;
333 typelib_TypeDescriptionReference* pNewType = anypair_test_assigned_type(pOldType,_pUnoAny->pType);
335 if (pNewType != NULL)
337 uno_Any aTmpAny;
338 anypair_Data_fill_Any(&aTmpAny,_pAnyPairDesc,_pAnyPairData,_nSelect);
340 typelib_typedescriptionreference_acquire(aTmpAny.pType);
342 uno_type_any_assign(&aTmpAny,
343 _pUnoAny->pData,
344 _pUnoAny->pType,
345 reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire ),
346 reinterpret_cast< uno_AcquireFunc >( uno::cpp_release ));
348 sal_uInt8 nNewState = anypair_any_set_Data(_pAnyPairData,_nSelect,&aTmpAny);
349 impl_state_setState(&_pAnyPairDesc->nState, nNewState, _nSelect);
351 uno_any_destruct(
352 &aTmpAny,
353 reinterpret_cast< uno_ReleaseFunc >(uno::cpp_release));
355 if (pNewType != pOldType)
357 typelib_typedescriptionreference_acquire(pNewType);
358 typelib_typedescriptionreference_release(pOldType);
359 _pAnyPairDesc->pType = pNewType;
362 CFG_POSTCOND( cfgmgr_AnyPair_isNull(_pAnyPairDesc,_nSelect) == !impl_Any_hasValue(_pUnoAny) );
363 CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPairDesc->pType,pNewType) );
365 else
366 OSL_ENSURE(false, "anypair_assign_XXX(): Cannot assign - Type mismatch");
368 return (pNewType != NULL);
371 // -----------------------------------------------------------------------------
372 // -----------------------------------------------------------------------------
373 void anypair_construct_default(cfgmgr_AnyPair * _pAnyPair)
375 CFG_PRECOND( _pAnyPair != NULL );
377 anypair_default_construct_Desc(&_pAnyPair->desc);
378 anypair_empty_set_Data(&_pAnyPair->first);
379 anypair_empty_set_Data(&_pAnyPair->second);
381 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) );
382 CFG_POSTCOND( cfgmgr_AnyPair_isEmpty(&_pAnyPair->desc) );
385 // -----------------------------------------------------------------------------
386 void anypair_construct_type(cfgmgr_AnyPair * _pAnyPair, typelib_TypeDescriptionReference* _pType)
388 CFG_PRECOND( _pAnyPair != NULL );
389 CFG_PRECOND( _pType != NULL );
391 anypair_type_construct_Desc(&_pAnyPair->desc, _pType);
392 anypair_empty_set_Data(&_pAnyPair->first);
393 anypair_empty_set_Data(&_pAnyPair->second);
395 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) );
396 CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pType) );
399 // -----------------------------------------------------------------------------
400 void anypair_construct_first(cfgmgr_AnyPair * _pAnyPair, uno_Any const *_pUnoAny)
402 CFG_PRECOND( _pAnyPair != NULL );
403 CFG_PRECOND( _pUnoAny != NULL );
405 anypair_type_construct_Desc(&_pAnyPair->desc, _pUnoAny->pType);
407 _pAnyPair->desc.nState = anypair_any_set_Data (&_pAnyPair->first, cfgmgr_SELECT_FIRST, _pUnoAny);
409 anypair_empty_set_Data(&_pAnyPair->second);
411 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) == !impl_Any_hasValue(_pUnoAny) );
412 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) );
413 CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pUnoAny ->pType) );
416 // -----------------------------------------------------------------------------
417 void anypair_construct_second(cfgmgr_AnyPair * _pAnyPair, uno_Any const *_pUnoAny)
419 CFG_PRECOND( _pAnyPair != NULL );
420 CFG_PRECOND( _pUnoAny != NULL );
422 anypair_type_construct_Desc(&_pAnyPair->desc, _pUnoAny->pType);
424 anypair_empty_set_Data(&_pAnyPair->first);
426 _pAnyPair->desc.nState = anypair_any_set_Data (&_pAnyPair->second, cfgmgr_SELECT_SECOND, _pUnoAny);
428 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) );
429 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) == !impl_Any_hasValue(_pUnoAny) );
430 CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pUnoAny ->pType) );
433 // -----------------------------------------------------------------------------
434 // if type not equal, you got false and the struct contains undefined values
435 sal_Bool anypair_construct(cfgmgr_AnyPair * _pAnyPair, uno_Any const * _pFirstAny, uno_Any const *_pSecondAny)
437 CFG_PRECOND( _pAnyPair != NULL );
438 CFG_PRECOND( _pFirstAny != NULL );
439 CFG_PRECOND( _pSecondAny != NULL );
441 bool bHasFirst = impl_Any_hasValue(_pFirstAny);
442 bool bHasSecond = impl_Any_hasValue(_pSecondAny);
444 if (bHasFirst && bHasSecond)
446 if ( ! typelib_typedescriptionreference_equals(_pFirstAny->pType,_pSecondAny->pType))
448 OSL_ENSURE(false, "anypair_construct(): Cannot construct - Different types");
449 return false;
453 anypair_type_construct_Desc(&_pAnyPair->desc, bHasFirst ? _pFirstAny->pType : _pSecondAny->pType);
455 sal_uInt8 nState = 0;
457 nState |= anypair_any_set_Data (&_pAnyPair->first, cfgmgr_SELECT_FIRST, _pFirstAny);
458 nState |= anypair_any_set_Data (&_pAnyPair->second, cfgmgr_SELECT_SECOND, _pSecondAny);
460 _pAnyPair->desc.nState = nState;
462 CFG_POSTCOND((bHasFirst || bHasSecond) == !cfgmgr_AnyPair_isEmpty(&_pAnyPair->desc) );
463 CFG_POSTCOND( bHasFirst == !cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) );
464 CFG_POSTCOND( bHasSecond == !cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) );
465 CFG_POSTCOND( !bHasFirst || typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pFirstAny ->pType) );
466 CFG_POSTCOND( !bHasSecond || typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pSecondAny->pType) );
468 return true;
471 // -----------------------------------------------------------------------------
472 void anypair_copy_construct(cfgmgr_AnyPair* _pAnyPair, cfgmgr_AnyPair const * _pAnyPairFrom)
474 CFG_PRECOND( _pAnyPair != NULL );
475 CFG_PRECOND( _pAnyPairFrom != NULL );
477 anypair_type_construct_Desc(&_pAnyPair->desc, _pAnyPairFrom->desc.pType);
479 sal_uInt8 nState = 0;
481 nState |= anypair_copy_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST,
482 &_pAnyPairFrom->desc, &_pAnyPairFrom->first );
484 nState |= anypair_copy_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND,
485 &_pAnyPairFrom->desc, &_pAnyPairFrom->second );
487 _pAnyPair->desc.nState = nState;
489 OSL_ENSURE(_pAnyPairFrom->desc.nState == nState, "Unexpected: Copy changes state");
490 CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pAnyPairFrom->desc.pType) );
493 // -----------------------------------------------------------------------------
494 void anypair_destruct(cfgmgr_AnyPair* _pAnyPair)
496 CFG_PRECOND( _pAnyPair != NULL );
498 anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc);
499 anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc);
500 anypair_destruct_Desc(&_pAnyPair->desc );
503 // -----------------------------------------------------------------------------
504 sal_Bool anypair_assign_first(cfgmgr_AnyPair* _pAnyPair, uno_Any const * _pUnoAny)
506 CFG_PRECOND( _pAnyPair != NULL );
507 CFG_PRECOND( _pUnoAny != NULL );
509 return anypair_any_assign_Data(&_pAnyPair->desc, &_pAnyPair->first, cfgmgr_SELECT_FIRST, _pUnoAny);
512 // -----------------------------------------------------------------------------
513 sal_Bool anypair_assign_second(cfgmgr_AnyPair* _pAnyPair, uno_Any const * _pUnoAny)
515 CFG_PRECOND( _pAnyPair != NULL );
516 CFG_PRECOND( _pUnoAny != NULL );
518 return anypair_any_assign_Data(&_pAnyPair->desc, &_pAnyPair->second, cfgmgr_SELECT_SECOND, _pUnoAny);
521 // -----------------------------------------------------------------------------
522 void anypair_assign(cfgmgr_AnyPair* _pAnyPair, cfgmgr_AnyPair const * _pAnyPairFrom)
524 if (_pAnyPair != _pAnyPairFrom)
526 anypair_destruct(_pAnyPair);
527 anypair_copy_construct(_pAnyPair, _pAnyPairFrom);
531 // -----------------------------------------------------------------------------
532 void anypair_clear_first(cfgmgr_AnyPair* _pAnyPair)
534 CFG_PRECOND( _pAnyPair != NULL );
536 anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc);
537 impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_FIRST);
539 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) );
542 // -----------------------------------------------------------------------------
543 void anypair_clear_second(cfgmgr_AnyPair* _pAnyPair)
545 CFG_PRECOND( _pAnyPair != NULL );
547 anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc );
548 impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_SECOND);
550 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) );
553 // -----------------------------------------------------------------------------
554 void anypair_clear_values(cfgmgr_AnyPair* _pAnyPair)
556 CFG_PRECOND( _pAnyPair != NULL );
558 anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc);
559 anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc );
560 impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_BOTH);
562 CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) );
565 // -----------------------------------------------------------------------------
566 // -----------------------------------------------------------------------------
567 static
568 inline
569 uno::Any anypair_Data_toAny(cfgmgr_AnyPair_Desc const* _pAnyPairDesc,
570 const void * const* _pAnyPairData,
571 sal_uInt8 _nSelect)
573 uno_Any aTmpAny;
574 anypair_Data_fill_Any(&aTmpAny,_pAnyPairDesc,_pAnyPairData,_nSelect);
576 return uno::Any( aTmpAny.pData, aTmpAny.pType );
579 // -----------------------------------------------------------------------------
580 AnyPair::AnyPair(uno::Type const& _aType) // one Type, any's are null
582 anypair_construct_type(&m_aAnyPair, _aType.getTypeLibType());
585 // -----------------------------------------------------------------------------
586 AnyPair::AnyPair(uno::Any const& _aAny, SelectMember _select)
588 switch (_select)
590 case SELECT_FIRST: anypair_construct_first(&m_aAnyPair,&_aAny); break;
591 case SELECT_SECOND: anypair_construct_second(&m_aAnyPair,&_aAny); break;
592 case SELECT_BOTH: OSL_VERIFY( anypair_construct(&m_aAnyPair,&_aAny,&_aAny) ); break;
594 default: OSL_ENSURE(false, "AnyPair: Unknown member selector");
595 anypair_construct_default(&m_aAnyPair); break;
599 // -----------------------------------------------------------------------------
600 AnyPair::AnyPair(uno::Any const& _aAny, uno::Any const& _aAny2) SAL_THROW((lang::IllegalArgumentException))
602 if (!anypair_construct(&m_aAnyPair,&_aAny, &_aAny2))
604 throw lang::IllegalArgumentException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AnyPair: Type mismatch in constructor.")),NULL,-1);
608 // -----------------------------------------------------------------------------
609 // copy-ctor
610 AnyPair::AnyPair(AnyPair const& _aOther)
612 anypair_copy_construct(&m_aAnyPair, &_aOther.m_aAnyPair);
615 // -----------------------------------------------------------------------------
616 // assign operator
617 AnyPair& AnyPair::operator=(AnyPair const& _aOther)
619 anypair_assign(&m_aAnyPair, &_aOther.m_aAnyPair);
620 return *this;
623 // -----------------------------------------------------------------------------
624 // d-tor
625 AnyPair::~AnyPair()
627 anypair_destruct(&m_aAnyPair);
631 // -----------------------------------------------------------------------------
632 sal_Bool AnyPair::setFirst(uno::Any const& _aAny)
634 return anypair_assign_first(&m_aAnyPair,&_aAny);
637 // -----------------------------------------------------------------------------
638 sal_Bool AnyPair::setSecond(uno::Any const& _aAny)
640 return anypair_assign_second(&m_aAnyPair,&_aAny);
643 // -----------------------------------------------------------------------------
644 void AnyPair::clear(SelectMember _select)
646 switch (_select)
648 case SELECT_FIRST: anypair_clear_first(&m_aAnyPair); break;
649 case SELECT_SECOND: anypair_clear_second(&m_aAnyPair); break;
650 case SELECT_BOTH: anypair_clear_values(&m_aAnyPair); break;
652 default: OSL_ENSURE(false, "AnyPair: Unknown member selector");
653 break;
657 // -----------------------------------------------------------------------------
658 uno::Type AnyPair::getValueType() const
660 return uno::Type(m_aAnyPair.desc.pType);
663 // -----------------------------------------------------------------------------
664 uno::Any AnyPair::getFirst() const
666 return anypair_Data_toAny( &m_aAnyPair.desc, &m_aAnyPair.first, cfgmgr_SELECT_FIRST );
668 // -----------------------------------------------------------------------------
669 uno::Any AnyPair::getSecond() const
671 return anypair_Data_toAny( &m_aAnyPair.desc, &m_aAnyPair.second, cfgmgr_SELECT_SECOND );
674 // -----------------------------------------------------------------------------
675 uno::Any AnyPair::getValue(SelectMember _select) const
677 switch (_select)
679 case SELECT_FIRST: return getFirst();
680 case SELECT_SECOND: return getSecond();
682 default: OSL_ENSURE(false, "AnyPair: Unknown member selector");
683 case SELECT_BOTH: OSL_ENSURE(false, "AnyPair: Cannot get value - Invalid selector");
684 return uno::Any();
688 // -----------------------------------------------------------------------------
690 } // namespace