xref: /AOO41X/main/comphelper/source/property/propertysetinfo.cxx (revision dde7d3faf6dcd9cbeb7b48ba6d0cea5ffcc883d0)
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
10cdf0e10cSrcweir  *
11*dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
27cdf0e10cSrcweir #include "comphelper/propertysetinfo.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using namespace ::rtl;
30cdf0e10cSrcweir using namespace ::comphelper;
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir using namespace ::com::sun::star::beans;
34cdf0e10cSrcweir using namespace ::com::sun::star::lang;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace comphelper
37cdf0e10cSrcweir {
38cdf0e10cSrcweir class PropertyMapImpl
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir 	PropertyMapImpl() throw();
42cdf0e10cSrcweir 	virtual ~PropertyMapImpl() throw();
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	void add( PropertyMapEntry* pMap, sal_Int32 nCount = -1 ) throw();
45cdf0e10cSrcweir 	void remove( const OUString& aName ) throw();
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	Sequence< Property > getProperties() throw();
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	const PropertyMap* getPropertyMap() const throw();
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
52cdf0e10cSrcweir 	sal_Bool hasPropertyByName( const OUString& aName ) throw();
53cdf0e10cSrcweir 
54cdf0e10cSrcweir private:
55cdf0e10cSrcweir 	PropertyMap maPropertyMap;
56cdf0e10cSrcweir 	Sequence< Property > maProperties;
57cdf0e10cSrcweir };
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
PropertyMapImpl()60cdf0e10cSrcweir PropertyMapImpl::PropertyMapImpl() throw()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
~PropertyMapImpl()64cdf0e10cSrcweir PropertyMapImpl::~PropertyMapImpl() throw()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
add(PropertyMapEntry * pMap,sal_Int32 nCount)68cdf0e10cSrcweir void PropertyMapImpl::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	// nCount < 0	=> add all
71cdf0e10cSrcweir 	// nCount == 0	=> add nothing
72cdf0e10cSrcweir 	// nCount > 0	=> add at most nCount entries
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #ifdef DBG_UTIL
79cdf0e10cSrcweir 		PropertyMap::iterator aIter = maPropertyMap.find( aName );
80cdf0e10cSrcweir 		if( aIter != maPropertyMap.end() )
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Warning: PropertyMapEntry added twice, possible error!");
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir #endif
85cdf0e10cSrcweir 		if( NULL == pMap->mpType )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "No type in PropertyMapEntry!");
88cdf0e10cSrcweir 			pMap->mpType = &::getCppuType((const sal_Int32*)0);
89cdf0e10cSrcweir 		}
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		maPropertyMap[aName] = pMap;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		if( maProperties.getLength() )
94cdf0e10cSrcweir 			maProperties.realloc( 0 );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		pMap = &pMap[1];
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
remove(const OUString & aName)100cdf0e10cSrcweir void PropertyMapImpl::remove( const OUString& aName ) throw()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	maPropertyMap.erase( aName );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	if( maProperties.getLength() )
105cdf0e10cSrcweir 		maProperties.realloc( 0 );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
getProperties()108cdf0e10cSrcweir Sequence< Property > PropertyMapImpl::getProperties() throw()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	// maybe we have to generate the properties after
111cdf0e10cSrcweir 	// a change in the property map or at first call
112cdf0e10cSrcweir 	// to getProperties
113cdf0e10cSrcweir 	if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		maProperties = Sequence< Property >( maPropertyMap.size() );
116cdf0e10cSrcweir 		Property* pProperties = maProperties.getArray();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		PropertyMap::iterator aIter = maPropertyMap.begin();
119cdf0e10cSrcweir 		const PropertyMap::iterator aEnd = maPropertyMap.end();
120cdf0e10cSrcweir 		while( aIter != aEnd )
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			PropertyMapEntry* pEntry = (*aIter).second;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 			pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
125cdf0e10cSrcweir 			pProperties->Handle = pEntry->mnHandle;
126cdf0e10cSrcweir 			pProperties->Type = *pEntry->mpType;
127cdf0e10cSrcweir 			pProperties->Attributes = pEntry->mnAttributes;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 			pProperties++;
130cdf0e10cSrcweir 			aIter++;
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	return maProperties;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
getPropertyMap() const137cdf0e10cSrcweir const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	return &maPropertyMap;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
getPropertyByName(const OUString & aName)142cdf0e10cSrcweir Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	PropertyMap::iterator aIter = maPropertyMap.find( aName );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	if( maPropertyMap.end() == aIter )
147cdf0e10cSrcweir 		throw UnknownPropertyException( aName, NULL );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	PropertyMapEntry* pEntry = (*aIter).second;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	return Property( aName, pEntry->mnHandle, *pEntry->mpType, pEntry->mnAttributes );
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
hasPropertyByName(const OUString & aName)154cdf0e10cSrcweir sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	return maPropertyMap.find( aName ) != maPropertyMap.end();
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
160cdf0e10cSrcweir 
PropertySetInfo()161cdf0e10cSrcweir PropertySetInfo::PropertySetInfo() throw()
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	mpMap = new PropertyMapImpl();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
PropertySetInfo(PropertyMapEntry * pMap)166cdf0e10cSrcweir PropertySetInfo::PropertySetInfo( PropertyMapEntry* pMap ) throw()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	mpMap = new PropertyMapImpl();
169cdf0e10cSrcweir 	mpMap->add( pMap );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
~PropertySetInfo()172cdf0e10cSrcweir PropertySetInfo::~PropertySetInfo() throw()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	delete mpMap;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
add(PropertyMapEntry * pMap)177cdf0e10cSrcweir void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	mpMap->add( pMap );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
add(PropertyMapEntry * pMap,sal_Int32 nCount)182cdf0e10cSrcweir void PropertySetInfo::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	mpMap->add( pMap, nCount );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
remove(const rtl::OUString & aName)187cdf0e10cSrcweir void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	mpMap->remove( aName );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
getProperties()192cdf0e10cSrcweir Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	return mpMap->getProperties();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
getPropertyByName(const::rtl::OUString & aName)197cdf0e10cSrcweir Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	return mpMap->getPropertyByName( aName );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
hasPropertyByName(const::rtl::OUString & Name)202cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	return mpMap->hasPropertyByName( Name );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
getPropertyMap() const207cdf0e10cSrcweir const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	return mpMap->getPropertyMap();
210cdf0e10cSrcweir }
211