merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / property / propertysetinfo.cxx
blobbfa0c9ea0ef93b3ef80089ba8ea1dbdeb25582b6
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: propertysetinfo.cxx,v $
10 * $Revision: 1.6 $
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"
34 #include "comphelper/propertysetinfo.hxx"
36 using namespace ::rtl;
37 using namespace ::comphelper;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::lang;
43 namespace comphelper
45 class PropertyMapImpl
47 public:
48 PropertyMapImpl() throw();
49 virtual ~PropertyMapImpl() throw();
51 void add( PropertyMapEntry* pMap, sal_Int32 nCount = -1 ) throw();
52 void remove( const OUString& aName ) throw();
54 Sequence< Property > getProperties() throw();
56 const PropertyMap* getPropertyMap() const throw();
58 Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
59 sal_Bool hasPropertyByName( const OUString& aName ) throw();
61 private:
62 PropertyMap maPropertyMap;
63 Sequence< Property > maProperties;
67 PropertyMapImpl::PropertyMapImpl() throw()
71 PropertyMapImpl::~PropertyMapImpl() throw()
75 void PropertyMapImpl::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
77 // nCount < 0 => add all
78 // nCount == 0 => add nothing
79 // nCount > 0 => add at most nCount entries
81 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
83 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
85 #ifndef PRODUCT
86 PropertyMap::iterator aIter = maPropertyMap.find( aName );
87 if( aIter != maPropertyMap.end() )
89 OSL_ENSURE( sal_False, "Warning: PropertyMapEntry added twice, possible error!");
91 #endif
92 if( NULL == pMap->mpType )
94 OSL_ENSURE( sal_False, "No type in PropertyMapEntry!");
95 pMap->mpType = &::getCppuType((const sal_Int32*)0);
98 maPropertyMap[aName] = pMap;
100 if( maProperties.getLength() )
101 maProperties.realloc( 0 );
103 pMap = &pMap[1];
107 void PropertyMapImpl::remove( const OUString& aName ) throw()
109 maPropertyMap.erase( aName );
111 if( maProperties.getLength() )
112 maProperties.realloc( 0 );
115 Sequence< Property > PropertyMapImpl::getProperties() throw()
117 // maybe we have to generate the properties after
118 // a change in the property map or at first call
119 // to getProperties
120 if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
122 maProperties = Sequence< Property >( maPropertyMap.size() );
123 Property* pProperties = maProperties.getArray();
125 PropertyMap::iterator aIter = maPropertyMap.begin();
126 const PropertyMap::iterator aEnd = maPropertyMap.end();
127 while( aIter != aEnd )
129 PropertyMapEntry* pEntry = (*aIter).second;
131 pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
132 pProperties->Handle = pEntry->mnHandle;
133 pProperties->Type = *pEntry->mpType;
134 pProperties->Attributes = pEntry->mnAttributes;
136 pProperties++;
137 aIter++;
141 return maProperties;
144 const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
146 return &maPropertyMap;
149 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
151 PropertyMap::iterator aIter = maPropertyMap.find( aName );
153 if( maPropertyMap.end() == aIter )
154 throw UnknownPropertyException( aName, NULL );
156 PropertyMapEntry* pEntry = (*aIter).second;
158 return Property( aName, pEntry->mnHandle, *pEntry->mpType, pEntry->mnAttributes );
161 sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
163 return maPropertyMap.find( aName ) != maPropertyMap.end();
166 ///////////////////////////////////////////////////////////////////////
168 PropertySetInfo::PropertySetInfo() throw()
170 mpMap = new PropertyMapImpl();
173 PropertySetInfo::PropertySetInfo( PropertyMapEntry* pMap ) throw()
175 mpMap = new PropertyMapImpl();
176 mpMap->add( pMap );
179 PropertySetInfo::~PropertySetInfo() throw()
181 delete mpMap;
184 void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
186 mpMap->add( pMap );
189 void PropertySetInfo::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw()
191 mpMap->add( pMap, nCount );
194 void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
196 mpMap->remove( aName );
199 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
201 return mpMap->getProperties();
204 Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
206 return mpMap->getPropertyByName( aName );
209 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
211 return mpMap->hasPropertyByName( Name );
214 const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
216 return mpMap->getPropertyMap();