1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*dde7d3faSAndrew Rist * distributed with this work for additional information
6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at
10*dde7d3faSAndrew Rist *
11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*dde7d3faSAndrew Rist *
13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the
17*dde7d3faSAndrew Rist * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist * under the License.
19*dde7d3faSAndrew Rist *
20*dde7d3faSAndrew Rist *************************************************************/
21*dde7d3faSAndrew Rist
22*dde7d3faSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_
27cdf0e10cSrcweir #include <comphelper/MasterPropertySetInfo.hxx>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <comphelper/TypeGeneration.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir using ::rtl::OUString;
32cdf0e10cSrcweir using ::comphelper::PropertyInfo;
33cdf0e10cSrcweir using ::comphelper::GenerateCppuType;
34cdf0e10cSrcweir using ::comphelper::MasterPropertySetInfo;
35cdf0e10cSrcweir using ::com::sun::star::uno::Any;
36cdf0e10cSrcweir using ::com::sun::star::uno::Type;
37cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
38cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
39cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
40cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
41cdf0e10cSrcweir using ::com::sun::star::beans::Property;
42cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo;
43cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException;
44cdf0e10cSrcweir
MasterPropertySetInfo()45cdf0e10cSrcweir MasterPropertySetInfo::MasterPropertySetInfo()
46cdf0e10cSrcweir throw()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
MasterPropertySetInfo(PropertyInfo * pMap)50cdf0e10cSrcweir MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
51cdf0e10cSrcweir throw()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir add ( pMap );
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
~MasterPropertySetInfo()56cdf0e10cSrcweir MasterPropertySetInfo::~MasterPropertySetInfo()
57cdf0e10cSrcweir throw()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
60cdf0e10cSrcweir while (aIter != aEnd )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir delete (*aIter).second;
63cdf0e10cSrcweir aIter++;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
add(PropertyInfo * pMap,sal_Int32 nCount,sal_uInt8 nMapId)67cdf0e10cSrcweir void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
68cdf0e10cSrcweir throw()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir // nCount < 0 => add all
71cdf0e10cSrcweir // nCount == 0 => add nothing
72cdf0e10cSrcweir // nCount > 0 => add at most nCount entries
73cdf0e10cSrcweir if( maProperties.getLength() )
74cdf0e10cSrcweir maProperties.realloc( 0 );
75cdf0e10cSrcweir
76cdf0e10cSrcweir for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
79cdf0e10cSrcweir
80cdf0e10cSrcweir #ifdef DBG_UTIL
81cdf0e10cSrcweir PropertyDataHash::iterator aIter = maMap.find( aName );
82cdf0e10cSrcweir if( aIter != maMap.end() )
83cdf0e10cSrcweir OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
84cdf0e10cSrcweir #endif
85cdf0e10cSrcweir maMap[aName] = new PropertyData ( nMapId, pMap );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
add(PropertyInfoHash & rHash,sal_uInt8 nMapId)89cdf0e10cSrcweir void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
90cdf0e10cSrcweir throw()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir if( maProperties.getLength() )
93cdf0e10cSrcweir maProperties.realloc( 0 );
94cdf0e10cSrcweir PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
95cdf0e10cSrcweir
96cdf0e10cSrcweir while ( aIter != aEnd )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir #ifdef DBG_UTIL
99cdf0e10cSrcweir PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
100cdf0e10cSrcweir if( aDebugIter != maMap.end() )
101cdf0e10cSrcweir OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
102cdf0e10cSrcweir #endif
103cdf0e10cSrcweir maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
104cdf0e10cSrcweir aIter++;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
remove(const rtl::OUString & aName)108cdf0e10cSrcweir void MasterPropertySetInfo::remove( const rtl::OUString& aName )
109cdf0e10cSrcweir throw()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir maMap.erase ( aName );
112cdf0e10cSrcweir if ( maProperties.getLength() )
113cdf0e10cSrcweir maProperties.realloc( 0 );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
getProperties()116cdf0e10cSrcweir Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
117cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir sal_Int32 nSize = maMap.size();
120cdf0e10cSrcweir if( maProperties.getLength() != nSize )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir maProperties.realloc ( nSize );
123cdf0e10cSrcweir Property* pProperties = maProperties.getArray();
124cdf0e10cSrcweir
125cdf0e10cSrcweir PropertyDataHash::iterator aIter = maMap.begin();
126cdf0e10cSrcweir const PropertyDataHash::iterator aEnd = maMap.end();
127cdf0e10cSrcweir for ( ; aIter != aEnd; ++aIter, ++pProperties)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir PropertyInfo* pInfo = (*aIter).second->mpInfo;
130cdf0e10cSrcweir
131cdf0e10cSrcweir pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
132cdf0e10cSrcweir pProperties->Handle = pInfo->mnHandle;
133cdf0e10cSrcweir const Type* pType;
134cdf0e10cSrcweir GenerateCppuType ( pInfo->meCppuType, pType);
135cdf0e10cSrcweir pProperties->Type = *pType;
136cdf0e10cSrcweir pProperties->Attributes = pInfo->mnAttributes;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir return maProperties;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
getPropertyByName(const::rtl::OUString & rName)142cdf0e10cSrcweir Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
143cdf0e10cSrcweir throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir PropertyDataHash::iterator aIter = maMap.find( rName );
146cdf0e10cSrcweir
147cdf0e10cSrcweir if ( maMap.end() == aIter )
148cdf0e10cSrcweir throw UnknownPropertyException( rName, *this );
149cdf0e10cSrcweir
150cdf0e10cSrcweir PropertyInfo *pInfo = (*aIter).second->mpInfo;
151cdf0e10cSrcweir Property aProperty;
152cdf0e10cSrcweir aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
153cdf0e10cSrcweir aProperty.Handle = pInfo->mnHandle;
154cdf0e10cSrcweir const Type* pType;
155cdf0e10cSrcweir GenerateCppuType ( pInfo->meCppuType, pType );
156cdf0e10cSrcweir aProperty.Type = *pType;
157cdf0e10cSrcweir
158cdf0e10cSrcweir aProperty.Attributes = pInfo->mnAttributes;
159cdf0e10cSrcweir return aProperty;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
hasPropertyByName(const::rtl::OUString & rName)162cdf0e10cSrcweir sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
163cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
166cdf0e10cSrcweir }
167