merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / property / ChainablePropertySetInfo.cxx
blob6660517ef97ee344fdeee58d3373eb4b311410d2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/ChainablePropertySetInfo.hxx>
31 #include <comphelper/TypeGeneration.hxx>
33 using ::rtl::OUString;
34 using ::comphelper::PropertyInfo;
35 using ::comphelper::GenerateCppuType;
36 using ::comphelper::ChainablePropertySetInfo;
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::uno::Type;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::XInterface;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::beans::Property;
44 using ::com::sun::star::beans::XPropertySetInfo;
45 using ::com::sun::star::beans::UnknownPropertyException;
47 ChainablePropertySetInfo::ChainablePropertySetInfo()
48 throw()
52 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
53 throw()
55 add ( pMap );
58 ChainablePropertySetInfo::~ChainablePropertySetInfo()
59 throw()
63 void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
64 throw()
66 // nCount < 0 => add all
67 // nCount == 0 => add nothing
68 // nCount > 0 => add at most nCount entries
69 if( maProperties.getLength() )
70 maProperties.realloc( 0 );
72 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
74 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
76 #ifdef DBG_UTIL
77 PropertyInfoHash::iterator aIter = maMap.find( aName );
78 if( aIter != maMap.end() )
79 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
80 #endif
81 maMap[aName] = pMap++;
85 void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
86 throw()
88 maMap.erase ( aName );
89 if ( maProperties.getLength() )
90 maProperties.realloc( 0 );
93 Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
94 throw(::com::sun::star::uno::RuntimeException)
96 sal_Int32 nSize = maMap.size();
97 if( maProperties.getLength() != nSize )
99 maProperties.realloc ( nSize );
100 Property* pProperties = maProperties.getArray();
102 PropertyInfoHash::iterator aIter = maMap.begin();
103 const PropertyInfoHash::iterator aEnd = maMap.end();
104 for ( ; aIter != aEnd; ++aIter, ++pProperties)
106 PropertyInfo* pInfo = (*aIter).second;
108 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
109 pProperties->Handle = pInfo->mnHandle;
110 const Type* pType;
111 GenerateCppuType ( pInfo->meCppuType, pType);
112 pProperties->Type = *pType;
113 pProperties->Attributes = pInfo->mnAttributes;
116 return maProperties;
119 Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
120 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
122 PropertyInfoHash::iterator aIter = maMap.find( rName );
124 if ( maMap.end() == aIter )
125 throw UnknownPropertyException( rName, *this );
127 PropertyInfo *pInfo = (*aIter).second;
128 Property aProperty;
129 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
130 aProperty.Handle = pInfo->mnHandle;
131 const Type* pType = &aProperty.Type;
132 GenerateCppuType ( pInfo->meCppuType, pType );
133 aProperty.Type = *pType;
134 aProperty.Attributes = pInfo->mnAttributes;
135 return aProperty;
138 sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
139 throw(::com::sun::star::uno::RuntimeException)
141 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );