CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / comphelper / source / property / MasterPropertySetInfo.cxx
blob57cf22b77508820a4e71a2e28d8e3a9e77f54427
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 #ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_
31 #include <comphelper/MasterPropertySetInfo.hxx>
32 #endif
33 #include <comphelper/TypeGeneration.hxx>
35 using ::rtl::OUString;
36 using ::comphelper::PropertyInfo;
37 using ::comphelper::GenerateCppuType;
38 using ::comphelper::MasterPropertySetInfo;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::uno::Type;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::XInterface;
44 using ::com::sun::star::uno::RuntimeException;
45 using ::com::sun::star::beans::Property;
46 using ::com::sun::star::beans::XPropertySetInfo;
47 using ::com::sun::star::beans::UnknownPropertyException;
49 MasterPropertySetInfo::MasterPropertySetInfo()
50 throw()
54 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
55 throw()
57 add ( pMap );
60 MasterPropertySetInfo::~MasterPropertySetInfo()
61 throw()
63 PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
64 while (aIter != aEnd )
66 delete (*aIter).second;
67 aIter++;
71 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
72 throw()
74 // nCount < 0 => add all
75 // nCount == 0 => add nothing
76 // nCount > 0 => add at most nCount entries
77 if( maProperties.getLength() )
78 maProperties.realloc( 0 );
80 for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
82 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
84 #ifdef DBG_UTIL
85 PropertyDataHash::iterator aIter = maMap.find( aName );
86 if( aIter != maMap.end() )
87 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
88 #endif
89 maMap[aName] = new PropertyData ( nMapId, pMap );
93 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
94 throw()
96 if( maProperties.getLength() )
97 maProperties.realloc( 0 );
98 PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
100 while ( aIter != aEnd )
102 #ifdef DBG_UTIL
103 PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
104 if( aDebugIter != maMap.end() )
105 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
106 #endif
107 maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
108 aIter++;
112 void MasterPropertySetInfo::remove( const rtl::OUString& aName )
113 throw()
115 maMap.erase ( aName );
116 if ( maProperties.getLength() )
117 maProperties.realloc( 0 );
120 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
121 throw(::com::sun::star::uno::RuntimeException)
123 sal_Int32 nSize = maMap.size();
124 if( maProperties.getLength() != nSize )
126 maProperties.realloc ( nSize );
127 Property* pProperties = maProperties.getArray();
129 PropertyDataHash::iterator aIter = maMap.begin();
130 const PropertyDataHash::iterator aEnd = maMap.end();
131 for ( ; aIter != aEnd; ++aIter, ++pProperties)
133 PropertyInfo* pInfo = (*aIter).second->mpInfo;
135 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
136 pProperties->Handle = pInfo->mnHandle;
137 const Type* pType;
138 GenerateCppuType ( pInfo->meCppuType, pType);
139 pProperties->Type = *pType;
140 pProperties->Attributes = pInfo->mnAttributes;
143 return maProperties;
146 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
147 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
149 PropertyDataHash::iterator aIter = maMap.find( rName );
151 if ( maMap.end() == aIter )
152 throw UnknownPropertyException( rName, *this );
154 PropertyInfo *pInfo = (*aIter).second->mpInfo;
155 Property aProperty;
156 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
157 aProperty.Handle = pInfo->mnHandle;
158 const Type* pType;
159 GenerateCppuType ( pInfo->meCppuType, pType );
160 aProperty.Type = *pType;
162 aProperty.Attributes = pInfo->mnAttributes;
163 return aProperty;
166 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
167 throw(::com::sun::star::uno::RuntimeException)
169 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );