update dev300-m57
[ooovba.git] / comphelper / source / property / MasterPropertySetInfo.cxx
blobe09eb1d8fa0d2741e30aeb9dd9613add86a45a3a
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: MasterPropertySetInfo.cxx,v $
10 * $Revision: 1.7 $
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_comphelper.hxx"
33 #ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_
34 #include <comphelper/MasterPropertySetInfo.hxx>
35 #endif
36 #include <comphelper/TypeGeneration.hxx>
38 using ::rtl::OUString;
39 using ::comphelper::PropertyInfo;
40 using ::comphelper::GenerateCppuType;
41 using ::comphelper::MasterPropertySetInfo;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::uno::Type;
44 using ::com::sun::star::uno::Sequence;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::XInterface;
47 using ::com::sun::star::uno::RuntimeException;
48 using ::com::sun::star::beans::Property;
49 using ::com::sun::star::beans::XPropertySetInfo;
50 using ::com::sun::star::beans::UnknownPropertyException;
52 MasterPropertySetInfo::MasterPropertySetInfo()
53 throw()
57 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
58 throw()
60 add ( pMap );
63 MasterPropertySetInfo::~MasterPropertySetInfo()
64 throw()
66 PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
67 while (aIter != aEnd )
69 delete (*aIter).second;
70 aIter++;
74 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
75 throw()
77 // nCount < 0 => add all
78 // nCount == 0 => add nothing
79 // nCount > 0 => add at most nCount entries
80 if( maProperties.getLength() )
81 maProperties.realloc( 0 );
83 for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
85 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
87 #ifndef PRODUCT
88 PropertyDataHash::iterator aIter = maMap.find( aName );
89 if( aIter != maMap.end() )
90 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
91 #endif
92 maMap[aName] = new PropertyData ( nMapId, pMap );
96 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
97 throw()
99 if( maProperties.getLength() )
100 maProperties.realloc( 0 );
101 PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
103 while ( aIter != aEnd )
105 #ifndef PRODUCT
106 PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
107 if( aDebugIter != maMap.end() )
108 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
109 #endif
110 maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
111 aIter++;
115 void MasterPropertySetInfo::remove( const rtl::OUString& aName )
116 throw()
118 maMap.erase ( aName );
119 if ( maProperties.getLength() )
120 maProperties.realloc( 0 );
123 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
124 throw(::com::sun::star::uno::RuntimeException)
126 sal_Int32 nSize = maMap.size();
127 if( maProperties.getLength() != nSize )
129 maProperties.realloc ( nSize );
130 Property* pProperties = maProperties.getArray();
132 PropertyDataHash::iterator aIter = maMap.begin();
133 const PropertyDataHash::iterator aEnd = maMap.end();
134 for ( ; aIter != aEnd; ++aIter, ++pProperties)
136 PropertyInfo* pInfo = (*aIter).second->mpInfo;
138 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
139 pProperties->Handle = pInfo->mnHandle;
140 const Type* pType;
141 GenerateCppuType ( pInfo->meCppuType, pType);
142 pProperties->Type = *pType;
143 pProperties->Attributes = pInfo->mnAttributes;
146 return maProperties;
149 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
150 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
152 PropertyDataHash::iterator aIter = maMap.find( rName );
154 if ( maMap.end() == aIter )
155 throw UnknownPropertyException( rName, *this );
157 PropertyInfo *pInfo = (*aIter).second->mpInfo;
158 Property aProperty;
159 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
160 aProperty.Handle = pInfo->mnHandle;
161 const Type* pType;
162 GenerateCppuType ( pInfo->meCppuType, pType );
163 aProperty.Type = *pType;
165 aProperty.Attributes = pInfo->mnAttributes;
166 return aProperty;
169 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
170 throw(::com::sun::star::uno::RuntimeException)
172 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );