merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / property / propertysetinfo.cxx
blobefdd495ac1bc72082aef6e838213797095568627
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"
31 #include "comphelper/propertysetinfo.hxx"
33 using namespace ::rtl;
34 using namespace ::comphelper;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::lang;
40 namespace comphelper
42 class PropertyMapImpl
44 public:
45 PropertyMapImpl() throw();
46 virtual ~PropertyMapImpl() throw();
48 void add( PropertyMapEntry* pMap, sal_Int32 nCount = -1 ) throw();
49 void remove( const OUString& aName ) throw();
51 Sequence< Property > getProperties() throw();
53 const PropertyMap* getPropertyMap() const throw();
55 Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
56 sal_Bool hasPropertyByName( const OUString& aName ) throw();
58 private:
59 PropertyMap maPropertyMap;
60 Sequence< Property > maProperties;
64 PropertyMapImpl::PropertyMapImpl() throw()
68 PropertyMapImpl::~PropertyMapImpl() throw()
72 void PropertyMapImpl::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
74 // nCount < 0 => add all
75 // nCount == 0 => add nothing
76 // nCount > 0 => add at most nCount entries
78 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
80 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
82 #ifdef DBG_UTIL
83 PropertyMap::iterator aIter = maPropertyMap.find( aName );
84 if( aIter != maPropertyMap.end() )
86 OSL_ENSURE( sal_False, "Warning: PropertyMapEntry added twice, possible error!");
88 #endif
89 if( NULL == pMap->mpType )
91 OSL_ENSURE( sal_False, "No type in PropertyMapEntry!");
92 pMap->mpType = &::getCppuType((const sal_Int32*)0);
95 maPropertyMap[aName] = pMap;
97 if( maProperties.getLength() )
98 maProperties.realloc( 0 );
100 pMap = &pMap[1];
104 void PropertyMapImpl::remove( const OUString& aName ) throw()
106 maPropertyMap.erase( aName );
108 if( maProperties.getLength() )
109 maProperties.realloc( 0 );
112 Sequence< Property > PropertyMapImpl::getProperties() throw()
114 // maybe we have to generate the properties after
115 // a change in the property map or at first call
116 // to getProperties
117 if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
119 maProperties = Sequence< Property >( maPropertyMap.size() );
120 Property* pProperties = maProperties.getArray();
122 PropertyMap::iterator aIter = maPropertyMap.begin();
123 const PropertyMap::iterator aEnd = maPropertyMap.end();
124 while( aIter != aEnd )
126 PropertyMapEntry* pEntry = (*aIter).second;
128 pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
129 pProperties->Handle = pEntry->mnHandle;
130 pProperties->Type = *pEntry->mpType;
131 pProperties->Attributes = pEntry->mnAttributes;
133 pProperties++;
134 aIter++;
138 return maProperties;
141 const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
143 return &maPropertyMap;
146 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
148 PropertyMap::iterator aIter = maPropertyMap.find( aName );
150 if( maPropertyMap.end() == aIter )
151 throw UnknownPropertyException( aName, NULL );
153 PropertyMapEntry* pEntry = (*aIter).second;
155 return Property( aName, pEntry->mnHandle, *pEntry->mpType, pEntry->mnAttributes );
158 sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
160 return maPropertyMap.find( aName ) != maPropertyMap.end();
163 ///////////////////////////////////////////////////////////////////////
165 PropertySetInfo::PropertySetInfo() throw()
167 mpMap = new PropertyMapImpl();
170 PropertySetInfo::PropertySetInfo( PropertyMapEntry* pMap ) throw()
172 mpMap = new PropertyMapImpl();
173 mpMap->add( pMap );
176 PropertySetInfo::~PropertySetInfo() throw()
178 delete mpMap;
181 void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
183 mpMap->add( pMap );
186 void PropertySetInfo::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
188 mpMap->add( pMap, nCount );
191 void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
193 mpMap->remove( aName );
196 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
198 return mpMap->getProperties();
201 Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
203 return mpMap->getPropertyByName( aName );
206 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
208 return mpMap->hasPropertyByName( Name );
211 const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
213 return mpMap->getPropertyMap();